-
Notifications
You must be signed in to change notification settings - Fork 619
Recommendations for caching poetry dependencies causes the wrong python version to be used for poetry install #846
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
Comments
Hello @sdb9696 |
Hello @sdb9696 – my team ran into this same issue recently. We solved it by pinning the python version in our [tool.poetry.dependencies]
python = "3.11.4" |
Thanks @andwaredev but we run our CI against all supported python versions to check there are no issues so not sure this workaround will help. |
I find it highly concerning that the recommend and only working solution for caching poetry venvs is to install poetry before This is what I would like to see working: - uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- run: pipx install poetry |
It's always struck me as a bad chicken/egg problem that poetry is the only cache type that requires the environment manager to be installed before it can be used. Even pipenv is not required to be installed
The Poetry default cache location is well known and I bet in CI the vase majority of projects are using that case. The big difference appears to be that the Poetry option is trying to support the fact that Poetry can install virtual environments in the project. Pipenv can also do this but it's just ignored for that option. I'd recommend just caching the default location like Pipenv, or you could have an option for enabling caching in project virtual environments it people use it. |
@silverwind You can tell poetry to use a specific version of python prior to running install https://python-poetry.org/docs/managing-environments#switching-between-environments |
@evilhamsterman doesn't really help me if there is simply no |
This also makes the assumtion that you have pipx which I do not :) I'd highly recommend to install poetry as part of this python version fetching if cache is set to poetry. Chances are everyone is going to need poetry if they are using poetry cache, so maybe get the specific python version with poetry pre-installed. This seems to be the only viable solution. |
I think |
Apparently, it doesn't so to install poetry without pip and having a poetry cache, this would be the ideal: - uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- uses: snok/install-poetry@v1 |
This is indeed inconvenient. We install Python and Poetry in the following way:
This triggered the following error:
Do note how the installation is failing because Poetry is using Python 3.10 while the specified Python version is 3.12. This took a while to chase down. I'm not sure what exactly depends on Poetry but perhaps it would be possible to integrate those functions into setup-python instead of having a hard dependency on the whole package? Alternatively, if there's a workaround it would be great if the documentation could be updated. |
Ultimately we're considering just using actions/cache directly to cache poetry rather than setup-python's built in support |
I just ran into this issue as well. I used an example in the docs that triggers this bug beautifully. Maybe time to ramp up the tests for this action? |
I am running the following workflow which works: jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pipx install poetry==1.8.3
- run: echo "/root/.local/bin" >> $GITHUB_PATH
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: poetry
- run: pipx install poetry==1.8.3
- run: poetry install
working-directory: app
- run: poetry run flake8
working-directory: app
What I had to do was add
|
Hi @sdb9696 , It is the expected behaviour, if the setup python tries to install the python version which was not specified in pyproject.toml file, under [tool.poetry.dependencies], the poetry install use the python version used during poetry installation from runner. Here's the screenshots for your reference.
![]() ![]() |
Hi @sdb9696, Just a gentle reminder regarding this issue, We have updated the document. If you have any questions or need further assistance, Please let us know. |
Hi @gowridurgad, apologies for the delayed reply I have been away. I'm not completely sure I follow the expected behaviour point or the point about matching the python version in pyproject.toml. Your example above is doing w.r.t the setup-python interpreter not matching the toml spec that is not the issue I was reporting. Our toml specifies |
Hi @sdb9696, we haven't use the command poetry env use "${{ steps.setup-python.outputs.python-path }}" in workflow file. Poetry seems to be automatically using the Python version set by setup-python, regardless of whether the command is used. However, The Poetry fails to use the setup-python Python version only when there's a mismatch between this version and the one specified in the pyproject.toml file. In such cases, using the poetry env use "${{steps.setup-python.outputs.python-path }}" actually causes the build to fail. here's the screenshots for your reference. ![]() screenshot2: without poetry env use "${{ steps.setup-python.outputs.python-path }}" ![]() screenshot3: poetry env use "${{ steps.setup-python.outputs.python-path }}" causes the build to fail if python version didn't ![]() |
I ran into the same issue. The existing workflow stopped working recently, without any changes to it. I fixed it by changing how poetry is installed. steps:
- uses: actions/checkout@v4
- name: Install poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- uses: actions/setup-python@v5
with:
python-version: "3.12.3"
cache: "poetry"
- name: Install dependencies
run: poetry install |
Hi @andreipetre, Could you please attach link to the build or public repository to reproduce the issue ? |
@gowridurgad maybe you're missing the issue because you're fixing the python version in your pyproject.toml. Have you tried this with a loose python specifier of |
Hi @sdb9696, We tried using a loose Python specifier of >=3.8 and Poetry is using the version installed by setup_python. Here is a screenshot for reference. can you please share your updated workflow link to check and assist further if anything missed as we are not seeing the issue from our end.
![]() |
Hi @gowridurgad, I don't have a workflow link to point you to as I ended up using actions/cache directly in the end. Can you point me to the PR/branch you've used to generate the output above and I'll see what the difference is? |
Hi @sdb9696, Here is the link to the repository |
Hi @sdb9696, Just a gentle reminder regarding this issue, If you have any updates, Please let us know. |
1 similar comment
Hi @sdb9696, Just a gentle reminder regarding this issue, If you have any updates, Please let us know. |
Hi, apologies for the delay. I tried to recreate the issue and couldn’t anymore. It’s possible something has fixed it so I’d say good to close with the doc updates. Many thanks for your time with this. |
Hello @sdb9696 , The PR has been merged and the documentation has been updated. For reference, you may visit https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages. I am proceeding with closing the issue. Please feel free to contact us in case of any further concerns. |
Edit: never mind, I realised I had missed out the |
Description:
The recommendations for caching poetry dependencies causes the wrong python version to be used for
poetry install
.Because pipx install poetry happens before
setup-python
and By default, Poetry will try to use the Python version used during Poetry’s installation to create the virtual environment for the current project.Maybe the solution here is to update the docs to make sure that users know to run
poetry env use ${{ steps.setup-python.outputs.python-path }}python
prior to runningpoetry install
. I have not tested that works however.Action version:
v5
Platform:
Runner type:
Tools version:
All versions of python affected except the default version installed on the github runner.
Repro steps:
Follow the steps outlined in advance-usage.md for caching poetry dependencies.
Run
poetry install
Expected behavior:
poetry install
should use the version of python set bysetup-python
Actual behavior:
poetry install
uses the default version of python from the runner os.The text was updated successfully, but these errors were encountered: