Load module path :param module_path: :return: :raises: ModuleNotFoundError
(module_path: Union[str, ModuleType])
| 23 | |
| 24 | |
| 25 | def 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 | |
| 49 | def split_module_path(module_path: str) -> Tuple[str, str]: |
no test coverage detected