Load and return the user's Python module.
(script_path)
| 86 | |
| 87 | |
| 88 | def load_user_module(script_path): |
| 89 | """Load and return the user's Python module.""" |
| 90 | script_dir = os.path.dirname(os.path.abspath(script_path)) |
| 91 | module_name = os.path.basename(script_path).rsplit(".", 1)[0] |
| 92 | |
| 93 | if script_dir not in sys.path: |
| 94 | sys.path.insert(0, script_dir) |
| 95 | |
| 96 | spec = importlib.util.spec_from_file_location(module_name, script_path) |
| 97 | if spec is None or spec.loader is None: |
| 98 | raise ImportError(f"Cannot load module from {script_path}") |
| 99 | |
| 100 | module = importlib.util.module_from_spec(spec) |
| 101 | spec.loader.exec_module(module) |
| 102 | |
| 103 | return module |
| 104 | |
| 105 | |
| 106 | def get_callable(module, method_name): |
no outgoing calls
no test coverage detected
searching dependent graphs…