From d3239a76b7135078f5f68ad55ef78599957e9c11 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 28 Jul 2025 12:10:06 -0500 Subject: [PATCH] Enable the Python download cache in CI --- .github/workflows/ci.yml | 37 ++++++++++++++++++++++++++++ crates/uv/tests/it/python_install.rs | 21 ++++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23efa58d2..73d578b58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,7 +214,18 @@ jobs: run: rustup show - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + + - name: "Cache Python downloads" + uses: actions/cache@v4 + with: + path: /tmp/uv/python + key: uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + restore-keys: | + uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + uv-${{ runner.os }} - name: "Install required Python versions" + env: + UV_PYTHON_CACHE_DIR: /tmp/uv/python run: uv python install - name: "Install cargo nextest" @@ -226,6 +237,7 @@ jobs: env: # Retry more than default to reduce flakes in CI UV_HTTP_RETRIES: 5 + UV_PYTHON_CACHE_DIR: /tmp/uv/python run: | cargo nextest run \ --features python-patch \ @@ -250,7 +262,18 @@ jobs: run: rustup show - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + + - name: "Cache Python downloads" + uses: actions/cache@v4 + with: + path: /tmp/uv/python + key: uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + restore-keys: | + uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + uv-${{ runner.os }} - name: "Install required Python versions" + env: + UV_PYTHON_CACHE_DIR: /tmp/uv/python run: uv python install - name: "Install cargo nextest" @@ -262,6 +285,7 @@ jobs: env: # Retry more than default to reduce flakes in CI UV_HTTP_RETRIES: 5 + UV_PYTHON_CACHE_DIR: /tmp/uv/python run: | cargo nextest run \ --no-default-features \ @@ -287,7 +311,19 @@ jobs: Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.UV_WORKSPACE }}" -Recurse - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + + - name: "Cache Python downloads" + uses: actions/cache@v4 + with: + path: ${{ env.UV_WORKSPACE }}/python + key: uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + restore-keys: | + uv-${{ runner.os }}-${{ hashFiles('.python-versions') }} + uv-${{ runner.os }} + - name: "Install required Python versions" + env: + UV_PYTHON_CACHE_DIR: ${{ env.UV_WORKSPACE }}/python run: uv python install - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 @@ -311,6 +347,7 @@ jobs: # Avoid permission errors during concurrent tests # See https://github.com/astral-sh/uv/issues/6940 UV_LINK_MODE: copy + UV_PYTHON_CACHE_DIR: ${{ env.UV_WORKSPACE }}/python shell: bash run: | cargo nextest run \ diff --git a/crates/uv/tests/it/python_install.rs b/crates/uv/tests/it/python_install.rs index 868aaa157..8ae99182d 100644 --- a/crates/uv/tests/it/python_install.rs +++ b/crates/uv/tests/it/python_install.rs @@ -2261,7 +2261,8 @@ fn python_install_no_cache() { .with_managed_python_dirs(); // Install the latest version - uv_snapshot!(context.filters(), context.python_install(), @r" + uv_snapshot!(context.filters(), context.python_install() + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r" success: true exit_code: 0 ----- stdout ----- @@ -2279,7 +2280,8 @@ fn python_install_no_cache() { bin_python.assert(predicate::path::exists()); // Should be a no-op when already installed - uv_snapshot!(context.filters(), context.python_install(), @r###" + uv_snapshot!(context.filters(), context.python_install() + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r###" success: true exit_code: 0 ----- stdout ----- @@ -2289,7 +2291,8 @@ fn python_install_no_cache() { "###); // Similarly, when a requested version is already installed - uv_snapshot!(context.filters(), context.python_install().arg("3.13"), @r###" + uv_snapshot!(context.filters(), context.python_install().arg("3.13") + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r###" success: true exit_code: 0 ----- stdout ----- @@ -2298,7 +2301,8 @@ fn python_install_no_cache() { "###); // You can opt-in to a reinstall - uv_snapshot!(context.filters(), context.python_install().arg("3.13").arg("--reinstall"), @r" + uv_snapshot!(context.filters(), context.python_install().arg("3.13").arg("--reinstall") + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r" success: true exit_code: 0 ----- stdout ----- @@ -2309,7 +2313,8 @@ fn python_install_no_cache() { "); // Uninstallation requires an argument - uv_snapshot!(context.filters(), context.python_uninstall(), @r###" + uv_snapshot!(context.filters(), context.python_uninstall() + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r###" success: false exit_code: 2 ----- stdout ----- @@ -2323,7 +2328,8 @@ fn python_install_no_cache() { For more information, try '--help'. "###); - uv_snapshot!(context.filters(), context.python_uninstall().arg("3.13"), @r" + uv_snapshot!(context.filters(), context.python_uninstall().arg("3.13") + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r" success: true exit_code: 0 ----- stdout ----- @@ -2343,7 +2349,8 @@ fn python_install_no_cache() { uv_snapshot!(filters, context .python_install() .arg("3.12") - .arg("--offline"), @r" + .arg("--offline") + .env_remove(EnvVars::UV_PYTHON_CACHE_DIR), @r" success: false exit_code: 1 ----- stdout -----