Anonymous avatar Anonymous committed f2ea8ab

autoimport: support wildcards in module names

Now modules parameter in generate_modules_cache() can contain modules
like "rope.*" which means rope and all of its submodules.

Comments (0)

Files changed (2)


 import re
 from rope.base import (exceptions, pynames, resourceobserver,
-                       taskhandle, pyobjects, builtins)
+                       taskhandle, pyobjects, builtins, resources)
 from rope.refactor import importutils
             'Generatig autoimport cache for modules', len(modules))
         for modname in modules:
             job_set.started_job('Working on <%s>' % modname)
-            self.update_module(modname, underlined)
+            if modname.endswith('.*'):
+                mod = self.project.pycore.find_module(modname[:-2])
+                if mod:
+                    for sub in submodules(mod):
+                        self.update_resource(sub, underlined)
+            else:
+                self.update_module(modname, underlined)
     def clear_cache(self):
             modname = self._module_name(resource)
             if modname in self.names:
                 del self.names[modname]
+def submodules(mod):
+    if isinstance(mod, resources.File):
+        if'.py') and != '':
+            return set([mod])
+        return set()
+    if not mod.has_child(''):
+        return set()
+    result = set([mod])
+    for child in mod.get_children():
+        result |= submodules(child)
+    return result


         self.assertTrue('sys' in self.importer.get_modules('exit'))
+    def test_submodules(self):
+        self.assertEquals(set([self.mod1]),
+                          autoimport.submodules(self.mod1))
+        self.assertEquals(set([self.mod2, self.pkg]),
+                          autoimport.submodules(self.pkg))
 class AutoImportObservingTest(unittest.TestCase):
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
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.