Skip to content

Commit

Permalink
Parse subdirs in CLI match specs (#2799)
Browse files Browse the repository at this point in the history
Fixes #2792

For example, the channel in `install conda-forge/noarch::tzdata` would
previously be parsed as `conda-forge/noarch` while it should be parsed
as `conda-forge` with `noarch` subdir.
  • Loading branch information
jonashaag authored Aug 31, 2023
1 parent 207e755 commit c51ce62
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
1 change: 1 addition & 0 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace mamba
{
std::vector<std::string> get_known_platforms();
// Note: Channels can only be created using ChannelContext.
class Channel
{
Expand Down
12 changes: 8 additions & 4 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,17 @@ namespace mamba
// that already contains the platform
else
{
std::string cleaned_url = "", platform = "";
std::string platform = "";
util::split_platform(
KNOWN_PLATFORMS,
get_known_platforms(),
value,
Context::instance().platform,
cleaned_url,
value,
platform
);
if (!platform.empty())
{
platforms.push_back(std::move(platform));
value = cleaned_url;
}
}
}
Expand All @@ -256,6 +255,11 @@ namespace mamba
}
} // namespace

std::vector<std::string> get_known_platforms()
{
return KNOWN_PLATFORMS;
}

/**************************
* Channel implementation *
**************************/
Expand Down
25 changes: 13 additions & 12 deletions libmamba/src/core/match_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <regex>

#include "mamba/core/channel.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/environment.hpp"
#include "mamba/core/match_spec.hpp"
#include "mamba/core/output.hpp"
Expand Down Expand Up @@ -177,17 +178,14 @@ namespace mamba
{
throw std::runtime_error("Parsing of channel / namespace / subdir failed.");
}
// TODO implement Channel, and parsing of the channel here!
// channel = subdir = channel_str;
// channel, subdir = _parse_channel(channel_str)
// if 'channel' in brackets:
// b_channel, b_subdir = _parse_channel(brackets.pop('channel'))
// if b_channel:
// channel = b_channel
// if b_subdir:
// subdir = b_subdir
// if 'subdir' in brackets:
// subdir = brackets.pop('subdir')

std::string cleaned_url;
std::string platform;
util::split_platform(get_known_platforms(), channel, Context::instance().platform, channel, platform);
if (!platform.empty())
{
subdir = platform;
}

// support faulty conda matchspecs such as `libblas=[build=*mkl]`, which is
// the repr of `libblas=*=*mkl`
Expand Down Expand Up @@ -279,7 +277,10 @@ namespace mamba
}
else if (k == "subdir")
{
subdir = v;
if (platform.empty())
{
subdir = v;
}
}
else if (k == "url")
{
Expand Down
25 changes: 25 additions & 0 deletions libmamba/tests/src/core/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ namespace mamba
MatchSpec ms("numpy=1.20", channel_context);
CHECK_EQ(ms.str(), "numpy=1.20");
}

{
MatchSpec ms("conda-forge::tzdata", channel_context);
CHECK_EQ(ms.str(), "conda-forge::tzdata");
}
{
MatchSpec ms("conda-forge::noarch/tzdata", channel_context);
CHECK_EQ(ms.str(), "conda-forge::noarch/tzdata");
}
{
MatchSpec ms("pkgs/main::tzdata", channel_context);
CHECK_EQ(ms.str(), "pkgs/main::tzdata");
}
{
MatchSpec ms("pkgs/main/noarch::tzdata", channel_context);
CHECK_EQ(ms.str(), "pkgs/main/noarch::tzdata");
}
{
MatchSpec ms("conda-forge/noarch::tzdata[subdir=linux64]", channel_context);
CHECK_EQ(ms.str(), "conda-forge/noarch::tzdata");
}
{
MatchSpec ms("conda-forge::tzdata[subdir=linux64]", channel_context);
CHECK_EQ(ms.str(), "conda-forge/linux64::tzdata");
}
}

TEST_CASE("is_simple")
Expand Down
20 changes: 20 additions & 0 deletions libmamba/tests/src/util/test_url_manip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ TEST_SUITE("util::url_manip")

CHECK_EQ(platform_found, "noarch");
CHECK_EQ(cleaned_url, "https://mamba.com");

split_platform(
{ "noarch", "linux-64" },
"https://conda.anaconda.org/conda-forge/noarch",
std::string(mamba::specs::build_platform_name()),
cleaned_url,
platform_found
);
CHECK_EQ(platform_found, "noarch");
CHECK_EQ(cleaned_url, "https://conda.anaconda.org/conda-forge");

split_platform(
{ "noarch", "linux-64" },
"https://conda.anaconda.org/pkgs/main/noarch",
std::string(mamba::specs::build_platform_name()),
cleaned_url,
platform_found
);
CHECK_EQ(platform_found, "noarch");
CHECK_EQ(cleaned_url, "https://conda.anaconda.org/pkgs/main");
}

TEST_CASE("path_to_url")
Expand Down

0 comments on commit c51ce62

Please sign in to comment.