-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install Poetry with pipx #47
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/br3ndonland/inboard/8WLzDUrKnkT4YY5rVWJynKMDBnEV |
Codecov Report
@@ Coverage Diff @@
## develop #47 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 264 264
=========================================
Hits 264 264
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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`.
b0b49c4
to
ebd8454
Compare
#47 9476d5b b33af2a This commit will add the `poetry config --local virtualenvs.create true` setting to poetry.toml. This setting is true by default, but it will be added to poetry.toml for consistent configuration. The environment variable `POETRY_VIRTUALENVS_CREATE` can also be used to configure this setting. The environment variable value takes precedence. https://github.com/python-poetry/poetry/blob/10d5559/poetry/config/config.py#L103-L126 When the new pipx install method from #47 is released, projects will therefore need to remove `POETRY_VIRTUALENVS_CREATE` from Dockerfiles and other configuration files for compatibility.
After creating numerous problems for maintainers by cramming breaking changes into patch releases, Poetry finally released a minor version, 1.2, which should probably have been a major version. In order to upgrade, each project will need to update its pyproject.toml (to support groups), update any references to the install script (which has been moved twice), and make several other associated changes. This commit will set an upper bound on the `pipx install poetry` command to avoid upgrading to Poetry 1.2. br3ndonland/inboard#36 br3ndonland/inboard#44 br3ndonland/inboard#47 https://python-poetry.org/blog/announcing-poetry-1.2.0/
Description
Poetry has introduced some breaking changes recently. To help buffer against these breaking changes, and to promote reproducible Poetry installations, this PR will install Poetry with
pipx
instead of get-poetry.py.Changes
GitHub Actions
The following steps will be taken to install Poetry and verify that the correct version is installed:
PIPX_VERSION
andPOETRY_VERSION
environment variables, which will be used to install specific versions of each package.POETRY_VIRTUALENVS_IN_PROJECT=true
environment variable so that Poetry uses a consistent path for the project's virtualenv.pipx
withpip
, for the appropriate version of Python.pipx
is included by default in the GitHub Actions virtual environment, but only for the default Python version, not necessarily the version installed by actions/setup-python.pipx
, instead of the get-poetry.py and install-poetry.py install scripts.poetry install
as usual.poetry -V
command matches$POETRY_VERSION
.These steps promote reproducible Poetry installations.
Docker
As explained in python-poetry/poetry#1879 (comment), there are two conflicting conventions to consider when working with Poetry in Docker:
This project previously preferred the Docker convention:
POETRY_HOME=/opt/poetry
used to specify a consistent location for Poetry.poetry install
was used withPOETRY_VIRTUALENVS_CREATE=false
to install the project's packages into the system Python directory.The conventional Docker approach no longer works because:
In the updated approach:
ENV PATH=/opt/pipx/bin:/app/.venv/bin:$PATH
will be set first to prepare the$PATH
.pip
will be used to install a pinned version ofpipx
.pipx
will be used to install a pinned version of Poetry, withPIPX_BIN_DIR=/opt/pipx/bin
used to specify the location wherepipx
installs the Poetry command-line application, andPIPX_HOME=/opt/pipx/home
used to specify the location forpipx
itself.poetry install
will be used withPOETRY_VIRTUALENVS_CREATE=true
,POETRY_VIRTUALENVS_IN_PROJECT=true
andWORKDIR /app
to install the project's packages into the virtualenv at/app/.venv
.Subsequent
python
commands will use the executable atapp/.venv/bin/python
. As long asPOETRY_VIRTUALENVS_IN_PROJECT=true
andWORKDIR /app
are retained, subsequent Poetry commands will use the same virtual environment at/app/.venv
.For a Poetry project with the following directory structure:
repo/
package/
__init__.py
main.py
Dockerfile
poetry.lock
pyproject.toml
A minimal Dockerfile could look like this:
Related