clarify best practice for python matrix strategy github workflow (#9454)

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Existing documentation on how to apply a matrix strategy over the python
version in a github workflow is incomplete and possibly misleading. This
PR deletes the existing section and creates a new one to reflect current
best practice. See https://github.com/astral-sh/uv/issues/9376.

## Test Plan

N/A, only docs.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
Zach Kurtz 2024-12-16 14:38:06 -05:00 committed by GitHub
parent 2fb340b19d
commit a8772c6944
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,37 +67,6 @@ jobs:
This will respect the Python version pinned in the project.
Or, when using a matrix, as in:
```yaml title="example.yml"
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
```
Provide the version to the `python install` invocation:
```yaml title="example.yml" hl_lines="14 15"
name: Example
jobs:
uv-example:
name: python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
```
Alternatively, the official GitHub `setup-python` action can be used. This can be faster, because
GitHub caches the Python versions alongside the runner.
@ -148,6 +117,52 @@ jobs:
python-version-file: "pyproject.toml"
```
## Multiple Python versions
When using a matrix test test multiple Python versions, set the Python version using
`astral-sh/setup-uv`, which will override the Python version specification in the `pyproject.toml`
or `.python-version` files:
```yaml title="example.yml" hl_lines="17 18"
jobs:
build:
name: continuous-integration
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@v4
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
```
If not using the `setup-uv` action, you can set the `UV_PYTHON` environment variable:
```yaml title="example.yml" hl_lines="12"
jobs:
build:
name: continuous-integration
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
```
## Syncing and running
Once uv and Python are installed, the project can be installed with `uv sync` and commands can be