Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --force-reinstall for global install #2275

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
6 changes: 5 additions & 1 deletion src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub struct Args {

#[clap(flatten)]
config: ConfigCli,

/// Specifies that the packages should be reinstalled even if they are already installed.
#[arg(action, long)]
force_reinstall: bool,
}

impl HasSpecs for Args {
Expand Down Expand Up @@ -158,7 +162,7 @@ async fn setup_environment(
}
}

if project.environment_in_sync(env_name).await? {
if !args.force_reinstall && project.environment_in_sync(env_name).await? {
return Ok(StateChanges::new_with_env(env_name.clone()));
}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
},
"packages": {},
"packages.conda": {
"dummy-b-0.1.0-hb0f4dca_0.conda": {
"arch": "x86_64",
"build": "hb0f4dca_0",
"build_number": 0,
"depends": [],
"md5": "f85960fbb020f325b1a881176f0af94a",
"name": "dummy-b",
"platform": "linux",
"sha256": "c1319a6e656c72410738cd99823a9c861e95568684e405d09c400bf2e400a904",
"size": 12212,
"subdir": "linux-64",
"timestamp": 1728983076380,
"version": "0.1.0"
},
"dummy-x-0.1.0-hb0f4dca_0.conda": {
"arch": "x86_64",
"build": "hb0f4dca_0",
"build_number": 0,
"depends": [],
"md5": "18c4298839160e3bbae390173b35293d",
"md5": "2fde9a3b035cb6e898c28ab7a3cc6c6d",
"name": "dummy-x",
"platform": "linux",
"sha256": "1c8369a424a9d8dad4be77915a4b30d940e7c7447118f6444fed5cee21cbd402",
"size": 5912,
"sha256": "e18f27d9ac595a8c30ca243223526d6b76e0a19ca186d950393243d2d209a79f",
"size": 15140,
"subdir": "linux-64",
"timestamp": 1727337510373,
"timestamp": 1728983076380,
"version": "0.1.0"
}
},
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
},
"packages": {},
"packages.conda": {
"dummy-b-0.1.0-h0dc7051_0.conda": {
"arch": "x86_64",
"build": "h0dc7051_0",
"build_number": 0,
"depends": [],
"md5": "01e59c205e5868da1383de347188aff0",
"name": "dummy-b",
"platform": "osx",
"sha256": "5b9b58c26fe363325bf55d6a2e853f6dd24fb7f68eb6920d315bcb7452088328",
"size": 32249,
"subdir": "osx-64",
"timestamp": 1728983076503,
"version": "0.1.0"
},
"dummy-x-0.1.0-h0dc7051_0.conda": {
"arch": "x86_64",
"build": "h0dc7051_0",
"build_number": 0,
"depends": [],
"md5": "2df37a2fbdce7376961e1ce9015e3fc6",
"md5": "6b53468a2a62b6fe93907a04fb69dd95",
"name": "dummy-x",
"platform": "osx",
"sha256": "9ada98c647d5d0aa35633f30c5bbd6f64ea97d2ff25c06c51d1f9264600bb598",
"size": 14313,
"sha256": "76c5eb3ceb3a470e2a6400b87aad855c634f4ac08f33d880887ec3f1fd4f22e1",
"size": 26189,
"subdir": "osx-64",
"timestamp": 1727337510468,
"timestamp": 1728983076503,
"version": "0.1.0"
}
},
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
},
"packages": {},
"packages.conda": {
"dummy-b-0.1.0-h60d57d3_0.conda": {
"arch": "arm64",
"build": "h60d57d3_0",
"build_number": 0,
"depends": [],
"md5": "edca682cc09a974b6453d9b19d32c351",
"name": "dummy-b",
"platform": "osx",
"sha256": "a90458015c443c443460064d14bbf1b6560ceb27b7d4eb204caf3e501e16865f",
"size": 18391,
"subdir": "osx-arm64",
"timestamp": 1728983076440,
"version": "0.1.0"
},
"dummy-x-0.1.0-h60d57d3_0.conda": {
"arch": "arm64",
"build": "h60d57d3_0",
"build_number": 0,
"depends": [],
"md5": "2f442a05d9f8384ce08fd9416b6f68bc",
"md5": "fe2b9de8fbcbd1a588ed41d04e850d2d",
"name": "dummy-x",
"platform": "osx",
"sha256": "4bb821c92815ffe4d5382224ae5c55198653dc487917edb893004dd333151338",
"size": 11703,
"sha256": "70b985a0464aca5c82985a334c90f85cc6290683efabcb3d01139ae9108ed2e3",
"size": 22135,
"subdir": "osx-arm64",
"timestamp": 1727337510420,
"timestamp": 1728983076440,
"version": "0.1.0"
}
},
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
},
"packages": {},
"packages.conda": {
"dummy-b-0.1.0-h9490d1a_0.conda": {
"arch": "x86_64",
"build": "h9490d1a_0",
"build_number": 0,
"depends": [],
"md5": "56b5a7a65150d4a2941515c9c3717c6f",
"name": "dummy-b",
"platform": "win",
"sha256": "e281921e34424985e680050bf1714289fdd4e20241b830410bfdfee55505dce6",
"size": 6195,
"subdir": "win-64",
"timestamp": 1728983076323,
"version": "0.1.0"
},
"dummy-x-0.1.0-h9490d1a_0.conda": {
"arch": "x86_64",
"build": "h9490d1a_0",
"build_number": 0,
"depends": [],
"md5": "0a82fb2f6e9da49968cba40b9187833d",
"md5": "feeb05a11f1ee00a94ec168991c8a46f",
"name": "dummy-x",
"platform": "win",
"sha256": "39b394c995a29f180f6543771e7a70abcad9feadba7d9663eed80c7296babb19",
"size": 2824,
"sha256": "90dfd8c70601d8efc60e91b48a928a40f48268a78829c457f88a40024cced32c",
"size": 3055,
"subdir": "win-64",
"timestamp": 1727337510326,
"timestamp": 1728983076323,
"version": "0.1.0"
}
},
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/test_data/dummy_channel_2/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ outputs:
else:
- echo "dummy-x on unix" > $PREFIX/bin/dummy-x
- chmod +x $PREFIX/bin/dummy-x

