Implement `uv cache dir` (#1734)

## Summary

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

Closes https://github.com/astral-sh/uv/issues/1646.
This commit is contained in:
Charlie Marsh 2024-02-19 23:29:10 -05:00 committed by GitHub
parent bb876d95ed
commit 692c00defe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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
@ -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)]
@ -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 {
@ -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()?;