[appobject imports] don't include __init__ in package's name. See comment for more info stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 30 Mar 2010 13:28:19 +0200
branchstable
changeset 5078 ea66c4aabb47
parent 5077 dc448c9ad9dd
child 5079 e646047f80cb
[appobject imports] don't include __init__ in package's name. See comment for more info
vregistry.py
--- 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