Skip to content

Commit

Permalink
Move uv clean to uv cache clean (#1733)
Browse files Browse the repository at this point in the history
## Summary

This opens up space to add other cache-related commands. (`uv clean`
continues to work for backwards compatibility but is hidden from the
CLI.)
  • Loading branch information
charliermarsh authored Feb 20, 2024
1 parent 254a94c commit bb876d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ If you're running into caching issues, uv includes a few escape hatches:
- To force uv to revalidate cached data for all dependencies, run `uv pip install --refresh ...`.
- To force uv to revalidate cached data for a specific dependency, run, e.g., `uv pip install --refresh-package flask ...`.
- To force uv to ignore existing installed versions, run `uv pip install --reinstall ...`.
- To clear the global cache entirely, run `uv clean`.
- To clear the global cache entirely, run `uv cache clean`.

### Resolution strategy

Expand Down
34 changes: 26 additions & 8 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,34 @@ impl From<ColorChoice> for anstream::ColorChoice {
#[allow(clippy::large_enum_variant)]
enum Commands {
/// Resolve and install Python packages.
Pip(PipArgs),
Pip(PipNamespace),
/// Create a virtual environment.
#[clap(alias = "virtualenv", alias = "v")]
Venv(VenvArgs),
/// Manage the cache.
Cache(CacheNamespace),
/// Clear the cache.
#[clap(hide = true)]
Clean(CleanArgs),
/// Generate shell completion
#[clap(alias = "--generate-shell-completion", hide = true)]
GenerateShellCompletion { shell: clap_complete_command::Shell },
}

#[derive(Args)]
struct PipArgs {
struct CacheNamespace {
#[clap(subcommand)]
command: CacheCommand,
}

#[derive(Subcommand)]
enum CacheCommand {
/// Clear the cache.
Clean(CleanArgs),
}

#[derive(Args)]
struct PipNamespace {
#[clap(subcommand)]
command: PipCommand,
}
Expand Down Expand Up @@ -804,7 +819,7 @@ async fn run() -> Result<ExitStatus> {
let cache = Cache::try_from(cli.cache_args)?;

match cli.command {
Commands::Pip(PipArgs {
Commands::Pip(PipNamespace {
command: PipCommand::Compile(args),
}) => {
args.compat_args.validate()?;
Expand Down Expand Up @@ -879,7 +894,7 @@ async fn run() -> Result<ExitStatus> {
)
.await
}
Commands::Pip(PipArgs {
Commands::Pip(PipNamespace {
command: PipCommand::Sync(args),
}) => {
args.compat_args.validate()?;
Expand Down Expand Up @@ -922,7 +937,7 @@ async fn run() -> Result<ExitStatus> {
)
.await
}
Commands::Pip(PipArgs {
Commands::Pip(PipNamespace {
command: PipCommand::Install(args),
}) => {
let cache = cache.with_refresh(Refresh::from_args(args.refresh, args.refresh_package));
Expand Down Expand Up @@ -1000,7 +1015,7 @@ async fn run() -> Result<ExitStatus> {
)
.await
}
Commands::Pip(PipArgs {
Commands::Pip(PipNamespace {
command: PipCommand::Uninstall(args),
}) => {
let sources = args
Expand All @@ -1016,10 +1031,13 @@ async fn run() -> Result<ExitStatus> {
.collect::<Vec<_>>();
commands::pip_uninstall(&sources, cache, printer).await
}
Commands::Pip(PipArgs {
Commands::Pip(PipNamespace {
command: PipCommand::Freeze(args),
}) => commands::freeze(&cache, args.strict, printer),
Commands::Clean(args) => commands::clean(&cache, &args.package, printer),
Commands::Cache(CacheNamespace {
command: CacheCommand::Clean(args),
})
| Commands::Clean(args) => commands::clean(&cache, &args.package, printer),
Commands::Venv(args) => {
args.compat_args.validate()?;

Expand Down

0 comments on commit bb876d9

Please sign in to comment.