Reputation: 2887
for the sake of the question, let's assume that under one git repository, I'm developing 2 independent packages. Consider the following structure:
my_repo/
package1/
...some modules
package2/
...some modules
setup.py
setup.py code is:
from setuptools import setup
setup(
name='Cool_package',
version=1.0,
description='...',
author='Myself',
packages=['package1', 'package2'],
install_requires=[
...
]
)
I'm using this command to install the packages in desired manner (avoiding python setup.py install or develop):
pip install -e .
And both package1 and package2 are installed.
My question is there a way to install only one of the two (user decides which one), considering that mentioned above structure requires them to share one setup.py file?
Again, I'm aware of that structure is not ideal (ideally I would split the packages into 2 separated repos).
Many thanks in advance!
Upvotes: 1
Views: 1283
Reputation: 36269
I suggest you to create one setup script for each package. You can share common information via a general setup.py
script like so:
repo/
├── bar
├── foo
├── setup_bar.py
├── setup_foo.py
└── setup.py
2 directories, 3 files
Then the common setup.py
file would contain the following code. It can also be used to install both packages at once:
from functools import partial
from setuptools import setup
setup = partial(
setup,
name='Cool_package',
version=1.0,
description='...',
author='Myself',
packages=['foo', 'bar']
)
if __name__ == '__main__':
setup()
The separate setup_*.py
scripts would reuse that information and only install a single package:
from setup import setup
setup(packages=['foo']) # For `setup_foo.py`.
setup(packages=['bar']) # For `setup_bar.py`.
This way the user can choose which package to install by using the corresponding setup script.
Upvotes: 1