Skip to content

Commit

Permalink
Junction
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 24, 2024
1 parent f633a90 commit 50ba902
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Cache {
}

/// Run the garbage collector on the cache, removing any dangling entries.
pub fn prune(&self, all_unzipped: bool) -> Result<Removal, io::Error> {
pub fn prune(&self, ci: bool) -> Result<Removal, io::Error> {
let mut summary = Removal::default();

// First, remove any top-level directories that are unused. These typically represent
Expand Down Expand Up @@ -387,7 +387,7 @@ impl Cache {
}

// Third, if enabled, remove all unzipped wheels, leaving only the wheel archives.
if all_unzipped {
if ci {
// Remove the entire pre-built wheel cache, since every entry is an unzipped wheel.
match fs::read_dir(self.bucket(CacheBucket::Wheels)) {
Ok(entries) => {
Expand Down
9 changes: 7 additions & 2 deletions crates/uv-cache/src/removal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ impl Removal {

// Remove the file.
self.total_bytes += metadata.len();
remove_file(path)?;
if cfg!(windows) && metadata.is_symlink() {
// Remove the junction.
remove_dir(path)?;
} else {
remove_file(path)?;
}

return Ok(());
}
Expand All @@ -64,7 +69,7 @@ impl Removal {

let entry = entry?;
if cfg!(windows) && entry.file_type().is_symlink() {
// In this branch, we try to handle junction removal.
// Remove the junction.
self.num_files += 1;
remove_dir(entry.path())?;
} else if entry.file_type().is_dir() {
Expand Down
22 changes: 14 additions & 8 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,21 @@ pub struct CleanArgs {
#[derive(Args, Debug)]
#[allow(clippy::struct_excessive_bools)]
pub struct PruneArgs {
/// Whether to remove unzipped wheels from the cache, leaving only zipped wheel entries.
///
/// By default, uv stores unzipped wheels in the cache, which enables high-performance package
/// installation. In some scenarios, though, persisting unzipped wheels may be undesirable. For
/// example, in GitHub Actions or other CI environments, uploading unzipped wheels to a remote
/// cache may have a negative impact on cache performance. Pruning unzipped wheels will leave
/// the cache with any built wheels in their zipped form.
/// Optimize the cache for persistence in a continuous integration environment, like GitHub
/// Actions.
///
/// By default, uv caches both the wheels that it builds from source and the pre-built wheels
/// that it downloads directly, to enable high-performance package installation. In some
/// scenarios, though, persisting pre-built wheels may be undesirable. For example, in GitHub
/// Actions, it's faster to omit pre-built wheels from the cache and instead have re-download
/// them on each run. However, it typically _is_ faster to cache wheels that are built from
/// source, since the wheel building process can be expensive, especially for extension
/// modules.
///
/// In `--ci` mode, uv will prune any pre-built wheels from the cache, but retain any wheels
/// that were built from source.
#[arg(long)]
pub all_unzipped: bool,
pub ci: bool,
}

#[derive(Args)]
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/cache_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::printer::Printer;

/// Prune all unreachable objects from the cache.
pub(crate) fn cache_prune(
all_unzipped: bool,
ci: bool,
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
Expand All @@ -31,7 +31,7 @@ pub(crate) fn cache_prune(
)?;

let summary = cache
.prune(all_unzipped)
.prune(ci)
.with_context(|| format!("Failed to prune cache at: {}", cache.root().user_display()))?;

// Write a summary of the number of files and directories removed.
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
command: CacheCommand::Prune(args),
}) => {
show_settings!(args);
commands::cache_prune(args.all_unzipped, &cache, printer)
commands::cache_prune(args.ci, &cache, printer)
}
Commands::Cache(CacheNamespace {
command: CacheCommand::Dir,
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/cache_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn prune_stale_symlink() -> Result<()> {
Ok(())
}

/// `cache prune --all-unzips` should remove all unzipped archives.
/// `cache prune --ci` should remove all unzipped archives.
#[test]
fn prune_unzipped() -> Result<()> {
let context = TestContext::new("3.12");
Expand All @@ -195,7 +195,7 @@ fn prune_unzipped() -> Result<()> {
+ source-distribution==0.0.1
"###);

uv_snapshot!(context.filters(), context.prune().arg("--all-unzipped"), @r###"
uv_snapshot!(context.filters(), context.prune().arg("--ci"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down

0 comments on commit 50ba902

Please sign in to comment.