setup-python: v3.1's default poetry example uses wrong python version

Description:

The default configuration example for #281’s new example installs poetry before actions/setup-python is ran.

This can run into some funky issues in poetry itself since poetry may stick to use the python version it was installed in.

This may be on the poetry side. I’m not sure:

Action version: v3.1

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Repro steps:
Reproduction repo: https://github.com/tony/setup-python-poetry-version-example

Runs: https://github.com/tony/setup-python-poetry-version-example/actions

Expected behavior: poetry should respect the version in actions/setup-python

Actual behavior: It uses the python version poetry was installed with before actions/setup-python was ran.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 16
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

You can get around this problem by telling poetry to use the same version of python as installed by setup-python with the poetry env use command

This has been working for me:

- uses: actions/checkout@v3

- name: Install poetry
  run: pipx install poetry

- name: Setup Python
  uses: actions/setup-python@v3
  with:
    python-version: "3.10"
    cache: "poetry"

- name: Install dependencies
  run: |
    poetry env use "3.10"
    poetry install --no-interaction

Unfortunately, poetry is still broken with v4.

To solve it, I used the GitHub API to get a list of caches, and then delete it.

How did you delete it? Where did you delete it from?

First I ran this, to get a list of the caches, in this case, there was only one.

gh api \
 -H "Accept: application/vnd.github+json" \
 /repos/OWNER/REPO/actions/caches

Then I ran this, to delete the cache, based off of the cache ID in the previous command.


gh api \
  --method DELETE \
  -H "Accept: application/vnd.github+json" \
  /repos/OWNER/REPO/actions/caches/CACHE_ID

More information available here: https://docs.github.com/en/rest/actions/cache

I encountered this issue as well, and spent some time trying to figure out why this was still happening after upgrading the action to v4.2.0. It is cache, it had the wrong python version cached.

To solve it, I used the GitHub API to get a list of caches, and then delete it. Once done, I re-ran the workflow, and it rebuilt the cache and had the correct python version.

Hello everyone. Sorry for the late response. We released a new version of the action and updated the major tag with possible fix. Could you please confirm that everything works as expected.

I can confirm the latest version (4.2.0) fixes the problem in the places I’ve previously had to add the poetry env use 3.10 workaround. Thanks!

How hard would it be to defer caching to a later step? Then you wouldn’t have to rely on the system version of Python. I’m thinking something like this:

- name: Install Python
  uses: actions/setup-python@v3
  with:  # Install Python, skip caching
    python-version: ${{ matrix.python-version }}
- name: Install poetry
  run: python -m pip install poetry
- name: Cache Poetry deps
  uses: actions/setup-python@v3
  with:  # Restore cache, skip Python installation
    cache: poetry