Prune unzipped source distributions in uv cache prune --ci (#7446)

## Summary

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

Closes https://github.com/astral-sh/uv/issues/7394.
This commit is contained in:
Charlie Marsh 2024-09-16 19:18:20 -04:00 committed by GitHub
parent e31851fb52
commit 9f7d9da449
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 8 deletions

View file

@ -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)?;
}
}
}
}

View file

@ -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

View file

@ -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