Skip to content

Commit

Permalink
Export Poetry's lockfile as pip requirements.txt
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabcor-maxiv committed Jul 8, 2024
1 parent 32780ba commit bb49ef0
Show file tree
Hide file tree
Showing 3 changed files with 1,455 additions and 2 deletions.
25 changes: 24 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,32 @@ repos:
- --strict

- repo: https://github.com/python-poetry/poetry
rev: 1.5.0
rev: 1.8.3
hooks:

# Equivalent to running `poetry check --lock`.
# This checks that:
# 1. the Poetry content of the `pyproject.toml` file is valid;
# 2. there is a `poetry.lock` file;
# 3. the content of `poetry.lock` is in sync with the content of `pyproject.toml`.
- id: poetry-check
args:
- --lock

# Equivalent to running `poetry lock --no-update`.
# This syncs the `poetry.lock` file with the content of the `pyproject.toml` file.
# This hook fails if it results in modifying `poetry.lock`.
- id: poetry-lock
args:
- --no-update

# Equivalent to running `poetry export`.
# This exports the `poetry.lock` file to the `requirements.txt` file.
# This hook fails if it results in modifying `requirements.txt`.
- repo: https://github.com/python-poetry/poetry-plugin-export
rev: 1.8.0
hooks:
- id: poetry-export

- repo: https://github.com/myint/autoflake
rev: v1.6.0
Expand Down
10 changes: 9 additions & 1 deletion docs/source/dev/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Some might prefer to use a dedicated installer tool, like pip for such a task.

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

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

Note that the pre-commit hooks are configured to automatically
generate an exported `requirements.txt` file and keep it in sync with `poetry.lock`.
So this step could be skipped.

1. Move the `requirements.txt` file to the deployment target system

1. On the deployment system, let pip install {{project}} via the exported requirements file
1. On the deployment system,
let pip install {{project}} via the exported requirements file

1. Install the dependencies
```shell
Expand Down
Loading

0 comments on commit bb49ef0

Please sign in to comment.