Skip to content

Commit

Permalink
Add ChannelContext::from_path
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Oct 10, 2023
1 parent 3218a52 commit ecaaf7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ namespace mamba
const std::string& channel_canonical_name
);

Channel from_any_path(specs::ChannelSpec&& spec);
Channel from_package_path(specs::ChannelSpec&& spec);
Channel from_path(specs::ChannelSpec&& spec);
Channel from_url(specs::ChannelSpec&& spec);
Channel from_name(const std::string& name);
Channel from_value(const std::string& value);
Expand Down
37 changes: 34 additions & 3 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,22 @@ namespace mamba
}
return std::array{ head.substr(0, head.size() - 1), tail };
}

auto
make_platforms(util::flat_set<std::string> filters, const std::vector<std::string>& defaults)
{
if (filters.empty())
{
for (const auto& plat : defaults)
{
filters.insert(plat);
}
}
return filters;
};
}

Channel ChannelContext::from_package_path(specs::ChannelSpec&& spec)
Channel ChannelContext::from_any_path(specs::ChannelSpec&& spec)
{
assert(util::url_get_scheme(spec.location()) == "file");

Expand All @@ -413,7 +426,7 @@ namespace mamba
);
}

auto path = uri.path();
auto path = uri.pretty_path();
auto [loc, name] = rsplit_once(path, '/');
for (const auto& [canonical_name, chan] : get_custom_channels())
{
Expand All @@ -437,6 +450,21 @@ namespace mamba
);
}

Channel ChannelContext::from_package_path(specs::ChannelSpec&& spec)
{
assert(spec.type() == specs::ChannelSpec::Type::PackagePath);
return from_any_path(std::move(spec));
}

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;
}

namespace
{
// Channel configuration
Expand Down Expand Up @@ -706,12 +734,15 @@ namespace mamba
{
return from_package_path(std::move(spec));
}
case specs::ChannelSpec::Type::Path:
{
return from_path(std::move(spec));
}
case specs::ChannelSpec::Type::PackageURL:
{
return from_url(std::move(spec));
}
case specs::ChannelSpec::Type::URL:
case specs::ChannelSpec::Type::Path:
{
auto plats = get_platforms();
auto chan = from_url(std::move(spec));
Expand Down

0 comments on commit ecaaf7e

Please sign in to comment.