diff --git a/docs/reference/cli/pixi/global/install.md b/docs/reference/cli/pixi/global/install.md index e411c0cbbd..2e2c2b9094 100644 --- a/docs/reference/cli/pixi/global/install.md +++ b/docs/reference/cli/pixi/global/install.md @@ -30,7 +30,7 @@ pixi global install [OPTIONS] ... - `--expose ` : Add one or more mapping which describe which executables are exposed. The syntax is `exposed_name=executable_name`, so for example `python3.10=python`. Alternatively, you can input only an executable_name and `executable_name=executable_name` is assumed - `--force-reinstall` -: Specifies that the packages should be reinstalled even if they are already installed +: Specifies that the environment should be reinstalled - `--no-shortcut` : Specifies that no shortcuts should be created for the installed packages - `--platform (-p) ` diff --git a/src/cli/global/install.rs b/src/cli/global/install.rs index 411301f6c9..980f2ec590 100644 --- a/src/cli/global/install.rs +++ b/src/cli/global/install.rs @@ -65,7 +65,7 @@ pub struct Args { #[clap(flatten)] config: ConfigCli, - /// Specifies that the packages should be reinstalled even if they are already installed. + /// Specifies that the environment should be reinstalled. #[arg(action, long)] force_reinstall: bool, @@ -168,6 +168,10 @@ async fn setup_environment( ) -> miette::Result { let mut state_changes = StateChanges::new_with_env(env_name.clone()); + if args.force_reinstall && project.environment(env_name).is_some() { + state_changes |= project.remove_environment(env_name).await?; + } + let channels = if args.channels.is_empty() { project.config().default_channels() } else { @@ -207,7 +211,7 @@ async fn setup_environment( } } - if !args.force_reinstall && project.environment_in_sync(env_name).await? { + if project.environment_in_sync(env_name).await? { return Ok(StateChanges::new_with_env(env_name.clone())); } diff --git a/tests/integration_python/pixi_global/test_global.py b/tests/integration_python/pixi_global/test_global.py index 8784023150..1e853bf296 100644 --- a/tests/integration_python/pixi_global/test_global.py +++ b/tests/integration_python/pixi_global/test_global.py @@ -817,7 +817,71 @@ def test_install_twice_with_same_env_name_as_expose( assert dummy_b.is_file() -def test_install_twice_with_force_reinstall( +def test_install_force_reinstall_removes_original_environment( + pixi: Path, tmp_pixi_workspace: Path, dummy_channel_1: str +) -> None: + env = {"PIXI_HOME": str(tmp_pixi_workspace)} + + dummy_b = tmp_pixi_workspace / "bin" / exec_extension("dummy-b") + dummy_c = tmp_pixi_workspace / "bin" / exec_extension("dummy-c") + + env_name = "test_env" + + # Install dummy-b + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "--environment", + env_name, + "dummy-b", + ], + env=env, + ) + assert dummy_b.is_file() + assert not dummy_c.is_file() + + # Install dummy-c, it should be added to the environment + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "--environment", + env_name, + "dummy-c", + ], + env=env, + ) + assert dummy_b.is_file() + assert dummy_c.is_file() + + # Install dummy-c with `--force-reinstall + # It should create a fresh environment + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "--environment", + env_name, + "dummy-c", + "--force-reinstall", + ], + env=env, + ) + assert not dummy_b.is_file() + assert dummy_c.is_file() + + +def test_install_with_different_channel_and_force_reinstall( pixi: Path, tmp_pixi_workspace: Path, dummy_channel_1: str, dummy_channel_2: str ) -> None: env = {"PIXI_HOME": str(tmp_pixi_workspace)} diff --git a/tests/integration_python/pixi_global/test_trampoline.py b/tests/integration_python/pixi_global/test_trampoline.py index fa372b963b..30e1e7f1a1 100644 --- a/tests/integration_python/pixi_global/test_trampoline.py +++ b/tests/integration_python/pixi_global/test_trampoline.py @@ -88,7 +88,6 @@ def test_trampoline_new_activation_scripts( pixi, "global", "install", - "--force-reinstall", "dummy-trampoline==0.2.0", ], env=env,