Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
ruben-arts marked this conversation as resolved.
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";
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli/pixi/clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pixi clean [OPTIONS] [COMMAND]
: The environment directory to remove
- <a id="arg---activation-cache" href="#arg---activation-cache">`--activation-cache`</a>
: Only remove the activation cache
- <a id="arg---build" href="#arg---build">`--build`</a>
: Only remove the pixi-build cache

## Global Options
- <a id="arg---manifest-path" href="#arg---manifest-path">`--manifest-path <MANIFEST_PATH>`</a>
Expand Down
6 changes: 4 additions & 2 deletions docs/reference/cli/pixi/clean/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pixi clean cache [OPTIONS]
: Clean only `exec` cache
- <a id="arg---repodata" href="#arg---repodata">`--repodata`</a>
: Clean only the repodata cache
- <a id="arg---tool" href="#arg---tool">`--tool`</a>
: Clean only the build backend tools cache
- <a id="arg---build-backends" href="#arg---build-backends">`--build-backends`</a>
: Clean only the build backends environments cache
- <a id="arg---build" href="#arg---build">`--build`</a>
: Clean only the build related cache
- <a id="arg---yes" href="#arg---yes">`--yes (-y)`</a>
: Answer yes to all questions

Expand Down
45 changes: 39 additions & 6 deletions src/cli/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ pub struct Args {
command: Option<Command>,

/// The environment directory to remove.
#[arg(long, short, conflicts_with = "command")]
#[arg(long, short, conflicts_with_all = ["command", "build"])]
Comment thread
ruben-arts marked this conversation as resolved.
pub environment: Option<String>,

/// 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.
Expand Down Expand Up @@ -70,9 +74,13 @@ pub struct CacheArgs {
#[arg(long)]
pub repodata: bool,

/// Clean only the build backend tools cache.
/// Clean only the build backends environments cache.
#[arg(long)]
pub build_backends: bool,

/// Clean only the build related cache
#[arg(long)]
pub tool: bool,
pub build: bool,

/// Answer yes to all questions.
#[clap(short = 'y', long = "yes", alias = "assume-yes")]
Expand Down Expand Up @@ -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?;
Comment thread
ruben-arts marked this conversation as resolved.
tracing::info!(
"Only removing activation cache for explicit environment '{}'",
explicit_env.name().fancy_display()
Expand All @@ -123,7 +131,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
explicit_env.name().fancy_display()
);
}
} else {
} else if !args.activation_cache & !args.build {
// Remove all pixi related work from the workspace.
if !workspace
.environments_dir()
Expand All @@ -138,6 +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?;
} 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(())
}
Expand All @@ -162,12 +186,21 @@ 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.
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_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));
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()
Expand Down
Loading