1. Ronald Oussoren
  2. modulegraph
  3. Issues
Issue #19 new

Simplifying calc_setuptools_nspackages

created an issue

calc_setuptools_nspackages can be implemented much simpler.


  1. If a name space-package is defined this way (in a .pth-file), the .pth-file must have been processed on startup of the Python interpreter (in site.py). Otherwise the package would not be available in normal operation.
  2. Since the .pth-file is already processed, there is no need to search for .pth-files.
  3. The .pth-file puts a dummy-module into sys.path, which can be testes quite easily:

I have implemented such a test for PyInstaller. Here is the code:

class NamespaceImportDirector(BuiltinImportDirector):
    def __init__(self):
        self.path = 'Namespace'

    def getmod(self, nm, isbuiltin=imp.is_builtin):
        except KeyError:
            # not in sys.modules: module does not exist at all
            return None
        except ImportError:
            # in sys.modules, but not found: namespaced module
            return depend.modules.NamespaceModule(nm)
        return None

Comments (3)

  1. Ronald Oussoren repo owner

    I'll probably implement this, but need some time to fully think through the consequences of the change. Python's import machinery is fairly hairy, especially when setuptools is involved and you cannot use importlib ;-)

  2. Log in to comment