Dynamically load a Python module from a file path.
(path: Path, module_name: str)
| 102 | # --------------------------------------------------------------------------- |
| 103 | |
| 104 | def _load_module_from_path(path: Path, module_name: str): |
| 105 | """Dynamically load a Python module from a file path.""" |
| 106 | spec = importlib.util.spec_from_file_location(module_name, str(path)) |
| 107 | if spec is None or spec.loader is None: |
| 108 | raise ImportError(f"Cannot load module from {path}") |
| 109 | mod = importlib.util.module_from_spec(spec) |
| 110 | sys.modules[module_name] = mod |
| 111 | spec.loader.exec_module(mod) |
| 112 | return mod |
| 113 | |
| 114 | |
| 115 | def load_reference(): |
no outgoing calls
no test coverage detected