Expose Python runtime identity for downstream caching

This commit is contained in:
William Woodruff
2026-09-03 15:18:29 -04:00
parent 3956519c9e
commit 70e5842acc
11 changed files with 400 additions and 204 deletions
+28 -11
View File
@@ -17,18 +17,35 @@ This allows directly using it in later steps:
By default, the venv is created at `.venv` inside the `working-directory`.
With `activate-environment: true`, the `python-version-resolved` output contains the
venv's full Python version, as reported by `platform.python_version()`. For example,
a `python-version` input of `3.15t` can resolve to `3.15.0rc1`. Use
`${{ steps.setup-uv.outputs.python-version-resolved }}` in later steps to access
the resolved version (with `id: setup-uv` on the setup step).
With `activate-environment: true`, the `python-runtime-id` output identifies the
venv's Python runtime using its implementation, full Python version (including
prerelease numbers), and whether the interpreter was built for free threading.
For implementations other than CPython, it also includes the implementation's own
version, so upgrading PyPy changes the identifier even if its Python version stays
the same.
This is the Python language version: it includes prerelease suffixes, but no
implementation name or free-threaded marker. For cache keys that distinguish PyPy
from CPython or free-threaded builds, include the requested version as well.
The output is empty when `activate-environment` is false or the version cannot be
determined. The existing `python-version` output and setup-uv's cache keys are
unaffected.
Example identifiers:
| Runtime | `python-runtime-id` |
| --- | --- |
| CPython RC1 | `cpython-3.15.0rc1` |
| Free-threaded CPython RC1 | `cpython-3.15.0rc1-freethreaded` |
| Free-threaded CPython RC2 | `cpython-3.15.0rc2-freethreaded` |
| PyPy | `pypy-7.3.23-python-3.11.15` |
This is an opaque identifier in a setup-uv-defined format, not a Python version
specifier. Use the whole value as a cache-key component rather than parsing it.
Combine it with the platform and dependency information relevant to your cache,
for example (with `id: setup-uv` on the setup step):
```yaml
key: build-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-uv.outputs.python-runtime-id }}-${{ hashFiles('uv.lock') }}
```
The free-threaded marker describes the interpreter's build even when the GIL is
enabled at runtime. The output is empty when `activate-environment` is false or the
runtime cannot be determined. The existing `python-version` output and setup-uv's
cache keys are unaffected.
You can customize the venv location with `venv-path`, for example to place it in the runner temp directory: