Skip to content

fix(uv): Reuse the uv cache in runnable lock targets - #4180

Open
hartikainen wants to merge 1 commit into
bazel-contrib:mainfrom
hartikainen:uv-lock-cache
Open

hartikainen wants to merge 1 commit into
bazel-contrib:mainfrom
hartikainen:uv-lock-cache

Conversation

@hartikainen

Copy link
Copy Markdown
Contributor

This PR lets .run targets reuse the caller's uv cache by moving --no-cache from the shared arguments to the build-action arguments. Repeated runs can reuse registry metadata, Git checkouts, and build metadata. Build actions retain cache isolation, and callers can still pass --no-cache.

The lock tests use a sandbox-writable UV_CACHE_DIR and verify that .run creates it.

Closes #4179.

Copilot AI lite review requested due to automatic review settings September 23, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Correct the integration test lock-file path and update the news entry’s required references.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates lock() runnable targets to reuse the caller’s uv cache while preserving cache isolation for build actions.

Changes:

  • Moves --no-cache to build-action arguments.
  • Adds cache analysis and integration tests.
  • Documents the new runnable cache behavior.
File Summary
tests/​uv/​lock/​lock_run_test.py Updates runnable-script expectations and cache setup.
tests/​uv/​lock/​cache_tests.bzl Adds cache-policy analysis tests.
tests/​uv/​lock/​BUILD.bazel Registers cache tests.
tests/​integration/​uv_lock/​BUILD.bazel Adds the integration lock target.
tests/​integration/​uv_lock_test.py Tests cache reuse and bypass behavior; the lock-file path needs correction.
python/​uv/​private/​lock.bzl Separates build-only and runnable cache flags.
news/​uv-lock-run-cache.fixed.md Documents the change; needs required formatting and issue cross-reference updates.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread news/4179.fixed.md
The `lock()` macro's `.run` target uses the `uv` cache and honors
`UV_CACHE_DIR` and `UV_NO_CACHE`. Pass `--refresh` to refresh cached data or
`--no-cache` to disable caching. Lock build actions, including those used by
`.update`, disable the `uv` cache.
Keep `--no-cache` on Bazel build actions while allowing `.run` targets
to reuse the persistent `uv` cache. Document the cache controls and test
both lock formats, cache opt-outs, and POSIX and Windows script generation.

The integration regression resolves against a local authenticated package
index, deletes the output, and regenerates the lockfile offline. It fails
for both formats when `.run` receives `--no-cache` by default.

Related to [bazel-contrib#4164](bazel-contrib#4164).
This applies the same separation between build-action flags and `.run`
defaults to caching. Output verbosity remains unchanged.

This branch has not been deployed

No deployments
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.

Allow runnable lock targets to reuse the uv cache

2 participants