setup-python: Poetry caching fails because Poetry is not installed

Description: Poetry caching fails because Poetry is not installed.

Action version: v3

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version: All Python versions.

Repro steps:
Run a workflow with the setup-python action using the cache: 'poetry' argument. I have set up a minimal reproduction in a public repository. There is an example of a failed workflow run in that project.

Expected behavior: I would expect Poetry dependencies to be restored if they exist.

Actual behavior: The step fails due to a missing poetry executable.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Doesn’t work for me as of today @4.2.0

This should be reopened. The docs also still indicate that poetry must be installed before using this action: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages

I think it goes without saying, but until this gets resolved, python being a prerequisite of poetry renders the use of this action pretty much pointless

The reason I’m not filing a separate is I think it’d be closed on the same grounds as this issue.

But I’d like to note my workaround for python versions and poetry 1.x to work:

It looks like installing poetry before actions/setup-python causes poetry to use the earlier python version. e.g. if GH uses python 3.8 by default and poetry is installed in that, your poetry is going to run in 3.8, no matter what actions/setup-python is.

It looks like poetry install doesn’t obey the python version that actions/setup-python uses.

Here’s an example

My workaround is to use a matrix and poetry env <version>

name: tests

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [ '3.10' ]
    steps:
      - uses: actions/checkout@v3
      - name: Install poetry
        run: |
          curl -O -sSL https://install.python-poetry.org/install-poetry.py
          python install-poetry.py -y --version 1.1.12
          echo "PATH=${HOME}/.poetry/bin:${PATH}" >> $GITHUB_ENV
          rm install-poetry.py

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'poetry'

      - name: Install dependencies
        run: |
          # This is required to do as of @actions/checkout@v3 to prevent default action python (3.8) from being used
          poetry env use ${{ matrix.python-version }}
          poetry install

      - name: Lint with flake8
        run: poetry run flake8

      - name: Print python versions
        run: |
          python -V
          poetry run python -V

      - name: Test with pytest
        run: poetry run py.test

You can replace "Install poetrywithpipx install poetry, or pipx install poetry==1.1.12`, etc.

This isn’t fixed…the error still occurs as of today

Hello everyone. For now I’m going to close the issue because we released a new version with fix and updated major tag.

I don’t know about other people’s use cases, but consider this scenario:

  • install a specific version of python with this action
  • create a virtualenv (eg: python3 -m venv .venv)
  • install poetry through the virtualenv (.venv/bin/pip install poetry)
  • install packages with poetry (.venv/bin/poetry install)

In this scenario, using the cache option will fail because poetry doesn’t exist, but why does poetry need to exist before the cache is even accessed? It hasn’t installed any packages yet