Handled operation import errors

The program should not crash now if invalid code is imported
This commit is contained in:
gentlegiantJGC 2020-11-10 14:59:24 +00:00
parent a07ee4c7f8
commit 1aa7f36c79

View File

@ -196,12 +196,20 @@ def _load_operations(operations_: OperationStorageType, path: str):
if fpath.endswith("__init__.py"):
continue
mod = _load_module_file(fpath)
get_export_dict(mod, operations_, fpath)
try:
mod = _load_module_file(fpath)
except ImportError as e:
log.warn(f"Failed to import {fpath}.\n{e}")
else:
get_export_dict(mod, operations_, fpath)
for dpath in glob.iglob(os.path.join(glob.escape(path), "**", "__init__.py")):
mod = _load_module_directory(dpath)
get_export_dict(mod, operations_, os.path.basename(os.path.dirname(dpath)))
try:
mod = _load_module_directory(dpath)
except ImportError as e:
log.warn(f"Failed to import {dpath}.\n{e}")
else:
get_export_dict(mod, operations_, os.path.basename(os.path.dirname(dpath)))
def _load_operations_group(dir_paths: List[str]):