- package:
name: dummy-b
version: 0.1.0

build:
script:
- mkdir -p $PREFIX/bin
- if: win
then:
- echo "dummy-b on windows" > $PREFIX/bin/dummy-b.bat
else:
- echo "dummy-b on unix" > $PREFIX/bin/dummy-b
- chmod +x $PREFIX/bin/dummy-b
61 changes: 61 additions & 0 deletions tests/integration/test_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,67 @@ def test_install_twice(pixi: Path, tmp_path: Path, dummy_channel_1: str) -> None
assert dummy_b.is_file()


def test_install_twice_with_force_reinstall(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change the default channel in the config after the first install and check that another install does nothing. Then run force reinstall and check that it worked

pixi: Path, tmp_path: Path, dummy_channel_1: str, dummy_channel_2: str
) -> None:
env = {"PIXI_HOME": str(tmp_path)}

dummy_b = tmp_path / "bin" / exec_extension("dummy-b")

# Install dummy-b
verify_cli_command(
[
pixi,
"global",
"install",
"--channel",
dummy_channel_1,
"dummy-b",
],
env=env,
)
assert dummy_b.is_file()

# Modify dummy-b channel and try to install it again
# Even though we changed the channels, it will claim the environment is up-to-date

manifests = tmp_path / "manifests" / "pixi-global.toml"
parsed_toml = tomllib.loads(manifests.read_text())

parsed_toml["envs"]["dummy-b"]["channels"] = [dummy_channel_2]

manifests.write_text(tomli_w.dumps(parsed_toml))

verify_cli_command(
[
pixi,
"global",
"install",
"--channel",
dummy_channel_2,
"dummy-b",
],
env=env,
stderr_contains="The environment dummy-b was already up-to-date",
)

# Install dummy-b again, but with force-reinstall
# It should install it again
verify_cli_command(
[
pixi,
"global",
"install",
"--force-reinstall",
"--channel",
dummy_channel_2,
"dummy-b",
],
env=env,
stderr_contains="Added package dummy-b=0.1.0 to environment dummy-b",
)


def test_install_underscore(pixi: Path, tmp_path: Path, dummy_channel_1: str) -> None:
env = {"PIXI_HOME": str(tmp_path)}

Expand Down
Loading