MCPcopy Index your code
hub / github.com/python/cpython / _run_module_code

Function _run_module_code

Lib/runpy.py:90–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

88 return run_globals
89
90def _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
104def _get_module_details(mod_name, error=ImportError):

Callers 3

create_nsMethod · 0.90
run_moduleFunction · 0.85
run_pathFunction · 0.85

Calls 4

_TempModuleClass · 0.85
_ModifiedArgv0Class · 0.85
_run_codeFunction · 0.85
copyMethod · 0.45

Tested by 1

create_nsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…