htgoebel  committed 75b3cfc

Fix: Namespace-Pkgs only in ModuleGraph.path, but not in sys.path are not found.

Reason was: _namespace_package_path used pkg_resources.working_set,
which is constructed when pkg_resources is imported and based only on

  • Participants
  • Parent commits b36eb05

Comments (0)

Files changed (1)

File modulegraph/

-def _namespace_package_path(fqname, pathnames):
+def _namespace_package_path(fqname, pathnames, path=None):
     Return the __path__ for the python package in *fqname*.
     This function uses setuptools metadata to extract information
     about namespace packages from installed eggs.
+    working_set = pkg_resources.WorkingSet(path)
     path = list(pathnames)
-    working_set = pkg_resources.working_set
     for dist in working_set:
         if dist.has_metadata('namespace_packages.txt'):
             namespaces = dist.get_metadata(
             # works, it is not clear yet why that is. Setting to None would be
             # cleaner.
             m.filename = '-'
-            m.packagepath = _namespace_package_path(name, pathnames)
+            m.packagepath = _namespace_package_path(name, pathnames, self.path)
             # As per comment at top of file, simulate runtime packagepath additions.
             m.packagepath = m.packagepath + _packagePathMap.get(name, [])
         if newname:
             fqname = newname
-        ns_pkgpath = _namespace_package_path(fqname, pkgpath or [])
+        ns_pkgpath = _namespace_package_path(fqname, pkgpath or [], self.path)
         if ns_pkgpath or pkgpath:
             # this is a namespace package
             m = self.createNode(NamespacePackage, fqname)