Lines Matching +full:module +full:- +full:importer
1 """runpy.py - locating and running Python code using the module namespace
4 module namespace instead of the native filesystem.
6 This allows Python code to play nicely with non-filesystem based PEP 302
14 import importlib.machinery # importlib first so we can test #15386 via -m
27 """Temporarily replace a module in sys.modules with an empty namespace"""
30 self.module = ModuleType(mod_name)
39 sys.modules[mod_name] = self.module
97 mod_globals = temp_module.module.__dict__
100 # Copy the globals of the temporary module, as they
101 # may be cleared when the temporary module goes away
104 # Helper to get the full name, spec and code for a module
107 raise error("Relative module names not supported")
120 # Warn if the module has already been imported under its normal name
136 msg = "Error while finding module specification for {!r} ({}: {})"
138 msg += (f". Try using '{mod_name[:-3]}' instead of "
139 f"'{mod_name}' as the module name.")
142 raise error("No module named %s" % mod_name)
145 raise error("Cannot use package as __main__ module")
151 raise # No module loaded; being a package is irrelevant
174 """Runs the designated module in the __main__ namespace
176 Note that the executed module will have full access to the
178 function should be used to run the module code in a fresh namespace.
188 if alter_argv or mod_name != "__main__": # i.e. -m switch
203 """Execute a module's code without importing it.
205 mod_name -- an absolute module name or package name.
208 init_globals -- dictionary used to pre-populate the module’s
211 run_name -- if not None, this will be used for setting __name__;
213 named module is a package and to just mod_name otherwise.
215 alter_sys -- if True, sys.argv[0] is updated with the value of
217 module object for the module being executed. Both are
220 Returns the resulting module globals dictionary.
228 # Leave the sys module alone
243 raise error("can't find %r module in %r" %
265 path_name -- filesystem location of a Python script, zipfile,
269 init_globals -- dictionary used to pre-populate the module’s
272 run_name -- if not None, this will be used to set __name__;
275 Returns the resulting module globals dictionary.
281 importer = get_importer(path_name)
284 if type(importer).__module__ == 'imp':
285 if type(importer).__name__ == 'NullImporter':
287 if isinstance(importer, type(None)) or is_NullImporter:
299 # case. There, we only had to replace the module in sys while the
303 # existing __main__ module may prevent location of the new module.
307 mod_globals = temp_module.module.__dict__
318 # Run the module specified as the next command line argument
320 print("No module specified for execution", file=sys.stderr)
322 del sys.argv[0] # Make the requested module sys.argv[0]