4 ms·
> Also the requirements.txt file tends to get cluttered with non top level dependencies that make upgrading your dependencies an herculean task. Instead on poet
by ptx 4y ago
> Also the requirements.txt file tends to get cluttered with non top level dependencies that make upgrading your dependencies an herculean task. Instead on poetry you define your top level dependencies in your pyproject.toml and all the actual pinned dependencies will be compiled into a poetry.lock file.
This has now been solved [1] in pip, so no third-party tool is needed. Put your pinned dependencies in constraints.txt and your top-level dependencies plus the line "-c constraints.txt" in requirements.txt.
[1] https://pip.pypa.io/en/stable/user_guide/#constraints-files https://pip.pypa.io/en/stable/user_guide/#constraints-files
- partido3619463 4y agoConstraints are not the same thing. Poetry locks the entire dependency closure. You can install with “no-deps” option, but then you have to specify specific versions of every dependency in requirements.txt
- ptx 4y agoWhat do you mean? If you do "pip freeze >constraints.txt", that locks the versions of all installed packages, no matter where they came from. As an example, let's create a venv and install some older versions of Django and its dependencies (current versions are 0.4.2, 3.5.2 and 4.0.6) $ python3 -m venv env1 $ ./env1/bin/pip install sqlparse==0.4.0 asgiref==3.5.0 django=4.0.0 ...and also Flask just to complicate the constraints file for the example: $ ./env1/bin/pip install flask Lock all dependency versions in constraints.txt: $ ./env1/bin/pip freeze >constraints.txt Create a requirements file that specifies just "django" and references the constraints file: $ echo '-c constraints.txt' >requirements.txt $ echo 'django' >>requirements.txt $ cat requirements.txt -c constraints.txt django $ cat constraints.txt asgiref==3.5.0 click==8.1.3 Django==4.0 Flask==2.1.3 itsdangerous==2.1.2 Jinja2==3.1.2 MarkupSafe==2.1.1 sqlparse==0.4.0 Werkzeug==2.1.2 Now we can create another venv with the exact same versions of Django and all its dependencies (but not Flask or its dependencies) using just pip and the requirements file: $ python3 -m venv env2 $ ./env2/bin/pip install -r requirements.txt $ ./env2/bin/pip freeze asgiref==3.5.0 Django==4.0 sqlparse==0.4.0
- ok_dad 4y agoThat’sa lot more than just poetry init poetry add x y z Then later poetry install And maybe poetry remove y