I've reorganized my Python project to be under a same name umbrella. My project can now be seen as multiple subsystems than can depend on each other. That means that every submodule can now be distributed alone so that only required dependencies can be installed.
The old structure:
/
├─ myproj/
│ ├─ __init__.py
│ ├─ mod1.py
│ ├─ subpackage1/
│ └─ subpackage2/
└─ setup.py
The new structure:
/
├─ myproj/
│ ├─ common/
│ │ └─ mod1.py
│ ├─ subpackage1/
│ └─ subpackage2/
└─ setup.py
As you can see not much has changed except that myproj
is now a namespace package and that sub-packages common
, subpackage1
and subpackage2
can now be distributed independently.
Is it possible, still keeping one unique setup.py
file, to create 3 independent packages?
myproj.common
myproj.subpackage1
myproj.subpackage2
Also I'd like to specify that when installing myproj.subpackage1
, myproj.common
is required or that myproj.subpackage2
will require both myproj.common
and myproj.subpackage1
.
As Martijn Pieters stated it is just python code, so yes you can do this. I don't even think this would be all that difficult either.
Basically you just want to manipulate the command line arguments in setup.py
Once again though as Martijn Pieters stated it is probably not worth the effort. Python's main philosophy is that simple is better than complex. If your two sub-packages are completely different then maybe they should be different projects.
Example: Scipy
I tried to think of an example for why not to do this, but apparently
scipy
does this. So I may be wrong in trying to dissuade you. Still probably not worth the effort, because most people justpip install scipy
.It's interesting. Scipy's structure is very well thought out. Scipy has every sub-package as a Python package (directory with an __init__.py file.). Inside of every package is a setup.py file. They also use
numpy.distutils.misc_util.Configuration
to add sub packages.If you look through their source code, scipy's main setup.py file looks like.
So it looks like a good solution has already been found for you.