Skip to content

Check that intended python version is being used #808

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

Closed
wants to merge 8 commits into from

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Mar 31, 2025

This PR changes GitHub actions CI jobs as follows:

One reason I made this PR was to double-check that we were indeed running tests against the intended python versions, despite not specifying the version in uv sync. I've confirmed that we were (see #809). Presumably because uv uses the python interpreter installed by the setup-python action. Nevertheless, it seems good to be explicit in the uv commands, especially since, as described above, I think we will eventually move away from setup-python.

@dandavison dandavison force-pushed the fix-python-version-in-ci branch 2 times, most recently from 940c592 to c088cc2 Compare March 31, 2025 15:07
@dandavison dandavison force-pushed the fix-python-version-in-ci branch from 87a747c to 3dc6d6d Compare April 1, 2025 12:04
@dandavison dandavison marked this pull request as ready for review April 1, 2025 12:12
@dandavison dandavison requested a review from a team as a code owner April 1, 2025 12:12
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this PR has much value if it's just for "double checking" any more than we need to double check everything else GH actions install/use. I do think https://github.com/actions/setup-python will remain a reasonable/official way to install Python in GH actions even though uv (and apt and others) also offer a way.

Comment on lines +52 to +64
- name: Check python version
shell: bash
run: |
actual=$(uv run python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")
if [[ "$actual" != "${{ matrix.python }}" ]]; then
echo "Python version in use by uv ($actual) does not match intended version (${{ matrix.python }})"
exit 1
fi
actual=$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")
if [[ "$actual" != "${{ matrix.python }}" ]]; then
echo "Python version on PATH ($actual) does not match intended version (${{ matrix.python }})"
exit 1
fi
Copy link
Member

@cretz cretz Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this embedded GH workflow logic/check necessary? Can we not trust setup-python? Do we need to check Rust version, protoc version, CPU arch, etc too if we're concerned with the actions? I can't tell from the PR description whether something happened that made this not work and made us concerned.

@@ -48,7 +48,20 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: astral-sh/setup-uv@v5
- run: uv tool install poethepoet
- run: uv sync --all-extras
- run: uv sync --all-extras --python ${{ matrix.python }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for --python instead of letting it use the existing installed one? (even if we change the install method)

@dandavison
Copy link
Contributor Author

Yes, it appears that this PR is not strictly necessary at this point in time. But, uv is a tool to manage python projects, including managing the python interpreter used. And we are running all our tests under uv (as uv run pytest). I made the PR because I was worried that we hadn't checked that uv was actually respecting the environment changes made by setup-python).

I'm still learning uv. Is it your understanding that uv upholds the following guarantee:

If --python is not provided, then uv will create a virtualenv using the python interpreter that has precedence on PATH at the time of first issuing uv sync?

I need to read the discussion at https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching and discussion in actions/setup-python#822 again to see whether the idea is that setup-python will be the long-term action for use with uv.

But note that we are testing across multiple platforms -- Windows in particular differs a lot, and I've noticed that uv --preview python install on Windows doesn't actually result in the requested version having precendence on PATH. That sort of thing was making me think that it would be good to be careful.

@cretz
Copy link
Member

cretz commented Apr 1, 2025

Is it your understanding that uv upholds the following guarantee:

Yes, this is my understanding. I am just wary of embedding bash into our workflows to check for tool versions after we install them unless it's shown to be needed. Obviously it's not a big deal, just a bit abnormal compared to what we do elsewhere when installing language runtime. It does make sense that non-setup-python Python install approaches may not configure it for default use on GH runners.

@dandavison
Copy link
Contributor Author

Let's close this one. I mainly wanted to check that we were currently correct, and we are.

I've extracted out the README change to #811

@dandavison dandavison closed this Apr 1, 2025
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

Successfully merging this pull request may close these issues.

2 participants