Helper to run code in new namespace with sys modified
(code, init_globals=None,
mod_name=None, mod_spec=None,
pkg_name=None, script_name=None)
| 88 | return run_globals |
| 89 | |
| 90 | def _run_module_code(code, init_globals=None, |
| 91 | mod_name=None, mod_spec=None, |
| 92 | pkg_name=None, script_name=None): |
| 93 | """Helper to run code in new namespace with sys modified""" |
| 94 | fname = script_name if mod_spec is None else mod_spec.origin |
| 95 | with _TempModule(mod_name) as temp_module, _ModifiedArgv0(fname): |
| 96 | mod_globals = temp_module.module.__dict__ |
| 97 | _run_code(code, mod_globals, init_globals, |
| 98 | mod_name, mod_spec, pkg_name, script_name) |
| 99 | # Copy the globals of the temporary module, as they |
| 100 | # may be cleared when the temporary module goes away |
| 101 | return mod_globals.copy() |
| 102 | |
| 103 | # Helper to get the full name, spec and code for a module |
| 104 | def _get_module_details(mod_name, error=ImportError): |
searching dependent graphs…