import from filepath if can't import_module

This commit is contained in:
Sunny Liu
2025-03-15 20:25:53 -04:00
committed by Sung Ching Liu
parent eadb16c709
commit ec52561a0c

View File

@@ -36,7 +36,15 @@ def load(strategy, cfg, module_base=None, **kwargs):
module_base = ".".join(strategy.split(".")[:-2])
strategy = strategy.split(".")[-2]
except ModuleNotFoundError:
strategy = "." + ".".join(strategy.split(".")[:-1])
try:
file_path = "/".join(strategy.split(".")[:-1]) + ".py"
module_name = strategy.split(".")[-2]
mod = import_from_path(module_name, file_path)
func = getattr(mod, load_fn)
return func(cfg, **kwargs)
except FileNotFoundError:
strategy = "." + ".".join(strategy.split(".")[:-1])
else:
strategy = "." + ".".join(strategy.split(".")[:-1])
mod = importlib.import_module(strategy, module_base)