From 8ea3103d3c26261bc0443dc17e1d30c6f8aeee4d Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 5 Dec 2024 15:01:47 +0100 Subject: [PATCH] fix: Effectively apply dry-run on installation from PyPI (#3644) Signed-off-by: Julien Jerphanion --- libmamba/src/api/install.cpp | 9 ++++++--- micromamba/tests/test_install.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/libmamba/src/api/install.cpp b/libmamba/src/api/install.cpp index 9e64576b08..d6ebca5033 100644 --- a/libmamba/src/api/install.cpp +++ b/libmamba/src/api/install.cpp @@ -537,10 +537,13 @@ namespace mamba trans.execute(ctx, channel_context, prefix_data); - for (auto other_spec : config.at("others_pkg_mgrs_specs") - .value>()) + 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>()) + { + install_for_other_pkgmgr(ctx, other_spec, pip::Update::No); + } } } else diff --git a/micromamba/tests/test_install.py b/micromamba/tests/test_install.py index 2db7955afa..f542c19624 100644 --- a/micromamba/tests/test_install.py +++ b/micromamba/tests/test_install.py @@ -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