Skip to content
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

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

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading