Skip to content

Latest commit

 

History

History
94 lines (73 loc) · 2.32 KB

PIPTOOLS.md

File metadata and controls

94 lines (73 loc) · 2.32 KB

Pip & pip-tools

Sometimes you can't use poetry or your environment is somewhat constrained to only pip. Or for better compatability when locking down your dependencies for Docker. I'm using pip-tools here until I determine the pip only route to achieve the same thing.

pip-tools quickstart

Ultra quickstart for a bare minimum virtual environment and a requirements.in

python3 -m venv .venv
.venv/bin/python3 -m pip install -U pip pip-tools
.venv/bin/python3 -m piptools compile --generate-hashes requirements.in --output-file requirements.txt
.venv/bin/python3 -m pip install -r requirements.txt --require-hashes --no-deps --only-binary :all:

If you want to separate your requirements into requirements/app.in, requirements/test.in then follow this:

mkdir -p requirements src/myproject
touch src/myproject/__init__.py

https://www.b-list.org/weblog/2022/may/13/boring-python-dependencies/

pyproject.toml

[project]
name = "myproject"
description = ""
version = "0.1.0"
authors = []


[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

requirements/app.in

-e .
flask

Now generate the hashes...

python3 -m pip install --upgrade pip-tools
python3 -m piptools compile --generate-hashes requirements/app.in --output-file requirements/app.txt

requirements/app.txt

#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --generate-hashes --output-file=requirements/app.txt requirements/app.in
#
-e file:///Users/username/path/to/project
    # via -r requirements/app.in
blinker==1.7.0 \
    --hash=sha256:c3f865d4d54db7abc53758a01601cf343fe55b84c1de4e3fa910e420b438d5b9 \
    --hash=sha256:e6820ff6fa4e4d1d8e2747c2283749c3f547e4fee112b98555cdcdae32996182
    # via flask
click==8.1.7 \
    --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
    --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
    # via flask
.....
etc, etc, etc

https://www.b-list.org/weblog/2023/dec/07/pip-install-safely/

python -m pip install \
    --require-hashes \
    --no-deps \
    --only-binary :all: \
    -r requirements/app.txt