• Home
  • Raw
  • Download

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
25 """Temporarily replace a module in sys.modules with an empty namespace"""
28 self.module = imp.new_module(mod_name)
37 sys.modules[mod_name] = self.module
80 mod_globals = temp_module.module.__dict__
83 # Copy the globals of the temporary module, as they
84 # may be cleared when the temporary module goes away
89 # loader protocol (specifically, "get_filename" is non-standard)
99 # Helper to get the loader, code and filename for a module
104 raise error("No module named %s" % mod_name)
110 raise error("Cannot use package as __main__ module")
136 raise error("can't find %r module in %r" %
143 # This function is the actual implementation of the -m switch and direct
148 """Runs the designated module in the __main__ namespace
150 Note that the executed module will have full access to the
152 function should be used to run the module code in a fresh namespace.
161 if alter_argv or mod_name != "__main__": # i.e. -m switch
178 """Execute a module's code without importing it
190 # Leave the sys module alone
201 importer = cache[path_name]
209 importer = hook(path_name)
219 importer = imp.NullImporter(path_name)
222 cache[path_name] = importer
223 return importer
247 importer = _get_importer(path_name)
248 if isinstance(importer, imp.NullImporter):
254 # Importer is defined for path, so add it to
259 # case. There, we only had to replace the module in sys while the
263 # existing __main__ module may prevent location of the new module.
274 mod_globals = temp_module.module.__dict__
285 # Run the module specified as the next command line argument
287 print >> sys.stderr, "No module specified for execution"
289 del sys.argv[0] # Make the requested module sys.argv[0]