Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only register channels in the context once #3521

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// The full license is in the file LICENSE, distributed with this software.

#include <algorithm>
#include <stdexcept>

#include "mamba/api/channel_loader.hpp"
Expand All @@ -26,7 +27,7 @@
#include "mamba/util/path_manip.hpp"
#include "mamba/util/string.hpp"

#include "pip_utils.hpp"
#include "utils.hpp"

namespace mamba
{
Expand Down Expand Up @@ -377,7 +378,7 @@ namespace mamba
Context& ctx,
ChannelContext& channel_context,
const Configuration& config,
const std::vector<std::string>& specs,
const std::vector<std::string>& raw_specs,
bool create_env,
bool remove_prefix_on_failure,
bool is_retry
Expand All @@ -404,14 +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())
{
ctx.channels.push_back(ms->channel()->str());
}
}
populate_context_channels_from_specs(raw_specs, ctx);

if (ctx.channels.empty() && !ctx.offline)
{
Expand Down Expand Up @@ -443,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;

{
Expand Down Expand Up @@ -472,7 +466,7 @@ namespace mamba
ctx,
channel_context,
config,
specs,
raw_specs,
create_env,
remove_prefix_on_failure,
true
Expand Down
11 changes: 2 additions & 9 deletions libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "mamba/solver/libsolv/solver.hpp"
#include "mamba/solver/request.hpp"

#include "pip_utils.hpp"
#include "utils.hpp"

namespace mamba
{
Expand Down Expand Up @@ -150,14 +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())
{
ctx.channels.push_back(ms->channel()->str());
}
}
populate_context_channels_from_specs(raw_update_specs, ctx);

solver::libsolv::Database db{ channel_context.params() };
add_spdlog_logger_to_database(db);
Expand Down
24 changes: 23 additions & 1 deletion libmamba/src/api/pip_utils.cpp → libmamba/src/api/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "mamba/fs/filesystem.hpp"
#include "mamba/util/environment.hpp"

#include "pip_utils.hpp"
#include "utils.hpp"

namespace mamba
{
Expand Down Expand Up @@ -184,4 +184,26 @@ namespace mamba

return command;
}

void
populate_context_channels_from_specs(const std::vector<std::string>& 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);
}
}
}
}
}
9 changes: 6 additions & 3 deletions libmamba/src/api/pip_utils.hpp → libmamba/src/api/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdexcept>
#include <string>
Expand Down Expand Up @@ -39,6 +39,9 @@ namespace mamba
pip::Update update
);

void
populate_context_channels_from_specs(const std::vector<std::string>& raw_matchspecs, Context& context);

}

#endif // MAMBA_PIP_UTILS_HPP
#endif // MAMBA_UTILS_HPP
Loading