Skip to content

Commit

Permalink
Prune unzipped source distributions in uv cache prune --ci (#7446)
Browse files Browse the repository at this point in the history
## Summary

It's very unlikely that retaining these is beneficial, since you tend to
partition the cache by platform anyway.

Closes #7394.
  • Loading branch information
charliermarsh committed Sep 16, 2024
1 parent e31851f commit 9f7d9da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
27 changes: 23 additions & 4 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,31 @@ impl Cache {
Err(err) => return Err(err),
}

// Remove any unzipped wheels (i.e., symlinks) from the built wheels cache.
for entry in walkdir::WalkDir::new(self.bucket(CacheBucket::SourceDistributions)) {
let entry = entry?;
if entry.file_type().is_symlink() {
debug!("Removing unzipped wheel entry: {}", entry.path().display());
summary += rm_rf(entry.path())?;

// If the directory contains a `metadata.msgpack`, then it's a built wheel revision.
if !entry.file_type().is_dir() {
continue;
}

if !entry.path().join("metadata.msgpack").exists() {
continue;
}

// Remove any symlinks and directories in the revision. The symlinks represent
// unzipped wheels, and the directories represent the source distribution archives.
for entry in fs_err::read_dir(entry.path())? {
let entry = entry?;
let path = entry.path();

if path.is_dir() {
debug!("Removing unzipped built wheel entry: {}", path.display());
summary += rm_rf(path)?;
} else if path.is_symlink() {
debug!("Removing unzipped built wheel entry: {}", path.display());
summary += rm_rf(path)?;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/cache_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn prune_unzipped() -> Result<()> {
----- stderr -----
Pruning cache at: [CACHE_DIR]/
Removed 162 files ([SIZE])
Removed 170 files ([SIZE])
"###);

// Reinstalling the source distribution should not require re-downloading the source
Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ from source tends to be worthwhile, since the wheel building process can be expe
for extension modules.

To support this caching strategy, uv provides a `uv cache prune --ci` command, which removes all
pre-built wheels from the cache but retains any wheels that were built from source. We recommend
running `uv cache prune --ci` at the end of your continuous integration job to ensure maximum cache
efficiency. For an example, see the
pre-built wheels and unzipped source distributions from the cache, but retains any wheels that were
built from source. We recommend running `uv cache prune --ci` at the end of your continuous
integration job to ensure maximum cache efficiency. For an example, see the
[GitHub integration guide](../guides/integration/github.md#caching).

## Cache directory
Expand Down

0 comments on commit 9f7d9da

Please sign in to comment.