From 0f53b363c0f17f3e4bfb283a9df4312e10ae272c Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Fri, 3 Jan 2025 15:55:29 +0100 Subject: [PATCH 1/3] test: Add non-regression test Signed-off-by: Julien Jerphanion --- micromamba/tests/test_create.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/micromamba/tests/test_create.py b/micromamba/tests/test_create.py index 18b92c3b1b..a54089b213 100644 --- a/micromamba/tests/test_create.py +++ b/micromamba/tests/test_create.py @@ -1495,3 +1495,30 @@ def memory_intensive_operation(): pytest.fail( f"test_create_with_empty_lines_and_comments exceeded memory limit of {memory_limit} MB (used {max_memory:.2f} MB)" ) + + +def test_update_spec_list(tmp_path): + env_prefix = tmp_path / "env-invalid_spec" + + env_spec = """ +# This file may be used to create an environment using: +# $ conda create --name --file +# platform: linux-64 +@EXPLICIT +https://conda.anaconda.org/conda-forge/noarch/pip-24.3.1-pyh145f28c_2.conda#76601b0ccfe1fe13a21a5f8813cb38de +""" + + env_spec_file = tmp_path / "env_spec.txt" + + update_specs_list = """ + Updating specs: + + - pip==24.3.1=pyh145f28c_2 +""" + + with open(env_spec_file, "w") as f: + f.write(env_spec) + + out = helpers.create("-p", env_prefix, "-f", env_spec_file, "--dry-run") + + assert update_specs_list in out From 074da54d62fa163166abf95edc2e8e5763dd5566 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Fri, 3 Jan 2025 15:50:30 +0100 Subject: [PATCH 2/3] fix: Correctly populate lists of `MatchSpec` in `MTransaction`'s history Signed-off-by: Julien Jerphanion --- libmamba/src/core/transaction.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libmamba/src/core/transaction.cpp b/libmamba/src/core/transaction.cpp index 6daa990a12..4f4038f65b 100644 --- a/libmamba/src/core/transaction.cpp +++ b/libmamba/src/core/transaction.cpp @@ -177,13 +177,26 @@ namespace mamba [](const auto& pkg) { return explicit_spec(pkg); } ); + m_history_entry.update.reserve(pkgs_to_install.size()); + for (auto& pkg : pkgs_to_install) + { + m_history_entry.update.push_back(explicit_spec(pkg).str()); + } + m_history_entry.remove.reserve(pkgs_to_remove.size()); + for (auto& pkg : pkgs_to_remove) + { + m_history_entry.remove.push_back(explicit_spec(pkg).str()); + } + m_solution.actions.reserve(pkgs_to_install.size() + pkgs_to_remove.size()); + std::transform( std::move_iterator(pkgs_to_install.begin()), std::move_iterator(pkgs_to_install.end()), std::back_insert_iterator(m_solution.actions), [](specs::PackageInfo&& pkg) { return solver::Solution::Install{ std::move(pkg) }; } ); + std::transform( std::move_iterator(pkgs_to_remove.begin()), std::move_iterator(pkgs_to_remove.end()), @@ -191,17 +204,6 @@ namespace mamba [](specs::PackageInfo&& pkg) { return solver::Solution::Remove{ std::move(pkg) }; } ); - m_history_entry.remove.reserve(pkgs_to_remove.size()); - for (auto& pkg : pkgs_to_remove) - { - m_history_entry.remove.push_back(explicit_spec(pkg).str()); - } - m_history_entry.update.reserve(pkgs_to_install.size()); - for (auto& pkg : pkgs_to_install) - { - m_history_entry.update.push_back(explicit_spec(pkg).str()); - } - // if no action required, don't even start logging them if (!empty()) { From 78149a5fa7e8a3d6f4af50fe35bf56313b7c8374 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Mon, 6 Jan 2025 12:50:32 +0100 Subject: [PATCH 3/3] Remove "\r" in the output Signed-off-by: Julien Jerphanion --- micromamba/tests/test_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micromamba/tests/test_create.py b/micromamba/tests/test_create.py index a54089b213..2983d1a6b8 100644 --- a/micromamba/tests/test_create.py +++ b/micromamba/tests/test_create.py @@ -1521,4 +1521,4 @@ def test_update_spec_list(tmp_path): out = helpers.create("-p", env_prefix, "-f", env_spec_file, "--dry-run") - assert update_specs_list in out + assert update_specs_list in out.replace("\r", "")