Anonymous avatar Anonymous committed b5633d6

pycore: creating builtin modules only in PyCore

We should make sure only one BuiltinModule for each extension module
exists; otherwise caching problems might happen.

Comments (0)

Files changed (3)

rope/base/builtins.py

 
 class BuiltinModule(pyobjects.AbstractModule):
 
-    def __init__(self, name, modnames=[], initial={}):
+    def __init__(self, name, pycore=None, initial={}):
         super(BuiltinModule, self).__init__()
         self.name = name
+        self.pycore = pycore
         self.initial = initial
-        self.modnames = modnames
 
     parent = None
 
     def attributes(self):
         result = _object_attributes(self.module, self)
         result.update(self.initial)
-        for modname in self.submodules:
-            name = modname[len(self.name) + 1:]
-            if '.' not in name:
-                result[name] = BuiltinModule(modname, self.submodules)
+        if self.pycore is not None:
+            submodules = self.pycore._builtin_submodules(self.name)
+            for name, module in submodules.iteritems():
+                result[name] = rope.base.builtins.BuiltinName(module)
         return result
 
     @property
         except ImportError:
             return
 
-    @property
-    @utils.cacheit
-    def submodules(self):
-        modnames = []
-        for modname in self.modnames:
-            prefix = self.name + '.'
-            if modname.startswith(prefix):
-                modnames.append(modname)
-        return modnames
-
 
 class _BuiltinElement(object):
 

rope/base/pycore.py

             return module
         return self.resource_to_pyobject(module)
 
+    def _builtin_submodules(self, modname):
+        result = {}
+        for extension in self.extension_modules:
+            if extension.startswith(modname + '.'):
+                name = extension[len(modname) + 1:]
+                if '.' not in name:
+                    result[name] = self._builtin_module(extension)
+        return result
+
     def _builtin_module(self, name):
         return self.extension_cache.get_pymodule(name)
 
             return builtins.builtins
         allowed = self.pycore.extension_modules
         if name not in self.extensions and name in allowed:
-            self.extensions[name] = builtins.BuiltinModule(name, allowed)
+            self.extensions[name] = builtins.BuiltinModule(name, self.pycore)
         return self.extensions.get(name)
 
 

rope/base/pyobjectsdef.py

     def _create_structural_attributes(self):
         result = {}
         modname = self.pycore.modname(self.resource)
-        for extension in self.pycore.extension_modules:
-            if extension.startswith(modname + '.'):
-                name = extension[len(modname) + 1:]
-                if '.' not in name:
-                    module = rope.base.builtins.BuiltinModule(
-                        extension, self.pycore.extension_modules)
-                    result[name] = rope.base.builtins.BuiltinName(module)
+        extension_submodules = self.pycore._builtin_submodules(modname)
+        for name, module in extension_submodules.iteritems():
+            result[name] = rope.base.builtins.BuiltinName(module)
         if self.resource is None:
             return result
         for name, resource in self._get_child_resources().items():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.