Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 27 additions & 5 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 envs cache.
Comment thread
lucascolley marked this conversation as resolved.
Outdated
#[arg(long)]
pub build_backends: bool,

/// Clean only the pixi-build cache
Comment thread
lucascolley marked this conversation as resolved.
Outdated
#[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,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?;
Comment thread
lucascolley marked this conversation as resolved.
Outdated
Comment thread
lucascolley marked this conversation as resolved.
Outdated
} else {
// Remove all pixi related work from the workspace.
if !workspace
Expand All @@ -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?;
Comment thread
lucascolley marked this conversation as resolved.
Outdated
}
Ok(())
}
Expand All @@ -162,12 +176,20 @@ 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_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));
}
Comment thread
lucascolley marked this conversation as resolved.
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