I'm using https://github.com/jazzband/pip-tools to handle compiling the requirements.txt file for a Django project.
Previously, I was using it without a setup.py, and so I was using base.in, local.in, and production.in.
When I needed a local requirements.txt, after I finished running pip-compile, I just ran pip-sync base.txt local.txt, and it installed the requirements for the local environment.
When I needed a production requirements.txt, after I finished running pip-compile, I just ran pip-sync base.txt production.txt, and it installed the requirements for the production environment.
So, I switched away from using base.in, because I wanted to also lock the Python version and I realized setup.py and setup.cfg can help using python_requires.
But now I've become unsure of how to use setup.py and setup.cfg along with pip-tools to compile requirements.txt that can be environment-specific.
The only documentation for layered requirements is by using the different .in files as written in the README as in: https://github.com/jazzband/pip-tools#workflow-for-layered-requirements
So, my question is, with the following components:
- pip-tools
- setup.py and setup.cfg
How to still have layered requirements?
pip-toolsworks smoothly withsetup.pytoo. You just need to run it without providing it with an*.infile.Mixed variant with setup.py and in files:
So assuming, that you have the following structure:
and a local.in file:
you need to do the following to compile the dependencies:
$ pip-compile -o base.txtwill generate dependencies fromsetup.pyusingbase.txtas an output file. It defaults torequirements.txt.$ pip-compile local.inis the same what you did before, as with thepip-syncpart which doesn't change.So the only magic here is to run
pip-compilewithout providing it with an input file.Setup.py only solution:
Setup.py supports
extras_requirewhich is a dictionary of named optional dependencies:pip-tools has an option
extra:So you could do the following:
The output files contain all requiremenets in
install_requires+ the extra requirements specified.Afterwards you just sync the local/production.txt:
If I was you, I would grab the pure setup.py variant.