Skip to content

Commit

Permalink
Implement uv cache dir (#1734)
Browse files Browse the repository at this point in the history
## Summary

Like `pip cache dir`, merely prints out the cache directory.

Closes #1646.
  • Loading branch information
charliermarsh authored Feb 20, 2024
1 parent bb876d9 commit 692c00d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

/// Clear the cache.
pub(crate) fn clean(
pub(crate) fn cache_clean(
cache: &Cache,
packages: &[PackageName],
mut printer: Printer,
Expand Down
8 changes: 8 additions & 0 deletions crates/uv/src/commands/cache_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use owo_colors::OwoColorize;
use uv_cache::Cache;
use uv_fs::Normalized;

/// Show the cache directory.
pub(crate) fn cache_dir(cache: &Cache) {
anstream::println!("{}", cache.root().normalized_display().cyan());
}
10 changes: 6 additions & 4 deletions crates/uv/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use std::process::ExitCode;
use std::time::Duration;

pub(crate) use clean::clean;
pub(crate) use cache_clean::cache_clean;
pub(crate) use cache_dir::cache_dir;
use distribution_types::InstalledMetadata;
pub(crate) use freeze::freeze;
pub(crate) use pip_compile::{extra_name_with_clap_error, pip_compile, Upgrade};
pub(crate) use pip_freeze::pip_freeze;
pub(crate) use pip_install::pip_install;
pub(crate) use pip_sync::pip_sync;
pub(crate) use pip_uninstall::pip_uninstall;
pub(crate) use venv::venv;

mod clean;
mod freeze;
mod cache_clean;
mod cache_dir;
mod pip_compile;
mod pip_freeze;
mod pip_install;
mod pip_sync;
mod pip_uninstall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

/// Enumerate the installed packages in the current environment.
pub(crate) fn freeze(cache: &Cache, strict: bool, mut printer: Printer) -> Result<ExitStatus> {
pub(crate) fn pip_freeze(cache: &Cache, strict: bool, mut printer: Printer) -> Result<ExitStatus> {
// Detect the current Python interpreter.
let platform = Platform::current()?;
let venv = Virtualenv::from_env(platform, cache)?;
Expand Down
37 changes: 26 additions & 11 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ enum Commands {
Venv(VenvArgs),
/// Manage the cache.
Cache(CacheNamespace),
/// Clear the cache.
/// Remove all items from the cache.
#[clap(hide = true)]
Clean(CleanArgs),
/// Generate shell completion
Expand All @@ -133,8 +133,24 @@ struct CacheNamespace {

#[derive(Subcommand)]
enum CacheCommand {
/// Clear the cache.
/// Remove all items from the cache.
Clean(CleanArgs),
/// Show the cache directory.
Dir,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
struct CleanArgs {
/// The packages to remove from the cache.
package: Vec<PackageName>,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
struct DirArgs {
/// The packages to remove from the cache.
package: Vec<PackageName>,
}

#[derive(Args)]
Expand Down Expand Up @@ -640,13 +656,6 @@ struct PipFreezeArgs {
strict: bool,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
struct CleanArgs {
/// The packages to remove from the cache.
package: Vec<PackageName>,
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
struct VenvArgs {
Expand Down Expand Up @@ -1033,11 +1042,17 @@ async fn run() -> Result<ExitStatus> {
}
Commands::Pip(PipNamespace {
command: PipCommand::Freeze(args),
}) => commands::freeze(&cache, args.strict, printer),
}) => commands::pip_freeze(&cache, args.strict, printer),
Commands::Cache(CacheNamespace {
command: CacheCommand::Clean(args),
})
| Commands::Clean(args) => commands::clean(&cache, &args.package, printer),
| Commands::Clean(args) => commands::cache_clean(&cache, &args.package, printer),
Commands::Cache(CacheNamespace {
command: CacheCommand::Dir,
}) => {
commands::cache_dir(&cache);
Ok(ExitStatus::Success)
}
Commands::Venv(args) => {
args.compat_args.validate()?;

Expand Down

0 comments on commit 692c00d

Please sign in to comment.