From 36aae71b5896e45fb6e4f096c25247558474c6e0 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Tue, 15 Oct 2024 15:00:09 +0200 Subject: [PATCH 1/6] fix: Explicitly pin python 3.12 Resolves the error on the CI. Signed-off-by: Julien Jerphanion --- micromamba/tests/test_env.py | 1 + 1 file changed, 1 insertion(+) diff --git a/micromamba/tests/test_env.py b/micromamba/tests/test_env.py index a29dff8f3a..80c6c57636 100644 --- a/micromamba/tests/test_env.py +++ b/micromamba/tests/test_env.py @@ -335,6 +335,7 @@ def test_env_update_conda_forge_with_pypi(tmp_home, tmp_root_prefix, tmp_path): channels: - conda-forge dependencies: +- python 3.12 # Numpy has not been released for python >=3.13 yet - numpy==2.0.0 """ From df278248a4ecae6c0905466df4cdcd4e6147c7be Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Tue, 15 Oct 2024 15:24:22 +0200 Subject: [PATCH 2/6] fix: Skip `test_env_update_pypi_with_conda_forge` on macOS Signed-off-by: Julien Jerphanion --- micromamba/tests/test_env.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/micromamba/tests/test_env.py b/micromamba/tests/test_env.py index 80c6c57636..e3b2002301 100644 --- a/micromamba/tests/test_env.py +++ b/micromamba/tests/test_env.py @@ -1,6 +1,7 @@ import os import re import shutil +import platform from packaging.version import Version from pathlib import Path @@ -340,6 +341,11 @@ def test_env_update_conda_forge_with_pypi(tmp_home, tmp_root_prefix, tmp_path): """ +# Skip test on macOS because numpy 1.26.4 is not available on conda-forge for arm64-apple-darwin20.0.0 and latest +# See: https://pypi.org/project/numpy/1.26.4/#files +@pytest.mark.skipif( + platform.system() == "Darwin", reason="numpy 1.26.4 is not available on conda-forge for macOS" +) @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) def test_env_update_pypi_with_conda_forge(tmp_home, tmp_root_prefix, tmp_path): env_prefix = tmp_path / "env-update-pypi-with-conda-forge" From 31dcf740905dfa18d0f6e7c28e3a052cc966f985 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 10 Oct 2024 16:37:57 +0200 Subject: [PATCH 3/6] fix: Only register channels in the context once This makes parsing their associated subdirs only once. Signed-off-by: Julien Jerphanion --- libmamba/src/api/install.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libmamba/src/api/install.cpp b/libmamba/src/api/install.cpp index caec744866..baa3700e73 100644 --- a/libmamba/src/api/install.cpp +++ b/libmamba/src/api/install.cpp @@ -4,6 +4,7 @@ // // The full license is in the file LICENSE, distributed with this software. +#include #include #include "mamba/api/channel_loader.hpp" @@ -409,7 +410,19 @@ namespace mamba { if (auto ms = specs::MatchSpec::parse(s); ms && ms->channel().has_value()) { - ctx.channels.push_back(ms->channel()->str()); + // Only register channels in the context once + // NOTE: ctx.channels could be a `std::unordered_set` but `yaml-cpp` does not + // support it. See: https://github.com/jbeder/yaml-cpp/issues/1322 Hence we + // perform linear scanning: `ctx.channels` is a short `std::vector` in practice + // so linearly searching is reasonable (probably even faster than using an + // `std::unordered_set`). + auto channel_name = ms->channel()->str(); + auto channel_is_absent = std::find(ctx.channels.begin(), ctx.channels.end(), channel_name) + == ctx.channels.end(); + if (channel_is_absent) + { + ctx.channels.push_back(channel_name); + } } } From a1407c75fe05c76dfad0158329ae1ea936d5e093 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 10 Oct 2024 17:28:34 +0200 Subject: [PATCH 4/6] Apply fix on update call path as well Signed-off-by: Julien Jerphanion --- libmamba/src/api/update.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libmamba/src/api/update.cpp b/libmamba/src/api/update.cpp index 26f679a48c..d651f438b6 100644 --- a/libmamba/src/api/update.cpp +++ b/libmamba/src/api/update.cpp @@ -155,7 +155,19 @@ namespace mamba { if (auto ms = specs::MatchSpec::parse(s); ms && ms->channel().has_value()) { - ctx.channels.push_back(ms->channel()->str()); + // Only register channels in the context once + // NOTE: ctx.channels could be a `std::unordered_set` but `yaml-cpp` does not + // support it. See: https://github.com/jbeder/yaml-cpp/issues/1322 Hence we + // perform linear scanning: `ctx.channels` is a short `std::vector` in practice + // so linearly searching is reasonable (probably even faster than using an + // `std::unordered_set`). + auto channel_name = ms->channel()->str(); + auto channel_is_absent = std::find(ctx.channels.begin(), ctx.channels.end(), channel_name) + == ctx.channels.end(); + if (channel_is_absent) + { + ctx.channels.push_back(channel_name); + } } } From 71dfe403158532691c75b19f31eb67309ebd8200 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Tue, 15 Oct 2024 15:57:16 +0200 Subject: [PATCH 5/6] Just use python 3.12 everywhere Signed-off-by: Julien Jerphanion --- micromamba/tests/test_env.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/micromamba/tests/test_env.py b/micromamba/tests/test_env.py index e3b2002301..a29dff8f3a 100644 --- a/micromamba/tests/test_env.py +++ b/micromamba/tests/test_env.py @@ -1,7 +1,6 @@ import os import re import shutil -import platform from packaging.version import Version from pathlib import Path @@ -336,16 +335,10 @@ def test_env_update_conda_forge_with_pypi(tmp_home, tmp_root_prefix, tmp_path): channels: - conda-forge dependencies: -- python 3.12 # Numpy has not been released for python >=3.13 yet - numpy==2.0.0 """ -# Skip test on macOS because numpy 1.26.4 is not available on conda-forge for arm64-apple-darwin20.0.0 and latest -# See: https://pypi.org/project/numpy/1.26.4/#files -@pytest.mark.skipif( - platform.system() == "Darwin", reason="numpy 1.26.4 is not available on conda-forge for macOS" -) @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) def test_env_update_pypi_with_conda_forge(tmp_home, tmp_root_prefix, tmp_path): env_prefix = tmp_path / "env-update-pypi-with-conda-forge" From 505e5e09ad546c96fdc2aad2d02da43b025ad1e9 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Wed, 23 Oct 2024 10:12:36 +0200 Subject: [PATCH 6/6] Factorize Context's channels population Signed-off-by: Julien Jerphanion --- libmamba/CMakeLists.txt | 4 +-- libmamba/src/api/install.cpp | 31 ++++--------------- libmamba/src/api/update.cpp | 23 ++------------ libmamba/src/api/{pip_utils.cpp => utils.cpp} | 24 +++++++++++++- libmamba/src/api/{pip_utils.hpp => utils.hpp} | 9 ++++-- 5 files changed, 39 insertions(+), 52 deletions(-) rename libmamba/src/api/{pip_utils.cpp => utils.cpp} (87%) rename libmamba/src/api/{pip_utils.hpp => utils.hpp} (80%) diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index 16716339ce..67c6fb7849 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -257,8 +257,8 @@ set( ${LIBMAMBA_SOURCE_DIR}/api/info.cpp ${LIBMAMBA_SOURCE_DIR}/api/install.cpp ${LIBMAMBA_SOURCE_DIR}/api/list.cpp - ${LIBMAMBA_SOURCE_DIR}/api/pip_utils.cpp - ${LIBMAMBA_SOURCE_DIR}/api/pip_utils.hpp + ${LIBMAMBA_SOURCE_DIR}/api/utils.cpp + ${LIBMAMBA_SOURCE_DIR}/api/utils.hpp ${LIBMAMBA_SOURCE_DIR}/api/remove.cpp ${LIBMAMBA_SOURCE_DIR}/api/repoquery.cpp ${LIBMAMBA_SOURCE_DIR}/api/shell.cpp diff --git a/libmamba/src/api/install.cpp b/libmamba/src/api/install.cpp index baa3700e73..083f42dbc0 100644 --- a/libmamba/src/api/install.cpp +++ b/libmamba/src/api/install.cpp @@ -27,7 +27,7 @@ #include "mamba/util/path_manip.hpp" #include "mamba/util/string.hpp" -#include "pip_utils.hpp" +#include "utils.hpp" namespace mamba { @@ -378,7 +378,7 @@ namespace mamba Context& ctx, ChannelContext& channel_context, const Configuration& config, - const std::vector& specs, + const std::vector& raw_specs, bool create_env, bool remove_prefix_on_failure, bool is_retry @@ -405,26 +405,7 @@ namespace mamba MultiPackageCache package_caches{ ctx.pkgs_dirs, ctx.validation_params }; - // add channels from specs - for (const auto& s : specs) - { - if (auto ms = specs::MatchSpec::parse(s); ms && ms->channel().has_value()) - { - // Only register channels in the context once - // NOTE: ctx.channels could be a `std::unordered_set` but `yaml-cpp` does not - // support it. See: https://github.com/jbeder/yaml-cpp/issues/1322 Hence we - // perform linear scanning: `ctx.channels` is a short `std::vector` in practice - // so linearly searching is reasonable (probably even faster than using an - // `std::unordered_set`). - auto channel_name = ms->channel()->str(); - auto channel_is_absent = std::find(ctx.channels.begin(), ctx.channels.end(), channel_name) - == ctx.channels.end(); - if (channel_is_absent) - { - ctx.channels.push_back(channel_name); - } - } - } + populate_context_channels_from_specs(raw_specs, ctx); if (ctx.channels.empty() && !ctx.offline) { @@ -456,8 +437,8 @@ namespace mamba load_installed_packages_in_database(ctx, db, prefix_data); - auto request = create_install_request(prefix_data, specs, freeze_installed); - add_pins_to_request(request, ctx, prefix_data, specs, no_pin, no_py_pin); + auto request = create_install_request(prefix_data, raw_specs, freeze_installed); + add_pins_to_request(request, ctx, prefix_data, raw_specs, no_pin, no_py_pin); request.flags = ctx.solver_flags; { @@ -485,7 +466,7 @@ namespace mamba ctx, channel_context, config, - specs, + raw_specs, create_env, remove_prefix_on_failure, true diff --git a/libmamba/src/api/update.cpp b/libmamba/src/api/update.cpp index d651f438b6..98b8d084c3 100644 --- a/libmamba/src/api/update.cpp +++ b/libmamba/src/api/update.cpp @@ -18,7 +18,7 @@ #include "mamba/solver/libsolv/solver.hpp" #include "mamba/solver/request.hpp" -#include "pip_utils.hpp" +#include "utils.hpp" namespace mamba { @@ -150,26 +150,7 @@ namespace mamba auto channel_context = ChannelContext::make_conda_compatible(ctx); - // add channels from specs - for (const auto& s : raw_update_specs) - { - if (auto ms = specs::MatchSpec::parse(s); ms && ms->channel().has_value()) - { - // Only register channels in the context once - // NOTE: ctx.channels could be a `std::unordered_set` but `yaml-cpp` does not - // support it. See: https://github.com/jbeder/yaml-cpp/issues/1322 Hence we - // perform linear scanning: `ctx.channels` is a short `std::vector` in practice - // so linearly searching is reasonable (probably even faster than using an - // `std::unordered_set`). - auto channel_name = ms->channel()->str(); - auto channel_is_absent = std::find(ctx.channels.begin(), ctx.channels.end(), channel_name) - == ctx.channels.end(); - if (channel_is_absent) - { - ctx.channels.push_back(channel_name); - } - } - } + populate_context_channels_from_specs(raw_update_specs, ctx); solver::libsolv::Database db{ channel_context.params() }; add_spdlog_logger_to_database(db); diff --git a/libmamba/src/api/pip_utils.cpp b/libmamba/src/api/utils.cpp similarity index 87% rename from libmamba/src/api/pip_utils.cpp rename to libmamba/src/api/utils.cpp index f8a2a6e15b..8e3fc2fe3f 100644 --- a/libmamba/src/api/pip_utils.cpp +++ b/libmamba/src/api/utils.cpp @@ -19,7 +19,7 @@ #include "mamba/fs/filesystem.hpp" #include "mamba/util/environment.hpp" -#include "pip_utils.hpp" +#include "utils.hpp" namespace mamba { @@ -184,4 +184,26 @@ namespace mamba return command; } + + void + populate_context_channels_from_specs(const std::vector& raw_matchspecs, Context& context) + { + for (const auto& s : raw_matchspecs) + { + if (auto ms = specs::MatchSpec::parse(s); ms && ms->channel().has_value()) + { + auto channel_name = ms->channel()->str(); + auto channel_is_absent = std::find( + context.channels.begin(), + context.channels.end(), + channel_name + ) + == context.channels.end(); + if (channel_is_absent) + { + context.channels.push_back(channel_name); + } + } + } + } } diff --git a/libmamba/src/api/pip_utils.hpp b/libmamba/src/api/utils.hpp similarity index 80% rename from libmamba/src/api/pip_utils.hpp rename to libmamba/src/api/utils.hpp index 5e5e5861f9..89a2481b53 100644 --- a/libmamba/src/api/pip_utils.hpp +++ b/libmamba/src/api/utils.hpp @@ -4,8 +4,8 @@ // // The full license is in the file LICENSE, distributed with this software. -#ifndef MAMBA_PIP_UTILS_HPP -#define MAMBA_PIP_UTILS_HPP +#ifndef MAMBA_UTILS_HPP +#define MAMBA_UTILS_HPP #include #include @@ -39,6 +39,9 @@ namespace mamba pip::Update update ); + void + populate_context_channels_from_specs(const std::vector& raw_matchspecs, Context& context); + } -#endif // MAMBA_PIP_UTILS_HPP +#endif // MAMBA_UTILS_HPP