1

I want to keep multiple python modules in the same repo so it's easier to manage them, and work on them simultaneously.

The modules are packaged namespace packages, so I can't have the roots at the same level, and there are 4 of them, and might be more later.

Here's the structure I have:

repo/
  modules/
    foo_a/
      setup.py
      VERSION
      foo/
        __init__.py
        a/
    foo_b/
      setup.py
      VERSION
      foo/
        __init__.py
        b/

The VERSION files are separate and track different versions. And the __init__.py files above are the special type described here.

Currently I automatically build the respective module when the VERSION file in it changes.


What I want is to be able to install the entire package with all namespace packages from the root of the repo. So I can just do pip install .. Either this would install everything as a single package (foo_all) or individually install each module.

The usecase for this, is that most people use all modules and they want something easy to install, but sometimes I just want to be able to install one of the modules.

The key thing is that you can run:

pip install repo

and then these Python commands succeed.

from foo import a
from foo import b

Any ideas on how to do this?

I've seen the setuptools.find_namespace_packages() function, but that looks like it's only Python3, and I'm not entirely sure it's what I need anyway. I can't upgrade to Python3 because it's for a client and it's dependent on a Python2 API, which is incredibly frustrating.

Also seen the package_dir option for setuptools.setup(), but that's for if all the packages are just in a different folder. I can't put all the package in a different folder because the individual files would overlap (setup.py, VERSION, foo/)

blueteeth
  • 3,330
  • 1
  • 13
  • 23

1 Answers1

0

I suggest distributing foo.a and foo.b as independent projects alongside a foo project that serves as some kind of "umbrella project" and has the other two as direct dependencies (in install_requires).

The whole setup is described in the Python Packaging User Guide on "Packaging namespace packages". See also this answer to a similar question.

sinoroc
  • 18,409
  • 2
  • 39
  • 70