Execute a Python module. Args: module_name: Name of the module to execute module_args: Arguments to pass to the module Raises: TargetError: If module cannot be found
(module_name: str, module_args: List[str])
| 127 | |
| 128 | |
| 129 | def _execute_module(module_name: str, module_args: List[str]) -> None: |
| 130 | """ |
| 131 | Execute a Python module. |
| 132 | |
| 133 | Args: |
| 134 | module_name: Name of the module to execute |
| 135 | module_args: Arguments to pass to the module |
| 136 | |
| 137 | Raises: |
| 138 | TargetError: If module cannot be found |
| 139 | """ |
| 140 | # Replace sys.argv to match how Python normally runs modules |
| 141 | # When running 'python -m module args', sys.argv is ["__main__.py", "args"] |
| 142 | sys.argv = ["__main__.py"] + module_args |
| 143 | |
| 144 | try: |
| 145 | runpy.run_module(module_name, run_name="__main__", alter_sys=True) |
| 146 | except ImportError as e: |
| 147 | raise TargetError(f"Module '{module_name}' not found: {e}") from e |
| 148 | # Let other exceptions (including SystemExit) propagate naturally |
| 149 | # so Python prints the full traceback to stderr |
| 150 | |
| 151 | |
| 152 | def _execute_script(script_path: str, script_args: List[str], cwd: str) -> None: |
no test coverage detected
searching dependent graphs…