Skip to content

Commit

Permalink
fix: Effectively apply dry-run on installation from PyPI (#3644)
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
  • Loading branch information
jjerphan authored Dec 5, 2024
1 parent e67178c commit 8ea3103
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,13 @@ namespace mamba

trans.execute(ctx, channel_context, prefix_data);

for (auto other_spec : config.at("others_pkg_mgrs_specs")
.value<std::vector<detail::other_pkg_mgr_spec>>())
if (!ctx.dry_run)
{
install_for_other_pkgmgr(ctx, other_spec, pip::Update::No);
for (auto other_spec : config.at("others_pkg_mgrs_specs")
.value<std::vector<detail::other_pkg_mgr_spec>>())
{
install_for_other_pkgmgr(ctx, other_spec, pip::Update::No);
}
}
}
else
Expand Down
34 changes: 34 additions & 0 deletions micromamba/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,3 +796,37 @@ def test_install_empty_base(tmp_home, tmp_root_prefix, tmp_path):
packages = helpers.umamba_list("-p", env_prefix, "--json")
assert any(package["name"] == "xtensor" for package in packages)
assert any(package["name"] == "python" for package in packages)


env_specific_pip = """
channels:
- conda-forge
dependencies:
- python
- pip:
- numpy
"""


# Test that dry runs works if package are specified for the `pip:` section
def test_dry_run_pip_section(tmp_home, tmp_root_prefix, tmp_path):
env_prefix = tmp_path / "env-specific-pip"

env_file_yml = tmp_path / "test_install_env_specific_pip.yaml"
env_file_yml.write_text(env_specific_pip)

res = helpers.create("-p", env_prefix, "--json", "pip")
assert res["success"]
packages_at_creation = helpers.umamba_list("-p", env_prefix, "--json")

# Install from the environment file
res = helpers.install("-p", env_prefix, "-f", env_file_yml, "--json", "--dry-run")
assert res["success"]
assert res["dry_run"]

packages = helpers.umamba_list("-p", env_prefix, "--json")
assert packages == packages_at_creation

# Check that the packages are not installed using `pip`
res = helpers.umamba_run("-p", env_prefix, "pip", "list")
assert "numpy" not in res

0 comments on commit 8ea3103

Please sign in to comment.