Ronald Oussoren avatar Ronald Oussoren committed e1eaf96

Fix the way the __init__ module for packages is looked up (issue #12)

Comments (0)

Files changed (5)


   Reported by Andrew Barnert.
+* Issue #12: modulegraph would sometimes find the wrong package *__init__*
+  module due to using the wrong search method. One easy way to reproduce the
+  problem was to have a toplevel module named *__init__*.
+  Reported by Kentzo.


             self.msg(2, "find __init__ for %s"%(m.packagepath,))
-            fp, buf, stuff = self.find_module("__init__", m.packagepath)
+            fp, buf, stuff = self.find_module("__init__", m.packagepath, parent=m)
         except ImportError:


         node ='pkg.core.listenerimpl')
         self.assertIsInstance(node, modulegraph.SourceModule)
+class TestRegression5 (unittest.TestCase):
+    if not hasattr(unittest.TestCase, 'assertIsInstance'):
+        def assertIsInstance(self, value, types):
+            if not isinstance(value, types):
+      "%r is not an instance of %r"%(value, types))
+    def setUp(self):
+        root = os.path.join(
+                os.path.dirname(os.path.abspath(__file__)),
+                'testpkg-regr5')
+ = modulegraph.ModuleGraph(path=[ root ] + sys.path)
+, ''))
+    def testRegr1(self):
+        node ='distutils')
+        self.assertIsInstance(node, modulegraph.Package)
+        self.assertIn('distutils/__init__', node.filename)
 if __name__ == "__main__":


+""" A dummy __init__ file """


+import __init__
+from modulegraph.find_modules import find_needed_modules
+import distutils
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.