How to manage multiple python subprojects using setuptools?

I am wondering what is the right / easiest / most pythonic way to deal with the subprojects you want to use with the same base package. Currently we have the following file structure:

trunk\ proj1\setup.py company_name\__init__.py + proj1 code proj2\setup.py company_name\__init__.py + proj2 code 

We want the company_name namespace name to be common to all of our projects (maybe this alone doesn’t work), but when proj1 and proj2 are installed in development mode, the first one installed is broken. It looks like import company_name... confused about which company_name package will look in and it captures first / last / random.

How is this usually handled in a larger python project? Is it possible to resolve this with setup.py in the trunk, which creates a kind of mega-egg? I did not find any relevant information about google or the stack, so any information, even just links, is greatly appreciated!


edit: I just tried adding setup.py to the root folder using

 ... namespace_packages = ['company_name'], package_dir = {'company_name' : ['proj1/company_name', 'proj2/company_name']} ... 

with the corresponding pkg_resources.declare_namespace(__name__) in the __init_.py files, but ./setup.py bdist_egg just gives:

error in setup_name command: Distribution does not contain modules or packages for namespace package 'company_name'

+7
python package setuptools project
source share
1 answer

While I cannot vouch for the pythonity of my solution, I finally got different applications that work together. I was on the right track with namespace packages, but instead of trying to have one superproject in my trunk, I added the namespace_packages line to the setup.py of each individual project. This led to the correct operation when installing together, splitting the company_name namespace as intended.

Anyone who wants to listen to this is a reasonable python solution, I am still interested in hearing "this is so." It feels good, but it could be because it imitates the java style that I'm more used to.

+6
source share

All Articles