Skip to content

Commit 8ce28bc

Browse files
fabcor-maxivmarcus-oscarsson
authored andcommitted
Export Poetry's lockfile as pip requirements.txt
This will let the pre-commit hooks ensure that Poetry's lockfile is kept up-to-date and that it is exported to a pip `requirements.txt` file. GitHub: fix #1268
1 parent 6aff077 commit 8ce28bc

File tree

3 files changed

+1455
-2
lines changed

3 files changed

+1455
-2
lines changed

.pre-commit-config.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,32 @@ repos:
1313
- --strict
1414

1515
- repo: https://github.com/python-poetry/poetry
16-
rev: 1.5.0
16+
rev: 1.8.3
1717
hooks:
18+
19+
# Equivalent to running `poetry check --lock`.
20+
# This checks that:
21+
# 1. the Poetry content of the `pyproject.toml` file is valid;
22+
# 2. there is a `poetry.lock` file;
23+
# 3. the content of `poetry.lock` is in sync with the content of `pyproject.toml`.
1824
- id: poetry-check
25+
args:
26+
- --lock
27+
28+
# Equivalent to running `poetry lock --no-update`.
29+
# This syncs the `poetry.lock` file with the content of the `pyproject.toml` file.
30+
# This hook fails if it results in modifying `poetry.lock`.
31+
- id: poetry-lock
32+
args:
33+
- --no-update
34+
35+
# Equivalent to running `poetry export`.
36+
# This exports the `poetry.lock` file to the `requirements.txt` file.
37+
# This hook fails if it results in modifying `requirements.txt`.
38+
- repo: https://github.com/python-poetry/poetry-plugin-export
39+
rev: 1.8.0
40+
hooks:
41+
- id: poetry-export
1942

2043
- repo: https://github.com/myint/autoflake
2144
rev: v1.6.0

docs/source/dev/deployment.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Some might prefer to use a dedicated installer tool, like pip for such a task.
3434

3535
But Poetry's lockfile format is not standardized, its content is specific to Poetry.
3636
So this file is not immediately usable by other installers and tools.
37+
For example pip can not understand `poetry.lock` and completely ignores it.
38+
When running a command like `pip install mxcubeweb`
39+
it will NOT choose the versions pinned in `poetry.lock`.
3740

3841
To circumvent this, one could use a command like `poetry export`
3942
to generate a `requirements.txt` file compatible with pip (and some other tools).
@@ -45,9 +48,14 @@ it should be possible to approximate the behaviour of installing with Poetry's l
4548
poetry export --format=requirements.txt > requirements.txt
4649
```
4750

51+
Note that the pre-commit hooks are configured to automatically
52+
generate an exported `requirements.txt` file and keep it in sync with `poetry.lock`.
53+
So this step could be skipped.
54+
4855
1. Move the `requirements.txt` file to the deployment target system
4956

50-
1. On the deployment system, let pip install {{project}} via the exported requirements file
57+
1. On the deployment system,
58+
let pip install {{project}} via the exported requirements file
5159

5260
1. Install the dependencies
5361
```shell

0 commit comments

Comments
 (0)