-
Notifications
You must be signed in to change notification settings - Fork 2.2k
tests: cache managed Python installs #16723
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
base: main
Are you sure you want to change the base?
tests: cache managed Python installs #16723
Conversation
- flip `with_managed_python_dirs()` to set `UV_PYTHON_CACHE_DIR` - add `without_python_download_cache()` for the cold-cache scenarios - keep the offline test pointed at a fresh temp cache so it still fails the right way
crates/uv/tests/it/python_install.rs
Outdated
| .arg("3.12") | ||
| .arg("--offline"), @r" | ||
| .arg("--offline") | ||
| .env(EnvVars::UV_PYTHON_CACHE_DIR, offline_cache.as_os_str()), @r" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using the cache dir in the offline test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_managed_python_dirs() now calls with_python_download_cache(), so without an override the offline test inherits the warm cache and starts passing when earlier tests download that version. Pointing it at a dedicated temp cache keeps the test deterministic, the offline install still fails because the cache is empty, which is what the test asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as above,once the helper enables the shared cache by default we need an explicit optout. The new without_python_download_cache() clears the shared value and replaces it with an empty per test cache so no cache scenaris keep utilizing the intended code path.
|
How fast are the tests before and after, does the cache work? |
I ran |
crates/uv/tests/it/common/mod.rs
Outdated
|
|
||
| /// Use a shared global cache for Python downloads. | ||
| #[must_use] | ||
| pub fn with_python_download_cache(mut self) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd expect this to no longer be pub and all the redundant calls to be dropped
crates/uv/tests/it/common/mod.rs
Outdated
| self.extra_env.retain(|(existing, _)| existing != &key); | ||
| let empty_cache = self.temp_dir.child("python-cache-empty"); | ||
| self.extra_env | ||
| .push((key, empty_cache.as_os_str().to_owned())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can be an empty directory, we need to exercise the code path where the variable is unset
|
Thanks for the feedback, @zanieb! I want to make sure I understand correctly before pushing the changes I've made with_python_download_cache() non-public and removed all explicit calls from test files (python_install.rs, python_find.rs, python_upgrade.rs, and pip_install.rs). Since with_managed_python_dirs() now calls it internally, tests using .with_managed_python_dirs() will automatically get the cache enabled. Is this the intended behavior you were looking for? You mentioned we need to exercise the code path where the variable is unset. I've changed it to: This removes the variable from extra_env entirely, rather than setting it to an empty directory. Is this what you meant by unsetting the variable, or did you mean something else? (I want to confirm this correctly tests the "cache disabled" scenario vs just testing "empty cache directory".) |
Make `with_python_download_cache()` private and remove redundant explicit calls across test files. Fixes astral-sh#16721
1764935 to
02018f8
Compare
|
@konstin @zanieb I’ve pushed the changes so it’s easier for you to review what has actually changed, instead of going in circles. If this isn’t the expected outcome, it’s possible I misunderstood the intent behind the original change request. If that’s the case, I’m happy to hand this over to someone with a better understanding of the test and cache logic. |
Cache managed Python downloads (#16721)