theoden avatar theoden committed 868bdfb

* Any intermediate module is added to sys.modules. Not only root one, as it was.

Comments (0)

Files changed (1)


     def expose(self, module_name):
         Adds tasks to module which name is last in ``module_name`` argument.
-        ``module_name`` is a module path, e.g. 'mod.submod1.submod2'. Zero-level
-        module, 'mod' in example, must not exist in global namespace.
+        ``module_name`` is a module path, e.g. 'mod.submod1.submod2'. 
+        Any modules touched are extended not replaced.
         mod_list = module_name.split('.')
-        # zero-level module must not exist
+        # if zero-level module exists, take its object for
+        # addition instead of replacing
         if mod_list[0] in sys.modules:
             global_mod = sys.modules[mod_list[0]]
             global_mod = types.ModuleType(mod_list[0])
             sys.modules.setdefault(mod_list[0], global_mod)
         cur_mod = global_mod
-        for mod_name in mod_list[1:]:
+        for name_idx, mod_name in enumerate(mod_list[1:], 2):
             new_mod = types.ModuleType(mod_name)
-            setattr(cur_mod,mod_name,new_mod)
+            setattr(cur_mod, mod_name, new_mod)
+            sys.modules.setdefault('.'.join(mod_list[:name_idx]), new_mod)
             cur_mod = new_mod
         for name, task in self._get_fabric_tasks():
             setattr(cur_mod, name, task)
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.