Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5baed6e
feat: add `pixi reinstall`
Hofer-Julian Mar 12, 2025
06e9567
Add first mostly acceptable test
Hofer-Julian Mar 13, 2025
673148e
Add proper test
Hofer-Julian Mar 13, 2025
46c41de
Fix CLI
Hofer-Julian Mar 13, 2025
90df9b0
Test remaining scenarios
Hofer-Julian Mar 13, 2025
f26755e
Hook everything up
Hofer-Julian Mar 13, 2025
50b8b66
Get everything to compile
Hofer-Julian Mar 13, 2025
4a02d55
Get it to compile again
Hofer-Julian Mar 13, 2025
8dadeb6
feat: set refresh strategy for the context
tdejager Mar 13, 2025
00922b5
Adapt for conda
Hofer-Julian Mar 13, 2025
8c59bf6
Adapt tests
Hofer-Julian Mar 13, 2025
6d90eaa
Reorder test a bit
Hofer-Julian Mar 13, 2025
80ccaa6
Only use package names that are actually in our records
Hofer-Julian Mar 14, 2025
597547d
feat: set refresh strategy for the cache
tdejager Mar 14, 2025
5f1881c
fix: test for osx-arm64
tdejager Mar 14, 2025
4c551d1
Fix test
Hofer-Julian Mar 14, 2025
a6f0c0b
pixi build rebuild
Hofer-Julian Mar 14, 2025
7cbc7ac
Fix pixi toml
Hofer-Julian Mar 14, 2025
61b7b0f
Fix tests (mostly)
Hofer-Julian Mar 14, 2025
9b13afd
Finalize tests
Hofer-Julian Mar 14, 2025
0874270
Merge branch 'main' into feat/pixi-reinstall
Hofer-Julian Mar 14, 2025
e284fca
Adapt CLI docs
Hofer-Julian Mar 14, 2025
f9da01b
Adapt string
Hofer-Julian Mar 14, 2025
736c303
Fix string changes
Hofer-Julian Mar 14, 2025
d120620
Merge branch 'main' into feat/pixi-reinstall
Hofer-Julian Mar 14, 2025
9c9200f
Fix CLI docs
Hofer-Julian Mar 14, 2025
ef9e29a
Merge branch 'main' into feat/pixi-reinstall
ruben-arts Mar 17, 2025
58cbb32
Merge branch 'main' into feat/pixi-reinstall
Hofer-Julian Mar 17, 2025
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 src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use pixi_config::ConfigCli;
/// Running `pixi install` is not required before running other commands like `pixi run` or `pixi shell`.
/// These commands will automatically install the environment if it is not already installed.
///
/// You can use `pixi clean` to remove the installed environments and start fresh.
/// You can use `pixi reinstall` to reinstall all environments, one environment or just some packages of an environment.
#[derive(Parser, Debug)]
pub struct Args {
#[clap(flatten)]
Expand Down
3 changes: 3 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod init;
pub mod install;
pub mod list;
pub mod lock;
pub mod reinstall;
pub mod remove;
pub mod run;
pub mod search;
Expand Down Expand Up @@ -134,6 +135,7 @@ pub enum Command {
Remove(remove::Args),
#[clap(visible_alias = "i")]
Install(install::Args),
Reinstall(install::Args),
Update(update::Args),
Upgrade(upgrade::Args),
Lock(lock::Args),
Expand Down Expand Up @@ -270,6 +272,7 @@ pub async fn execute_command(command: Command) -> miette::Result<()> {
Command::Global(cmd) => global::execute(cmd).await,
Command::Auth(cmd) => rattler::cli::auth::execute(cmd).await.into_diagnostic(),
Command::Install(cmd) => install::execute(cmd).await,
Command::Reinstall(cmd) => install::execute(cmd).await,
Command::Shell(cmd) => shell::execute(cmd).await,
Command::ShellHook(cmd) => shell_hook::execute(cmd).await,
Command::Task(cmd) => task::execute(cmd).await,
Expand Down
112 changes: 112 additions & 0 deletions src/cli/reinstall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use crate::cli::cli_config::WorkspaceConfig;
use crate::environment::get_update_lock_file_and_prefix;
use crate::lock_file::UpdateMode;
use crate::{UpdateLockFileOptions, WorkspaceLocator};
use clap::Parser;
use fancy_display::FancyDisplay;
use itertools::Itertools;
use pixi_config::ConfigCli;

/// Re-install an environment, both updating the lockfile and re-installing the environment.
///
/// This command reinstalls an environment, if the lockfile is not up-to-date it will be updated.
/// If `--package` is given, only the specified package will be reinstalled.
Comment thread
Hofer-Julian marked this conversation as resolved.
Outdated
/// Otherwise the whole environment will be reinstalled.
///
/// `pixi reinstall` only re-installs one environment at a time,
/// if you have multiple environments you can select the right one with the `--environment` flag.
/// If you don't provide an environment, the `default` environment will be re-installed.
///
/// If you want to re-install all environments, you can use the `--all` flag.
#[derive(Parser, Debug)]
pub struct Args {
#[clap(flatten)]
pub project_config: WorkspaceConfig,

#[clap(flatten)]
pub lock_file_usage: super::LockFileUsageConfig,

/// The environment to install
#[arg(long, short)]
pub environment: Option<Vec<String>>,

#[clap(flatten)]
pub config: ConfigCli,

/// Install all environments
#[arg(long, short, conflicts_with = "environment")]
pub all: bool,

/// Specifies the package that should be reinstalled.
#[arg(num_args = 1.., required = true, id = "PACKAGE")]
packages: Vec<String>,
}

pub async fn execute(args: Args) -> miette::Result<()> {
let workspace = WorkspaceLocator::for_cli()
.with_search_start(args.project_config.workspace_locator_start())
.locate()?
.with_cli_config(args.config);

// Install either:
//
// 1. specific environments
// 2. all environments
// 3. default environment (if no environments are specified)
let envs = if let Some(envs) = args.environment {
envs
} else if args.all {
workspace
.environments()
.iter()
.map(|env| env.name().to_string())
.collect()
} else {
vec![workspace.default_environment().name().to_string()]
};

let mut installed_envs = Vec::with_capacity(envs.len());
for env in envs {
let environment = workspace.environment_from_name_or_env_var(Some(env))?;

// Update the prefix by installing all packages
get_update_lock_file_and_prefix(
&environment,
UpdateMode::Revalidate,
UpdateLockFileOptions {
lock_file_usage: args.lock_file_usage.into(),
no_install: false,
max_concurrent_solves: workspace.config().max_concurrent_solves(),
},
)
.await?;

installed_envs.push(environment.name().clone());
}

// Message what's installed
let detached_envs_message =
if let Ok(Some(path)) = workspace.config().detached_environments().path() {
format!(" in '{}'", console::style(path.display()).bold())
} else {
"".to_string()
};

if installed_envs.len() == 1 {
eprintln!(
"{}The {} environment has been installed{}.",
console::style(console::Emoji("✔ ", "")).green(),
installed_envs[0].fancy_display(),
detached_envs_message
);
} else {
eprintln!(
"{}The following environments have been installed: {}\t{}",
console::style(console::Emoji("✔ ", "")).green(),
installed_envs.iter().map(|n| n.fancy_display()).join(", "),
detached_envs_message
);
}

Ok(())
}