1. jergosh
  2. gsoc_import_engine

Commits

Greg Slodkowicz  committed 44e2382

Introduced a from_engine() method in the ImportEngine. Deleted wrapGlobalState() so as not to duplicate functionality.

  • Participants
  • Parent commits 2809923
  • Branches default

Comments (0)

Files changed (1)

File Lib/importlib/engine.py

View file
 import _warnings
 from os import sep as path_sep
 
-# __all__ = [ ImportEngine, GlobalImportEngine, sysengine, wrapGlobalState ]
+# __all__ = [ ImportEngine, GlobalImportEngine, sysengine ]
 
 # XXX Could also expose Modules/getpath.c:joinpath()
 def _path_join(*args):
                         pass
             return module
 
+    def from_engine(self, other):
+        """
+        Return an ImportEngine with a copy of the global import state.
+        """
+        import copy
+        engine = ImportEngine()
+
+        engine.modules = copy.copy(self.modules)
+        engine.path = copy.copy(self.path)
+        engine.path_hooks = copy.copy(self.path_hooks)
+        engine.meta_path = copy.copy(self.meta_path)
+        engine.path_importer_cache = copy.copy(self.path_importer_cache)
+
+        return engine
+
 class GlobalImportEngine(ImportEngine):
     def __init__(self):
         # Don't want to call super().__init__() since it would overwrite
     path_importer_cache = property(getpathimportercache, setpathimportercache)
 
 sysengine = GlobalImportEngine()
-
-def wrapGlobalState():
-    """
-    Return an ImportEngine with a copy of the global import state.
-    """
-    import copy
-    engine = ImportEngine()
-
-    engine.modules = copy.copy(sys.modules)
-    engine.path = copy.copy(sys.path)
-    engine.path_hooks = copy.copy(sys.path_hooks)
-    engine.meta_path = copy.copy(sys.meta_path)
-    engine.path_importer_cache = copy.copy(sys.path_importer_cache)
-
-    return engine
-