mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-05 01:35:32 +00:00
Repair cached Python directory junctions on Windows (#1122)
With `cache-python: true`, a Windows runner can report a cache hit while extracting the cache incorrectly. When `@actions/cache`'s tar extracts uv's minor-version junction before the patch directory it points to, it creates a file symlink. Resolving that link later raises `[WinError 5] Access is denied`. This PR fixes things up after restoring the Python cache, recreating the junction if resolving the link fails with access denied and its recorded target is a matching, accessible CPython installation in the same directory. This is a temporary workaround until https://github.com/actions/toolkit/issues/2562 gets resolved and `@actions/cache` itself becomes resilient to these situations. I tested this by restoring the same archive on two fresh `windows-2022` runners. The original run passed because resolving the minor-version link raised the expected WinError 5. With the patch, `uv sync --offline --managed-python --no-python-downloads` created a virtual environment whose `home` in `pyvenv.cfg` resolved to the cached CPython 3.10.22 installation. [Original run](https://github.com/astral-sh/ruff/actions/runs/41469344610/job/125358623949#step:9:1) · [Patched run](https://github.com/astral-sh/ruff/actions/runs/41469344610/job/125358623835#step:10:1).
This commit is contained in:
+27
-16
@@ -985,14 +985,18 @@ jobs:
|
||||
run: rm -rf "$UV_PYTHON_INSTALL_DIR"
|
||||
|
||||
test-cache-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-2022]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir is not populated
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ -e "$RUNNER_TEMP/uv-python-dir" ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1005,21 +1009,26 @@ jobs:
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
- name: Verify Python install dir exists
|
||||
shell: bash
|
||||
run: |
|
||||
if [ ! -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ ! -d "$UV_PYTHON_INSTALL_DIR" ]; then
|
||||
echo "Python install dir should exist"
|
||||
exit 1
|
||||
fi
|
||||
test-restore-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: test-cache-python-installs
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-2022]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir does not exist
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ -e "$RUNNER_TEMP/uv-python-dir" ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1030,19 +1039,21 @@ jobs:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-python-installs
|
||||
- name: Verify Python install dir exists
|
||||
run: |
|
||||
if [ ! -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
echo "Python install dir should exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Cache was hit
|
||||
run: |
|
||||
if [ "$CACHE_HIT" != "true" ]; then
|
||||
exit 1
|
||||
fi
|
||||
- name: Verify the restored Python minor-version link resolves to the patch directory
|
||||
shell: python
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.python-cache-hit }}
|
||||
run: |
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
assert os.environ["CACHE_HIT"] == "true", "expected a Python cache hit"
|
||||
installs = Path(os.environ["UV_PYTHON_INSTALL_DIR"]).resolve()
|
||||
assert installs.is_dir(), "Python install dir should exist"
|
||||
patch_dir, = installs.glob("cpython-*.*.*-*")
|
||||
minor_prefix = patch_dir.name.rsplit(".", 1)[0]
|
||||
alias, = installs.glob(f"{minor_prefix}-*")
|
||||
assert alias.resolve(strict=True) == patch_dir, alias
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
|
||||
|
||||
Reference in New Issue
Block a user