Skip to content

Commit

Permalink
Remove ChannelContext ctor (#3002)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv authored Nov 22, 2023
1 parent 1ee4893 commit acd357d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
5 changes: 2 additions & 3 deletions libmamba/include/mamba/core/channel_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef MAMBA_CORE_CHANNEL_HPP
#define MAMBA_CORE_CHANNEL_HPP

#include <functional>
#include <string>
#include <string_view>

Expand Down Expand Up @@ -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&;
Expand All @@ -52,7 +51,7 @@ namespace mamba

ChannelResolveParams m_channel_params;
ChannelCache m_channel_cache;
const Context& m_context;
std::reference_wrapper<const Context> m_context;
};
}
#endif
8 changes: 0 additions & 8 deletions libmamba/src/core/channel_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions libmambapy/src/libmambapy/bindings/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -136,11 +139,11 @@ namespace mambapy

private:

template <class T, class D>
T& init_once(std::unique_ptr<T, D>& ptr, mamba::Context& context)
template <class T, class D, class Factory>
T& init_once(std::unique_ptr<T, D>& ptr, Factory&& factory)
{
static std::once_flag init_flag;
std::call_once(init_flag, [&] { ptr = std::make_unique<T>(context); });
std::call_once(init_flag, [&] { ptr = std::make_unique<T>(factory()); });
if (!ptr)
{
throw mamba::mamba_error(
Expand Down

0 comments on commit acd357d

Please sign in to comment.