-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uv cache prune
removes all cached environments (#4845)
## Summary Resolves #4802 ## Test Plan - `cargo test` ```sh ❯ cargo run -- cache prune -v Pruning cache at: /Users/ahmedilyas/Library/Caches/uv No unused entries found ❯ cargo run -- tool run cowsay warning: `uv tool run` is experimental and may change without warning. Resolved 1 package in 182ms Installed 1 package in 20ms + cowsay==6.1 usage: Cowsay [-h] [-c CHARACTER] -t TEXT [-v] Cowsay: error: the following arguments are required: -t/--text ❯ cargo run -- cache prune -v Pruning cache at: /Users/ahmedilyas/Library/Caches/uv 0.793440s DEBUG uv_cache Removing dangling cache entry: /Users/ahmedilyas/Library/Caches/uv/environments-v1/095cd7c4c298a0d8 Removed 41 files (143.5KiB) ```
- Loading branch information
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -83,6 +83,59 @@ fn prune_stale_directory() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
/// `cache prune` should remove all cached environments from the cache. | ||
#[test] | ||
fn prune_cached_env() { | ||
let context = TestContext::new("3.12").with_filtered_counts(); | ||
let tool_dir = context.temp_dir.child("tools"); | ||
let bin_dir = context.temp_dir.child("bin"); | ||
|
||
uv_snapshot!(context.filters(), context.tool_run() | ||
.arg("[email protected]") | ||
.arg("--version") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
pytest 8.0.0 | ||
----- stderr ----- | ||
warning: `uv tool run` is experimental and may change without warning. | ||
Resolved [N] packages in [TIME] | ||
Prepared [N] packages in [TIME] | ||
Installed [N] packages in [TIME] | ||
+ iniconfig==2.0.0 | ||
+ packaging==24.0 | ||
+ pluggy==1.4.0 | ||
+ pytest==8.0.0 | ||
"###); | ||
|
||
let filters: Vec<_> = context | ||
.filters() | ||
.into_iter() | ||
.chain([ | ||
// The cache entry does not have a stable key, so we filter it out | ||
( | ||
r"\[CACHE_DIR\](\\|\/)(.+)(\\|\/).*", | ||
"[CACHE_DIR]/$2/[ENTRY]", | ||
), | ||
]) | ||
.collect(); | ||
|
||
uv_snapshot!(filters, prune_command(&context).arg("--verbose"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
----- stderr ----- | ||
DEBUG uv [VERSION] ([COMMIT] DATE) | ||
Pruning cache at: [CACHE_DIR]/ | ||
DEBUG Removing dangling cache entry: [CACHE_DIR]/environments-v1/[ENTRY] | ||
Removed [N] files ([SIZE]) | ||
"###); | ||
} | ||
|
||
/// `cache prune` should remove any stale symlink from the cache. | ||
#[test] | ||
fn prune_stale_symlink() -> Result<()> { | ||
|
This file contains 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