From acd357df95d7bf1a7f14ee0afa4aa87b0aa7d14f Mon Sep 17 00:00:00 2001 From: Antoine Prouvost Date: Wed, 22 Nov 2023 18:45:43 +0100 Subject: [PATCH] Remove ChannelContext ctor (#3002) --- libmamba/include/mamba/core/channel_context.hpp | 5 ++--- libmamba/src/core/channel_context.cpp | 8 -------- libmambapy/src/libmambapy/bindings/legacy.cpp | 11 +++++++---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/libmamba/include/mamba/core/channel_context.hpp b/libmamba/include/mamba/core/channel_context.hpp index 0936b89831..08a1b43df3 100644 --- a/libmamba/include/mamba/core/channel_context.hpp +++ b/libmamba/include/mamba/core/channel_context.hpp @@ -7,6 +7,7 @@ #ifndef MAMBA_CORE_CHANNEL_HPP #define MAMBA_CORE_CHANNEL_HPP +#include #include #include @@ -38,8 +39,6 @@ namespace mamba */ ChannelContext(Context& ctx, ChannelResolveParams params); - explicit ChannelContext(Context& ctx); - auto make_channel(std::string_view name) -> const channel_list&; [[nodiscard]] auto params() const -> const specs::ChannelResolveParams&; @@ -52,7 +51,7 @@ namespace mamba ChannelResolveParams m_channel_params; ChannelCache m_channel_cache; - const Context& m_context; + std::reference_wrapper m_context; }; } #endif diff --git a/libmamba/src/core/channel_context.cpp b/libmamba/src/core/channel_context.cpp index a4f9402b90..5959847d46 100644 --- a/libmamba/src/core/channel_context.cpp +++ b/libmamba/src/core/channel_context.cpp @@ -96,14 +96,6 @@ namespace mamba } } - ChannelContext::ChannelContext(Context& context) - : m_channel_params(make_simple_params_base(context)) - , m_context(context) - { - add_conda_params_custom_channel(m_channel_params, m_context); - add_simple_params_custom_multichannel(m_channel_params, m_context); - } - ChannelContext::ChannelContext(Context& context, ChannelResolveParams params) : m_channel_params(std::move(params)) , m_context(context) diff --git a/libmambapy/src/libmambapy/bindings/legacy.cpp b/libmambapy/src/libmambapy/bindings/legacy.cpp index 8a550c135e..3dd910b9d3 100644 --- a/libmambapy/src/libmambapy/bindings/legacy.cpp +++ b/libmambapy/src/libmambapy/bindings/legacy.cpp @@ -126,7 +126,10 @@ namespace mambapy } mamba::ChannelContext& channel_context() { - return init_once(p_channel_context, m_context); + return init_once( + p_channel_context, + [&]() { return mamba::ChannelContext::make_conda_compatible(m_context); } + ); } mamba::Configuration& config() @@ -136,11 +139,11 @@ namespace mambapy private: - template - T& init_once(std::unique_ptr& ptr, mamba::Context& context) + template + T& init_once(std::unique_ptr& ptr, Factory&& factory) { static std::once_flag init_flag; - std::call_once(init_flag, [&] { ptr = std::make_unique(context); }); + std::call_once(init_flag, [&] { ptr = std::make_unique(factory()); }); if (!ptr) { throw mamba::mamba_error(