-
-
Notifications
You must be signed in to change notification settings - Fork 723
fix(uv): Reuse the uv cache in runnable lock targets
#4180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ab4682
Allow `uv` lock runners to reuse the cache
hartikainen 85ed683
fix(uv): Place cache note before arguments
hartikainen 0523fa8
chore(uv): Format news fragment and wrap long lines in cache_tests
rickeylev 18cbc4b
chore(tests): Separate verification blocks in test_run_reuses_cache_o…
rickeylev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| (uv) The {obj}`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. | ||
| ([#4179](https://github.com/bazel-contrib/rules_python/issues/4179)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Cache policy tests for build actions and runnable lock targets.""" | ||
|
|
||
| load("@rules_testing//lib:analysis_test.bzl", "analysis_test") | ||
| load("@rules_testing//lib:test_suite.bzl", "test_suite") | ||
| load("//python/uv:lock.bzl", "lock") | ||
| load("//tests/support/platforms:platforms.bzl", "platform_targets") | ||
|
|
||
| def _cache_tests(name, is_windows, extension): | ||
| if is_windows: | ||
| platform = platform_targets.WINDOWS_X86_64 | ||
| else: | ||
| platform = platform_targets.LINUX_X86_64 | ||
| config_settings = { | ||
| "//command_line_option:platforms": [platform], | ||
| } | ||
| for no_cache in [False, True]: | ||
| subject = name + ("_no_cache" if no_cache else "_default") | ||
| lock( | ||
| name = subject, | ||
| srcs = ["testdata/pyproject.toml"], | ||
| args = ["--no-cache"] if no_cache else [], | ||
| out = subject + extension, | ||
| ) | ||
| analysis_test( | ||
| name = subject + "_build_test", | ||
| impl = _test_windows_build_impl if is_windows else _test_build_impl, | ||
| target = subject, | ||
| config_settings = config_settings, | ||
| ) | ||
| analysis_test( | ||
| name = subject + "_run_test", | ||
| impl = _test_no_cache_run_impl if no_cache else _test_run_impl, | ||
| target = subject + ".run", | ||
| config_settings = config_settings, | ||
| ) | ||
| native.test_suite( | ||
| name = name, | ||
| tests = [ | ||
| name + mode + kind | ||
| for mode in ["_default", "_no_cache"] | ||
| for kind in ["_build_test", "_run_test"] | ||
| ], | ||
| ) | ||
|
|
||
| def _test_build_impl(env, target): | ||
| output = target[DefaultInfo].files.to_list()[0] | ||
| env.expect.that_target(target).action_generating( | ||
| output.short_path, | ||
| ).argv().contains("--no-cache") | ||
|
|
||
| def _test_windows_build_impl(env, target): | ||
| env.expect.that_target(target).action_generating( | ||
| "{package}/{name}_lock.bat", | ||
| ).content().contains("--no-cache") | ||
|
|
||
| def _run_script(env, target): | ||
| executable = target[DefaultInfo].files_to_run.executable | ||
| return env.expect.that_target(target).action_generating( | ||
| executable.short_path, | ||
| ).content() | ||
|
|
||
| def _test_run_impl(env, target): | ||
| _run_script(env, target).split("--no-cache").has_size(1) | ||
|
|
||
| def _test_no_cache_run_impl(env, target): | ||
| _run_script(env, target).contains("--no-cache") | ||
|
|
||
| def _test_requirements_cache(name): | ||
| _cache_tests(name, is_windows = False, extension = ".txt") | ||
|
|
||
| def _test_uv_lock_cache(name): | ||
| _cache_tests(name, is_windows = False, extension = ".lock") | ||
|
|
||
| def _test_windows_requirements_cache(name): | ||
| _cache_tests(name, is_windows = True, extension = ".txt") | ||
|
|
||
| def _test_windows_uv_lock_cache(name): | ||
| _cache_tests(name, is_windows = True, extension = ".lock") | ||
|
|
||
| def cache_test_suite(name): | ||
| """Check cache defaults and explicit `--no-cache` for both lock formats.""" | ||
| test_suite( | ||
| name = name, | ||
| tests = [ | ||
| _test_requirements_cache, | ||
| _test_uv_lock_cache, | ||
| _test_windows_requirements_cache, | ||
| _test_windows_uv_lock_cache, | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.