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