1

pip-compile enables traceability in pinning requirements inside a requirements.txt with an external requirements.in. I really like this

My question is, can we somehow do the same, but for an install_requires list inside setup.py?

In other words, if I don't have a requirements.txt but instead just a setup.py, is it possible to use pip-compile?

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
  • Generate `requirements.txt` and read it in `setup.py`. You can do simple reaing like [this](https://stackoverflow.com/a/50931854/7976758) or you can do more complex [parsing](https://stackoverflow.com/a/59971236/7976758). – phd Jun 21 '22 at 17:57
  • @phd A best practice question here... would it be better to (a) generate requirements.txt from `install_requires` in setup.py, or (b) parse requirements.txt to generate `install_requires` list in setup.py ? – jacaheyo Sep 14 '22 at 09:58
  • @jacaheyo How you gonna automatically generate `requirements.txt` from `install_requires`? – phd Sep 14 '22 at 11:59

1 Answers1

2

Yes, pip-tools supports pyproject.toml, setup.cfg, and setup.py configuration files from version 6.1.0 (2021-04-14).

You should just run:

pip-compile -o requirements.txt YOUR_CONFIG_FILE
# where YOUR_CONFIG_FILE can be a setup.py
# or even simpler
pip-compile YOUR_CONFIG_FILE

Take a look at the documentation:

Requirements from pyproject.toml

Requirements from setup.py and setup.cfg

Changelog, verson 6.1.0 (2021-04-14)

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
wankata
  • 855
  • 4
  • 12