Skip to content
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

Poetry caching fails because Poetry is not installed #369

Closed
4 of 5 tasks
nwjsmith opened this issue Apr 1, 2022 · 17 comments
Closed
4 of 5 tasks

Poetry caching fails because Poetry is not installed #369

nwjsmith opened this issue Apr 1, 2022 · 17 comments
Assignees
Labels
bug Something isn't working

Comments

@nwjsmith
Copy link

nwjsmith commented Apr 1, 2022

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.

@nwjsmith nwjsmith added bug Something isn't working needs triage labels Apr 1, 2022
@dmitry-shibanov dmitry-shibanov self-assigned this Apr 1, 2022
@dmitry-shibanov
Copy link
Contributor

Hello @nwjsmith. Thank you for your report. It's an expected behaviour because the setup-python action uses poetry to get its configuration. Poetry should be preinstalled before using the setup-python action.

For now I'm going to close the issue.

@tony
Copy link

tony commented Apr 2, 2022

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.

@dmitry-shibanov
Copy link
Contributor

Hello @tony. Thank you for your report. I'll reopen the issue for deeper investigation.

@tony
Copy link

tony commented Apr 3, 2022

@dmitry-shibanov I created an independent issue here: #374 (with a minimal recreation example: https://github.com/tony/setup-python-poetry-version-example/)

srittau added a commit to srittau/rouver that referenced this issue May 9, 2022
@dmitry-shibanov
Copy link
Contributor

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

@jirojo2
Copy link

jirojo2 commented Sep 12, 2022

Doesn't work for me as of today @4.2.0

@taylor-shift
Copy link

This isn't fixed...the error still occurs as of today

@dunossauro
Copy link

Same issue here. Using version 4.5.0

@taylor-shift
Copy link

@dmitry-shibanov this issue is not fixed...any chance we can re-open this issue?

@khvn26
Copy link

khvn26 commented Feb 17, 2023

Sorry for a meaningless +1, but just bumped into this issue too. Hoping to see this fixed!

@EvanShaw
Copy link

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

@eduardoklosowski
Copy link

In all runners images there is already a relatively recent version of python 3 pre-installed (Included Software column), which can be used without problems to install poetry (except for Ubuntu 18.04 which will be discontinued), and python installed by setup-python after poetry is recognized normally when the virtual env is created, which doesn't cause any problems. I think that if it is not done in this sequence, setup-python would need to install poetry too, and why should it install poetry and not other options like pipenv, hatch, pdm...? Does it make sense for setup-python to have options to install these tools as well, or should it just focus on python?

And if you really need to install poetry on a specific version of python, you can use setup-python without use the cache options, install poetry, and call actions/cache directly afterward.

@EvanShaw
Copy link

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

@eduardoklosowski
Copy link

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

@EvanShaw because this action run poetry config --list (source) to know how poetry is configured and which directory should be cached. Otherwise the poetry configuration could be changed and the cache would not work properly either.

@telia-tomsan
Copy link

telia-tomsan commented Mar 22, 2023

I would like to advocate for the dependency on poetry to be removed. I'm trying to get this working on my company's own test runners but it's a pain, pip isn't preinstalled so I can't simply install poetry like in the examples.


EDIT: Turns out in my case this was a pretty easy fix, I just had to sudo apt-get update && sudo apt-get install -y python3-pip at the start of my workflow. However, it still feels really bad that the workflow spends 40 seconds installing pip and poetry, then spends 18 seconds installing Python, then 1 second to run my Python unit tests. If setup-python didn't depend on Poetry, I could at least jump straight to the Python install stage.

@adam-grant-hendry
Copy link

Hello @nwjsmith. Thank you for your report. It's an expected behaviour because the setup-python action uses poetry to get its configuration. Poetry should be preinstalled before using the setup-python action.

poetry is installed with python or pipx (which also requires python) except on MacOS where brew can be used, so it's often not possible to first install poetry (see #659).

The action should therefore install poetry after setting up python and configure the cache.

@adam-grant-hendry
Copy link

adam-grant-hendry commented Sep 15, 2023

poetry is installed with python or pipx (which also requires python) except on MacOS where brew can be used, so it's often not possible to first install poetry (see #659 (comment)).

Oops, I forgot about pre-installed software on each runner, and they all have python and pipx. My mistake...

MickaelFontes added a commit to MickaelFontes/dangling-finder that referenced this issue Feb 25, 2024
Need poetry install before, but it would not use the correct Python version
See actions/setup-python#369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests