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

Skipping rye pin considered harmful :) #313

Closed
yacoob opened this issue Aug 1, 2024 · 5 comments
Closed

Skipping rye pin considered harmful :) #313

yacoob opened this issue Aug 1, 2024 · 5 comments

Comments

@yacoob
Copy link

yacoob commented Aug 1, 2024

I was experimenting today with this action, and found a subtle discrepancy. Take a look at this minimal repository: https://github.com/yacoob/rye-pin-caching

The workflow in that repo skips rye pin and rye sync, if setup-rye was able to recover the venv from cache. rye-pin-caching doesn't have a .python-version file checked in, and the workflow runs python --version for 3 different Python versions: 3.10, 3.11, 3.12 via a matrix strategy. The first run behaves as expected:

https://github.com/yacoob/rye-pin-caching/actions/runs/10190413244/job/28190062641

On a second run, the following happens:

  • setup-rye manages to recover the venv from cache
  • both rye pin and rye sync are skipped, as configured
  • the log for subsequent rye run python --version looks like this:
Run rye run python --version
  rye run python --version
  shell: /usr/bin/bash -e {0}
  env:
    RYE_HOME: /opt/hostedtoolcache/setup-rye-2024-03-04/0.37.0/x86_64
Python version mismatch (found [email protected], expected [email protected]), recreating.
Downloading [email protected]
...

Full logs here: https://github.com/yacoob/rye-pin-caching/actions/runs/10190430876

The restored venv is correctly configured with py3.10. Rye doesn't know what version it should expect, and it defaults to the minimum requested by pyproject.toml - which in my case is 3.8.

Removing the if: ... line from rye pin that hinges the execution on whether there was a cache hit solves this problem completely.


This is not a bug per-se, more of an unexpected consequence of the suggested configuration linked from the doc. Has this ever worked for you, with multiple Python versions configured via matrix? Was rye run behaviour different before? This discrepancy ate some of time, so I wanted to compare notes, so to speak :) The example linked from the README uses a single version in strategy.matrix, plus it has a .python-version file present, so the problem doesn't appear there.

@eifinger
Copy link
Owner

eifinger commented Aug 1, 2024

Can you please add an explanation why you do not include the .python-version?

@yacoob
Copy link
Author

yacoob commented Aug 1, 2024

My original project where I've noticed this problem originally is a library that needs Python 3.10 at minimum. What would I set the .python-version to? I honestly don't know what should be the value in that case - when I develop I routinely switch between 3.10 and 3.11 (via rye pin && rye sync, to test different things). The example repo I've linked above runs tests with py3.{10,11,12} but lists the minimum required python version in pyproject.toml as 3.8, which is bit of a mixup, sorry.

Also, .python-version file itself is not cached, right? If it isn't, the problem would still persist, if I understand things correctly - except rye wouldn't be falling back to the minimum version of 3.8, but rather to the version from .python-version, which would still be different from the one the venv was initially created with, right? That is, this behaviour:

Python version mismatch (found [email protected], expected [email protected]), recreating.

would still be there, just with a different version in place of 3.8.19?

@eifinger
Copy link
Owner

eifinger commented Aug 1, 2024

You are completely right. The example is wrong and rye pin should never be skipped in a matrix workflow with different python versions. I fixed it in another repo but not in the one I am using as an example in the documentation here 🤦

@eifinger
Copy link
Owner

eifinger commented Aug 2, 2024

The example is updated. I now use https://rye.astral.sh/guide/pyproject/#toolryeuniversal to create lock files for all python versions.

@eifinger eifinger closed this as completed Aug 2, 2024
@eifinger
Copy link
Owner

@yacoob since the latest release of uv it has feature parity for my previous use of rye. I am switching all my projects to it. Since it creates a universal lock file by default this problem does not exist with it.

If you want to try it out I just created https://github.com/eifinger/setup-uv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants