Skip to content

Commit

Permalink
Resolve 1
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Nov 10, 2023
1 parent 32fcdab commit 2cb632e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 42 deletions.
18 changes: 15 additions & 3 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ namespace mamba
{
public:

struct ResolveParams
{
using platform_list = util::flat_set<std::string>;
using channel_list = std::vector<Channel>;
using channel_map = std::map<std::string, Channel>;
using multichannel_map = std::unordered_map<std::string, channel_list>;

const platform_list& platforms;
const specs::CondaURL& channel_alias;
const channel_map& custom_channels;

// TODO add CWD and home
};


Channel(
specs::CondaURL url,
std::string canonical_name,
Expand Down Expand Up @@ -117,9 +132,6 @@ namespace mamba

void init_custom_channels();

Channel from_any_path(specs::ChannelSpec&& spec);
Channel from_package_path(specs::ChannelSpec&& spec);
Channel from_path(specs::ChannelSpec&& spec);
Channel from_any_url(specs::ChannelSpec&& spec);
Channel from_package_url(specs::ChannelSpec&& spec);
Channel from_url(specs::ChannelSpec&& spec);
Expand Down
88 changes: 49 additions & 39 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ namespace mamba
}
}

auto
make_platforms(util::flat_set<std::string> filters, const util::flat_set<std::string>& defaults)
{
return filters.empty() ? defaults : filters;
}

auto
make_platforms(util::flat_set<std::string> filters, const std::vector<std::string>& defaults)
{
Expand All @@ -229,53 +235,51 @@ namespace mamba
}
}
return filters;
};
}

Channel ChannelContext::from_any_path(specs::ChannelSpec&& spec)
{
auto uri = specs::CondaURL::parse(util::path_or_url_to_url(spec.location()));
}

for (const auto& [canonical_name, chan] : get_custom_channels())
auto canonical_name_from_path(const specs::CondaURL& uri, Channel::ResolveParams params)
-> std::string
{
if (url_match(chan.url(), uri))
for (const auto& [canonical_name, chan] : params.custom_channels)
{
return Channel(
/* url= */ std::move(uri),
/* canonical_name= */ std::string(canonical_name)
);
if (url_match(chan.url(), uri))
{
return std::string(canonical_name);
}
}

if (const auto& ca = params.channel_alias; url_match(ca, uri))
{
return std::string(util::strip(util::remove_prefix(uri.path(), ca.path()), '/'));
}

return uri.pretty_str();
}

if (const auto& ca = get_channel_alias(); url_match(ca, uri))
auto resolve_any_path(specs::ChannelSpec&& spec, Channel::ResolveParams params) -> Channel
{
auto name = util::strip(util::remove_prefix(uri.path(), ca.path()), '/');
return Channel(
/* url= */ std::move(uri),
/* canonical_name= */ std::string(name)
);
}
auto uri = specs::CondaURL::parse(util::path_or_url_to_url(spec.location()));
auto canonical_name = canonical_name_from_path(uri, params);
auto platforms = Channel::ResolveParams::platform_list{};
if (spec.type() == specs::ChannelSpec::Type::Path)
{
platforms = make_platforms(spec.clear_platform_filters(), params.platforms);
}

auto canonical_name = uri.pretty_str();
return Channel(
/* url= */ std::move(uri),
/* canonical_name= */ std::move(canonical_name)
);
}
return Channel(std::move(uri), std::move(canonical_name), std::move(platforms));
}

Channel ChannelContext::from_package_path(specs::ChannelSpec&& spec)
{
assert(spec.type() == specs::ChannelSpec::Type::PackagePath);
return from_any_path(std::move(spec));
}
auto resolve_package_path(specs::ChannelSpec&& spec, Channel::ResolveParams params) -> Channel
{
assert(spec.type() == specs::ChannelSpec::Type::PackagePath);
return resolve_any_path(std::move(spec), params);
}

Channel ChannelContext::from_path(specs::ChannelSpec&& spec)
{
assert(spec.type() == specs::ChannelSpec::Type::Path);
auto platforms = make_platforms(spec.clear_platform_filters(), m_context.platforms());
auto chan = from_any_path(std::move(spec));
chan.m_platforms = std::move(platforms);
return chan;
auto resolve_path(specs::ChannelSpec&& spec, Channel::ResolveParams params) -> Channel
{
assert(spec.type() == specs::ChannelSpec::Type::Path);
return resolve_any_path(std::move(spec), params);
}
}

Channel ChannelContext::from_any_url(specs::ChannelSpec&& spec)
Expand Down Expand Up @@ -397,16 +401,22 @@ namespace mamba
}

auto spec = specs::ChannelSpec::parse(in_value);
const auto& platforms = m_context.platforms();
auto params = Channel::ResolveParams{
/* .platforms */ { platforms.cbegin(), platforms.cend() },
/* .channel_alias */ m_channel_alias,
/* .custom_channels */ m_custom_channels,
};

switch (spec.type())
{
case specs::ChannelSpec::Type::PackagePath:
{
return from_package_path(std::move(spec));
return resolve_package_path(std::move(spec), params);
}
case specs::ChannelSpec::Type::Path:
{
return from_path(std::move(spec));
return resolve_path(std::move(spec), params);
}
case specs::ChannelSpec::Type::PackageURL:
{
Expand Down

0 comments on commit 2cb632e

Please sign in to comment.