MCPcopy Index your code
hub / github.com/RustPython/RustPython / run_module

Function run_module

Lib/runpy.py:201–229  ·  view source on GitHub ↗

Execute a module's code without importing it. mod_name -- an absolute module name or package name. Optional arguments: init_globals -- dictionary used to pre-populate the module’s globals dictionary before the code is executed. run_name -- if not None, this will

(mod_name, init_globals=None,
               run_name=None, alter_sys=False)

Source from the content-addressed store, hash-verified

199 "__main__", mod_spec)
200
201def run_module(mod_name, init_globals=None,
202 run_name=None, alter_sys=False):
203 """Execute a module's code without importing it.
204
205 mod_name -- an absolute module name or package name.
206
207 Optional arguments:
208 init_globals -- dictionary used to pre-populate the module’s
209 globals dictionary before the code is executed.
210
211 run_name -- if not None, this will be used for setting __name__;
212 otherwise, __name__ will be set to mod_name + '__main__' if the
213 named module is a package and to just mod_name otherwise.
214
215 alter_sys -- if True, sys.argv[0] is updated with the value of
216 __file__ and sys.modules[__name__] is updated with a temporary
217 module object for the module being executed. Both are
218 restored to their original values before the function returns.
219
220 Returns the resulting module globals dictionary.
221 """
222 mod_name, mod_spec, code = _get_module_details(mod_name)
223 if run_name is None:
224 run_name = mod_name
225 if alter_sys:
226 return _run_module_code(code, init_globals, run_name, mod_spec)
227 else:
228 # Leave the sys module alone
229 return _run_code(code, {}, init_globals, run_name, mod_spec)
230
231def _get_main_module_details(error=ImportError):
232 # Helper that gives a nicer error message when attempting to

Calls 3

_get_module_detailsFunction · 0.85
_run_module_codeFunction · 0.85
_run_codeFunction · 0.85