vregistry.py
branchstable
changeset 5078 ea66c4aabb47
parent 4719 aaed3f813ef8
child 5093 8d073d2e089d
--- a/vregistry.py	Tue Mar 30 13:27:30 2010 +0200
+++ b/vregistry.py	Tue Mar 30 13:28:19 2010 +0200
@@ -48,7 +48,21 @@
             subfiles = [join(fileordir, fname) for fname in listdir(fileordir)]
             _toload_info(subfiles, extrapath, _toload)
         elif fileordir[-3:] == '.py':
-            modname = '.'.join(modpath_from_file(fileordir, extrapath))
+            modpath = modpath_from_file(fileordir, extrapath)
+            # omit '__init__' from package's name to avoid loading that module
+            # once for each name when it is imported by some other appobject
+            # module. This supposes import in modules are done as::
+            #
+            #   from package import something
+            #
+            # not::
+            #
+            #  from package.__init__ import something
+            #
+            # which seems quite correct.
+            if modpath[-1] == '__init__':
+                modpath.pop()
+            modname = '.'.join(modpath)
             _toload[0][modname] = fileordir
             _toload[1].append((fileordir, modname))
     return _toload