Execute a module's code without importing it Returns the resulting top level namespace dictionary
(mod_name, init_globals=None, run_name=None, alter_sys=False)
| 229 | |
| 230 | |
| 231 | def run_module(mod_name, init_globals=None, run_name=None, alter_sys=False): |
| 232 | """Execute a module's code without importing it |
| 233 | |
| 234 | Returns the resulting top level namespace dictionary |
| 235 | """ |
| 236 | mod_name, mod_spec, code = _get_module_details(mod_name) |
| 237 | if run_name is None: |
| 238 | run_name = mod_name |
| 239 | if alter_sys: |
| 240 | return _run_module_code(code, init_globals, run_name, mod_spec) |
| 241 | else: |
| 242 | # Leave the sys module alone |
| 243 | return _run_code(code, {}, init_globals, run_name, mod_spec) |
| 244 | |
| 245 | |
| 246 | def _get_main_module_details(error=ImportError): |
nothing calls this directly
no test coverage detected