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 docs/reference/cli/pixi/global/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pixi global install [OPTIONS] <PACKAGES>...
- <a id="arg---expose" href="#arg---expose">`--expose <EXPOSE>`</a>
: 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
- <a id="arg---force-reinstall" href="#arg---force-reinstall">`--force-reinstall`</a>
: Specifies that the packages should be reinstalled even if they are already installed
: Specifies that the environment should be reinstalled
- <a id="arg---no-shortcut" href="#arg---no-shortcut">`--no-shortcut`</a>
: Specifies that no shortcuts should be created for the installed packages
- <a id="arg---platform" href="#arg---platform">`--platform (-p) <PLATFORM>`</a>
Expand Down
8 changes: 6 additions & 2 deletions src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -168,6 +168,10 @@ async fn setup_environment(
) -> miette::Result<StateChanges> {
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 {
Expand Down Expand Up @@ -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()));
}

Expand Down
66 changes: 65 additions & 1 deletion tests/integration_python/pixi_global/test_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
1 change: 0 additions & 1 deletion tests/integration_python/pixi_global/test_trampoline.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def test_trampoline_new_activation_scripts(
pixi,
"global",
"install",
"--force-reinstall",
"dummy-trampoline==0.2.0",
],
env=env,
Expand Down