fix: resolve iOpenPod import conflict by removing src/ from sys.path during iop imports

iTunesDB_Writer's internal 'from ipod_device import ChecksumType' was resolving
to our local src/ipod_device.py instead of iOpenPod's version, even with
iop path at sys.path[0] (Python 3.14 import resolution quirk).

Now temporarily removes project src/ from sys.path during iOpenPod imports,
restoring it afterwards. The validated flow: main.py imports local ipod_device
first, then _import_iop evicts and replaces it when iPod tab is used.
This commit is contained in:
Maksim Totmin 2026-06-01 00:55:12 +07:00
parent 5ba346cc84
commit a0b1aba50e

View File

@ -88,19 +88,30 @@ def _import_iop(module_name: str):
return _IOP_CACHE[module_name] return _IOP_CACHE[module_name]
if not _IOP_READY: if not _IOP_READY:
# Evict local shadows ONCE so iOpenPod modules resolve correctly.
sys.modules.pop("ipod_device", None) sys.modules.pop("ipod_device", None)
_IOP_READY = True _IOP_READY = True
logger.debug("iOpenPod boot: evicted local ipod_device") logger.debug("iOpenPod boot: evicted local ipod_device")
src_paths = [p for p in sys.path if p.endswith('/src') or p == 'src']
for p in src_paths:
sys.path.remove(p)
had_iop = _IOP_ROOT in sys.path had_iop = _IOP_ROOT in sys.path
if not had_iop: if not had_iop:
sys.path.insert(0, _IOP_ROOT) sys.path.insert(0, _IOP_ROOT)
importlib.invalidate_caches()
try: try:
mod = importlib.import_module(module_name) mod = importlib.import_module(module_name)
finally: finally:
for p in src_paths:
if p not in sys.path:
sys.path.insert(0, p)
if not had_iop: if not had_iop:
sys.path.remove(_IOP_ROOT) try:
sys.path.remove(_IOP_ROOT)
except ValueError:
pass
_IOP_CACHE[module_name] = mod _IOP_CACHE[module_name] = mod
return mod return mod