pythonnetworkxnamespace-package

Tree structure for namespace package


I have an package named networkx-metis which has the following tree structure

networkx-metis/
              setup.py
              networkx/
                      __init__.py
                      addons/
                            __init__.py
                            metis/
                                 metis.py

networkx.addons.metis is supposed to be installed as a namespace package in networkx core package. The two __init__.py above contains the single line of code

__import__('pkg_resources').declare_namespace(__name__)

Now I have some specific questions,


Solution

  • What should be the changes in the networkx core package? Where should I put empty __init__.py files?

    Add a __init__.py inside networkx/addons/ with the single line of code in it

    __import__('pkg_resources').declare_namespace(__name__)
    

    What should be the value of namespace_packages in setup() of the setup.py of networkx-metis?

    It should be

    namespace_packages = ['networkx.addons', 'networkx']