MCPcopy
hub / github.com/microsoft/qlib / get_module_by_module_path

Function get_module_by_module_path

qlib/utils/mod.py:25–46  ·  view source on GitHub ↗

Load module path :param module_path: :return: :raises: ModuleNotFoundError

(module_path: Union[str, ModuleType])

Source from the content-addressed store, hash-verified

23
24
25def get_module_by_module_path(module_path: Union[str, ModuleType]):
26 """Load module path
27
28 :param module_path:
29 :return:
30 :raises: ModuleNotFoundError
31 """
32 if module_path is None:
33 raise ModuleNotFoundError("None is passed in as parameters as module_path")
34
35 if isinstance(module_path, ModuleType):
36 module = module_path
37 else:
38 if module_path.endswith(".py"):
39 module_name = re.sub("^[^a-zA-Z_]+", "", re.sub("[^0-9a-zA-Z_]", "", module_path[:-3].replace("/", "_")))
40 module_spec = importlib.util.spec_from_file_location(module_name, module_path)
41 module = importlib.util.module_from_spec(module_spec)
42 sys.modules[module_name] = module
43 module_spec.loader.exec_module(module)
44 else:
45 module = importlib.import_module(module_path)
46 return module
47
48
49def split_module_path(module_path: str) -> Tuple[str, str]:

Callers 4

init_tunerMethod · 0.85
register_wrapperFunction · 0.85
get_callable_kwargsFunction · 0.85
register_all_wrappersFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected