GitHub Actions
In GitHub Actions, the following steps will be taken to install Poetry
and verify that the correct version is installed:
1. Set the `PIPX_VERSION` and `POETRY_VERSION` environment variables,
which will be used to install specific versions of each package
2. Install `pipx` with `pip`, for the appropriate version of Python
(`pipx` is included by default in the GitHub Actions environment,
but only for the default Python version, not necessarily the version
installed by actions/setup-python)
3. Install Poetry with `pipx` instead of get-poetry.py/install-poetry.py
4. Test that the output of `poetry -V` matches `$POETRY_VERSION`
---
Docker
There are conflicting conventions when working with Poetry in Docker:
1. Docker's convention is to not use virtualenvs, because containers
themselves provide sufficient isolation.
2. Poetry's convention is to always use virtualenvs.
This project has previously preferred the Docker convention:
- Poetry itself was installed with the get-poetry.py script, with the
environment variable `POETRY_HOME=/opt/poetry` used to specify a
consistent location for Poetry.
- `poetry install` was used with `POETRY_VIRTUALENVS_CREATE=false` to
install the project's packages into the system Python directory.
The conventional Docker approach no longer works because:
- The old install script get-poetry.py is deprecated and not compatible
with Python 3.10.
- The new install script install-poetry.py has been problematic so far,
and Poetry doesn't really test it, so problems will likely continue.
In the updated approach:
- `ENV PATH=/opt/pipx/bin:/app/.venv/bin:$PATH` will prepare `$PATH`.
- `pip` will be used to install a pinned version of `pipx`.
- `pipx` will be used to install a pinned version of Poetry, with
`PIPX_BIN_DIR=/opt/pipx/bin` used to specify the location where `pipx`
installs the Poetry command-line application, and
`PIPX_HOME=/opt/pipx/home` used as the location for `pipx` itself.
- `poetry install` will be used with `POETRY_VIRTUALENVS_CREATE=true`,
`POETRY_VIRTUALENVS_IN_PROJECT=true` and `WORKDIR /app`
to install the project's packages into a virtualenv at `/app/.venv`.
Subsequent `python` commands will use `app/.venv/bin/python`. As long as
`POETRY_VIRTUALENVS_IN_PROJECT=true` and `WORKDIR /app` are retained,
subsequent Poetry commands will use the same virtualenv at `/app/.venv`.