pip-tools
pip-tools = pip-compile + pip-sync
A set of command line tools to help you keep your pip-based packages fresh, even when you've pinned them.
pip-compile
compile a requirements.txt file from your dependencies, specified in either pyproject.toml, setup.cfg, setup.py, or requirements.in.
python -m piptools compileでも
複数のPythonバージョンで実行すればよい
you can use pip-compile to pin the dependencies in projects that use modern standards-adhering packaging tools like Setuptools, Hatch or flit. extra(optional-dependencies)にも対応
pip-compile --extra dev -o dev-requirements.txt pyproject.toml
pip-compile generates a requirements.txt file using the latest versions that fulfil the dependencies you specify in the supported files.
(全パッケージを対象にせずに)--upgrade-packageで最新にするパッケージを指定できる
--pip-argsでpipコマンドに渡す引数を指定できる
Workflow for layered requirements
code:dev-requirements.in
-c requirements.txt # django<2.2 としている
django-debug-toolbar<2.2
even though a 2.2 release of Django is available, the dev requirements only include a 2.1 version of Django because they were constrained.
--all-build-deps
--all-extras
--no-annotate(コメントが出力されない)
-c (constraint)
pip-sync
(pip-compileの「Workflow for layered requirements」の続き)
To install requirements in production stage use:
pip-sync
You can install requirements in development stage by:
pip-sync requirements.txt dev-requirements.txt
Should I commit requirements.in and requirements.txt to source control?
Generally, yes.
pip-tools is a great tool to improve the reproducibility of builds. But there are a few things to keep in mind.
pip-compile will produce different results in different environments
pip must be used with the PIP_CONSTRAINT environment variable to lock dependencies in build environments
Dependencies come from many sources.
Other useful tools
pip-compile command wrapper for multiple cross-referencing requirements files.
IMO:pip-compileをextraごとに実施して、txtファイルをいくつか選んでpip-syncするのもありでは