From 7081e8ea7582cfe4849df99131a5bac78b8f47e2 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 13:21:53 +0100 Subject: [PATCH 1/6] feat(clean): add `--build` for `clean` and `clean cache` --- crates/pixi_consts/src/consts.rs | 2 +- src/cli/clean.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/pixi_consts/src/consts.rs b/crates/pixi_consts/src/consts.rs index 7fb558bbb1..56ab8c417c 100644 --- a/crates/pixi_consts/src/consts.rs +++ b/crates/pixi_consts/src/consts.rs @@ -36,7 +36,7 @@ pub const CONDA_MENU_SCHEMA_DIR: &str = "Menu"; pub const PYPI_CACHE_DIR: &str = "uv-cache"; pub const CONDA_PYPI_MAPPING_CACHE_DIR: &str = "conda-pypi-mapping"; pub const CACHED_ENVS_DIR: &str = "cached-envs-v0"; -// TODO: CACHED_BUILD_ENVS_DIR was deprecated in favor of CACHED_BUILD_ENVS_DIR. This constant will be removed in a future release. +// TODO: CACHED_BUILD_ENVS_DIR was deprecated in favor of CACHED_BUILD_TOOL_ENVS_DIR. This constant will be removed in a future release. pub const _CACHED_BUILD_ENVS_DIR: &str = "cached-build-envs-v0"; pub const CACHED_BUILD_TOOL_ENVS_DIR: &str = "cached-build-tool-envs-v0"; pub const CACHED_GIT_DIR: &str = "git-v0"; diff --git a/src/cli/clean.rs b/src/cli/clean.rs index 15c068e8dd..23a53ec378 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -37,12 +37,16 @@ pub struct Args { command: Option, /// The environment directory to remove. - #[arg(long, short, conflicts_with = "command")] + #[arg(long, short, conflicts_with_all = ["command", "build"])] pub environment: Option, /// Only remove the activation cache #[arg(long)] pub activation_cache: bool, + + /// Only remove the pixi-build cache + #[arg(long)] + pub build: bool, } /// Clean the cache of your system which are touched by pixi. @@ -70,10 +74,14 @@ pub struct CacheArgs { #[arg(long)] pub repodata: bool, - /// Clean only the build backend tools cache. + /// Clean only the build backends envs cache. #[arg(long)] pub tool: bool, + /// Clean only the pixi-build cache + #[arg(long)] + pub build: bool, + /// Answer yes to all questions. #[clap(short = 'y', long = "yes", alias = "assume-yes")] assume_yes: bool, @@ -110,7 +118,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { if let Some(explicit_env) = explicit_environment { if args.activation_cache { - remove_file(explicit_env.activation_cache_file_path(), false).await?; + remove_file(explicit_env.activation_cache_file_path(), true).await?; tracing::info!( "Only removing activation cache for explicit environment '{}'", explicit_env.name().fancy_display() @@ -123,6 +131,11 @@ pub async fn execute(args: Args) -> miette::Result<()> { explicit_env.name().fancy_display() ); } + } else if args.activation_cache { + remove_folder_with_progress(workspace.activation_env_cache_folder(), true).await?; + } else if args.build { + remove_folder_with_progress(workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), true) + .await?; } else { // Remove all pixi related work from the workspace. if !workspace @@ -138,6 +151,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { remove_folder_with_progress(workspace.solve_group_environments_dir(), false).await?; remove_folder_with_progress(workspace.task_cache_folder(), false).await?; remove_folder_with_progress(workspace.activation_env_cache_folder(), false).await?; + remove_folder_with_progress(workspace.pixi_dir(), false).await?; } Ok(()) } @@ -168,6 +182,14 @@ async fn clean_cache(args: CacheArgs) -> miette::Result<()> { // This will be removed in a future release. dirs.push(cache_dir.join(consts::_CACHED_BUILD_ENVS_DIR)); } + if args.build { + dirs.push(cache_dir.join(consts::CACHED_GIT_DIR)); + dirs.push(cache_dir.join(consts::CACHED_BUILD_WORK_DIR)); + dirs.push(cache_dir.join(consts::CACHED_BUILD_BACKENDS)); + dirs.push(cache_dir.join(consts::CACHED_SOURCE_BUILDS)); + dirs.push(cache_dir.join(consts::CACHED_SOURCE_METADATA)); + dirs.push(cache_dir.join(consts::CACHED_PACKAGES)); + } if dirs.is_empty() && (args.assume_yes || dialoguer::Confirm::new() .with_prompt("No cache types specified using the flags.\nDo you really want to remove all cache directories from your machine?") .interact_opt() From f2607461e432b6fd90099744ce3be5fec503b4ff Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 13:23:11 +0100 Subject: [PATCH 2/6] chore(clean): rename `--tool` to `--build_backends` --- src/cli/clean.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/clean.rs b/src/cli/clean.rs index 23a53ec378..a25024d34b 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -76,7 +76,7 @@ pub struct CacheArgs { /// Clean only the build backends envs cache. #[arg(long)] - pub tool: bool, + pub build_backends: bool, /// Clean only the pixi-build cache #[arg(long)] @@ -176,7 +176,7 @@ async fn clean_cache(args: CacheArgs) -> miette::Result<()> { if args.exec { dirs.push(cache_dir.join(consts::CACHED_ENVS_DIR)); } - if args.tool { + if args.build_backends { dirs.push(cache_dir.join(consts::CACHED_BUILD_TOOL_ENVS_DIR)); // TODO: Let's clean deprecated cache directory. // This will be removed in a future release. From 9d1381d557509f6fc19bda2bfd4b28b761bcf199 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 13:28:25 +0100 Subject: [PATCH 3/6] cli docs --- docs/reference/cli/pixi/clean.md | 2 ++ docs/reference/cli/pixi/clean/cache.md | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/reference/cli/pixi/clean.md b/docs/reference/cli/pixi/clean.md index 9fbcac5664..75cc32ebf6 100644 --- a/docs/reference/cli/pixi/clean.md +++ b/docs/reference/cli/pixi/clean.md @@ -22,6 +22,8 @@ pixi clean [OPTIONS] [COMMAND] : The environment directory to remove - `--activation-cache` : Only remove the activation cache +- `--build` +: Only remove the pixi-build cache ## Global Options - `--manifest-path ` diff --git a/docs/reference/cli/pixi/clean/cache.md b/docs/reference/cli/pixi/clean/cache.md index 1e4fc437f8..d41ee96662 100644 --- a/docs/reference/cli/pixi/clean/cache.md +++ b/docs/reference/cli/pixi/clean/cache.md @@ -22,8 +22,10 @@ pixi clean cache [OPTIONS] : Clean only `exec` cache - `--repodata` : Clean only the repodata cache -- `--tool` -: Clean only the build backend tools cache +- `--build-backends` +: Clean only the build backends envs cache +- `--build` +: Clean only the pixi-build cache - `--yes (-y)` : Answer yes to all questions From 0997a79986dbf726b172dc63463127b5de1ac97d Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 15:05:41 +0100 Subject: [PATCH 4/6] Apply suggestions from code review [skip ci] Co-authored-by: Ruben Arts --- src/cli/clean.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli/clean.rs b/src/cli/clean.rs index a25024d34b..b87441ed8b 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -74,11 +74,11 @@ pub struct CacheArgs { #[arg(long)] pub repodata: bool, - /// Clean only the build backends envs cache. + /// Clean only the build backends environments cache. #[arg(long)] pub build_backends: bool, - /// Clean only the pixi-build cache + /// Clean only the build related cache #[arg(long)] pub build: bool, @@ -151,7 +151,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { remove_folder_with_progress(workspace.solve_group_environments_dir(), false).await?; remove_folder_with_progress(workspace.task_cache_folder(), false).await?; remove_folder_with_progress(workspace.activation_env_cache_folder(), false).await?; - remove_folder_with_progress(workspace.pixi_dir(), false).await?; + remove_folder_with_progress(workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), false).await?; } Ok(()) } @@ -184,6 +184,7 @@ async fn clean_cache(args: CacheArgs) -> miette::Result<()> { } if args.build { dirs.push(cache_dir.join(consts::CACHED_GIT_DIR)); + dirs.push(cache_dir.join(consts::CACHED_BUILD_TOOL_ENVS_DIR)); dirs.push(cache_dir.join(consts::CACHED_BUILD_WORK_DIR)); dirs.push(cache_dir.join(consts::CACHED_BUILD_BACKENDS)); dirs.push(cache_dir.join(consts::CACHED_SOURCE_BUILDS)); From 69016bb96c6f29315faecdaab02315224937da83 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 15:11:37 +0100 Subject: [PATCH 5/6] fix `--activation_cache --build` logic --- src/cli/clean.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/cli/clean.rs b/src/cli/clean.rs index b87441ed8b..05c0d5823e 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -131,12 +131,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { explicit_env.name().fancy_display() ); } - } else if args.activation_cache { - remove_folder_with_progress(workspace.activation_env_cache_folder(), true).await?; - } else if args.build { - remove_folder_with_progress(workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), true) - .await?; - } else { + } else if !args.activation_cache & !args.build { // Remove all pixi related work from the workspace. if !workspace .environments_dir() @@ -151,7 +146,22 @@ pub async fn execute(args: Args) -> miette::Result<()> { remove_folder_with_progress(workspace.solve_group_environments_dir(), false).await?; remove_folder_with_progress(workspace.task_cache_folder(), false).await?; remove_folder_with_progress(workspace.activation_env_cache_folder(), false).await?; - remove_folder_with_progress(workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), false).await?; + remove_folder_with_progress( + workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), + false, + ) + .await?; + } else { + if args.activation_cache { + remove_folder_with_progress(workspace.activation_env_cache_folder(), true).await?; + } + if args.build { + remove_folder_with_progress( + workspace.pixi_dir().join(consts::WORKSPACE_CACHE_DIR), + true, + ) + .await?; + } } Ok(()) } From 62a05bcb35eb200235b2f37faa23cc2495af2d95 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 7 Aug 2025 15:12:33 +0100 Subject: [PATCH 6/6] cli docs --- docs/reference/cli/pixi/clean/cache.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/cli/pixi/clean/cache.md b/docs/reference/cli/pixi/clean/cache.md index d41ee96662..ba216dbcab 100644 --- a/docs/reference/cli/pixi/clean/cache.md +++ b/docs/reference/cli/pixi/clean/cache.md @@ -23,9 +23,9 @@ pixi clean cache [OPTIONS] - `--repodata` : Clean only the repodata cache - `--build-backends` -: Clean only the build backends envs cache +: Clean only the build backends environments cache - `--build` -: Clean only the pixi-build cache +: Clean only the build related cache - `--yes (-y)` : Answer yes to all questions