cbrxyz / pi-bot

🤖 Scioly.org's resident bot
9 stars 5 forks source link

Add `requirements.in` and use `pip-compile` to generate `requirements.txt` #488

Open Nydauron opened 4 months ago

Nydauron commented 4 months ago

It makes sense to have requirements.txt be a lockfile, but trying to modify the version numbers of top-level dependencies can be a nightmare.

The proposed idea is to add a new file, requirements.in, that contains all top-level dependencies. These constraints can target a range or a specific version. We can then use pip-compile (from the pip-tools package, installable via pip install pip-tools) to generate a requirements.txt file:

pip-compile --output-file=requirements.txt --strip-extras

The lockfile can then be updated to the newest versions (as allowed by requirements.in) by running:

pip-compile -U --output-file=requirements.txt --strip-extras

Adding or updating version constraints in requirements.in should then result in pip-compile being run which can be enforced by adding an additional git hook on pre-commit.