utils: add direct fallback to load_system_module
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
d6231634db
commit
1a5cf56532
|
@ -200,6 +200,12 @@ def verify_source(
|
||||||
return checksum, checksum == orig_chksum
|
return checksum, checksum == orig_chksum
|
||||||
|
|
||||||
def load_system_module(name: str) -> ModuleType:
|
def load_system_module(name: str) -> ModuleType:
|
||||||
|
if not SYS_MOD_PATHS:
|
||||||
|
# no dist path detected, fall back to direct import attempt
|
||||||
|
try:
|
||||||
|
return importlib.import_module(name)
|
||||||
|
except ImportError as e:
|
||||||
|
raise ServerError(f"Unable to import module {name}") from e
|
||||||
for module_path in SYS_MOD_PATHS:
|
for module_path in SYS_MOD_PATHS:
|
||||||
sys.path.insert(0, module_path)
|
sys.path.insert(0, module_path)
|
||||||
try:
|
try:
|
||||||
|
@ -207,10 +213,10 @@ def load_system_module(name: str) -> ModuleType:
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
if not isinstance(e, ModuleNotFoundError):
|
if not isinstance(e, ModuleNotFoundError):
|
||||||
logging.exception(f"Failed to load {name} module")
|
logging.exception(f"Failed to load {name} module")
|
||||||
sys.path.pop(0)
|
|
||||||
else:
|
else:
|
||||||
sys.path.pop(0)
|
|
||||||
break
|
break
|
||||||
|
finally:
|
||||||
|
sys.path.pop(0)
|
||||||
else:
|
else:
|
||||||
raise ServerError(f"Unable to import module {name}")
|
raise ServerError(f"Unable to import module {name}")
|
||||||
return module
|
return module
|
||||||
|
|
Loading…
Reference in New Issue