diff --git a/src/cli/global/install.rs b/src/cli/global/install.rs index 9afee27a4..6d46a618d 100644 --- a/src/cli/global/install.rs +++ b/src/cli/global/install.rs @@ -177,7 +177,7 @@ async fn setup_environment( } // Add the dependencies to the environment - for spec in specs { + for spec in specs.iter().chain(&args.with) { project.manifest.add_dependency( env_name, spec, diff --git a/src/global/project/mod.rs b/src/global/project/mod.rs index 63ced88cb..9d0aae0d2 100644 --- a/src/global/project/mod.rs +++ b/src/global/project/mod.rs @@ -701,14 +701,14 @@ impl Project { } } ExposedType::Filter(filter) => { - // Add new binaries that are not yet exposed and that come from one of the packages we filter on + // Add new binaries that are not yet exposed and that don't come from one of the packages we filter on let executable_names = env_executables .into_iter() .filter_map(|(package_name, executable)| { if filter.contains(&package_name) { - Some(executable) - } else { None + } else { + Some(executable) } }) .flatten() diff --git a/tests/integration/test_global.py b/tests/integration/test_global.py index e0ca077eb..16deeafd6 100644 --- a/tests/integration/test_global.py +++ b/tests/integration/test_global.py @@ -511,6 +511,142 @@ def test_existing_manifest_gets_version(pixi: Path, tmp_path: Path, dummy_channe assert actual_manifest == expected_manifest +def test_install_with_basic(pixi: Path, tmp_path: Path, dummy_channel_1: str) -> None: + env = {"PIXI_HOME": str(tmp_path)} + manifests = tmp_path.joinpath("manifests") + manifest = manifests.joinpath("pixi-global.toml") + + dummy_a = tmp_path / "bin" / exec_extension("dummy-a") + dummy_aa = tmp_path / "bin" / exec_extension("dummy-aa") + dummy_b = tmp_path / "bin" / exec_extension("dummy-b") + dummy_c = tmp_path / "bin" / exec_extension("dummy-c") + + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "dummy-a", + "--with", + "dummy-b", + "--with", + "dummy-c", + ], + env=env, + ) + + expected_manifest = f"""\ +version = {MANIFEST_VERSION} + +[envs.dummy-a] +channels = ["{dummy_channel_1}"] +dependencies = {{ dummy-a = "*", dummy-b = "*", dummy-c = "*" }} +exposed = {{ dummy-a = "dummy-a", dummy-aa = "dummy-aa" }} +""" + actual_manifest = manifest.read_text() + + # Ensure that the manifest is correctly adapted + assert actual_manifest == expected_manifest + + assert dummy_a.is_file() + assert dummy_aa.is_file() + assert not dummy_b.is_file() + assert not dummy_c.is_file() + + +def test_install_with_environment_no_expose( + pixi: Path, tmp_path: Path, dummy_channel_1: str +) -> None: + env = {"PIXI_HOME": str(tmp_path)} + manifests = tmp_path.joinpath("manifests") + manifest = manifests.joinpath("pixi-global.toml") + + dummy_a = tmp_path / "bin" / exec_extension("dummy-a") + dummy_aa = tmp_path / "bin" / exec_extension("dummy-aa") + dummy_b = tmp_path / "bin" / exec_extension("dummy-b") + + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "--environment", + "dummy", + "dummy-a", + "--with", + "dummy-b", + ], + env=env, + ) + + expected_manifest = f"""\ +version = {MANIFEST_VERSION} + +[envs.dummy] +channels = ["{dummy_channel_1}"] +dependencies = {{ dummy-a = "*", dummy-b = "*" }} +exposed = {{ dummy-a = "dummy-a", dummy-aa = "dummy-aa" }} +""" + actual_manifest = manifest.read_text() + + # Ensure that the manifest is correctly adapted + assert actual_manifest == expected_manifest + + assert dummy_a.is_file() + assert dummy_aa.is_file() + assert not dummy_b.is_file() + + +def test_install_with_environment_and_expose( + pixi: Path, tmp_path: Path, dummy_channel_1: str +) -> None: + env = {"PIXI_HOME": str(tmp_path)} + manifests = tmp_path.joinpath("manifests") + manifest = manifests.joinpath("pixi-global.toml") + + dummy_a = tmp_path / "bin" / exec_extension("dummy-a") + dummy_aa = tmp_path / "bin" / exec_extension("dummy-aa") + dummy_b = tmp_path / "bin" / exec_extension("dummy-b") + + verify_cli_command( + [ + pixi, + "global", + "install", + "--channel", + dummy_channel_1, + "--environment", + "dummy", + "--expose=dummy-b", + "dummy-a", + "--with", + "dummy-b", + ], + env=env, + ) + + expected_manifest = f"""\ +version = {MANIFEST_VERSION} + +[envs.dummy] +channels = ["{dummy_channel_1}"] +dependencies = {{ dummy-a = "*", dummy-b = "*" }} +exposed = {{ dummy-b = "dummy-b" }} +""" + actual_manifest = manifest.read_text() + + # Ensure that the manifest is correctly adapted + assert actual_manifest == expected_manifest + + assert not dummy_a.is_file() + assert not dummy_aa.is_file() + assert dummy_b.is_file() + + def test_install_twice(pixi: Path, tmp_path: Path, dummy_channel_1: str) -> None: env = {"PIXI_HOME": str(tmp_path)}