mirror of https://github.com/mamba-org/mamba.git
feat: add canonical flag to list command (#3777)
This commit is contained in:
parent
daebc1be49
commit
9b6be1ce60
|
@ -22,16 +22,17 @@ namespace mamba
|
|||
{
|
||||
struct list_options
|
||||
{
|
||||
bool full_name;
|
||||
bool no_pip;
|
||||
bool reverse;
|
||||
bool explicit_;
|
||||
bool md5;
|
||||
bool full_name = false;
|
||||
bool no_pip = false;
|
||||
bool reverse = false;
|
||||
bool explicit_ = false;
|
||||
bool md5 = false;
|
||||
bool canonical = false;
|
||||
};
|
||||
|
||||
struct formatted_pkg
|
||||
{
|
||||
std::string name, version, build, channel, url, md5;
|
||||
std::string name, version, build, channel, url, md5, build_string, platform;
|
||||
};
|
||||
|
||||
bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b)
|
||||
|
@ -168,6 +169,7 @@ namespace mamba
|
|||
obj["channel"] = get_formatted_channel(pkg_info, channels.front());
|
||||
obj["base_url"] = get_base_url(pkg_info, channels.front());
|
||||
obj["url"] = pkg_info.package_url;
|
||||
obj["md5"] = pkg_info.md5;
|
||||
obj["build_number"] = pkg_info.build_number;
|
||||
obj["build_string"] = pkg_info.build_string;
|
||||
obj["dist_name"] = pkg_info.str();
|
||||
|
@ -201,6 +203,8 @@ namespace mamba
|
|||
formatted_pkgs.build = package.second.build_string;
|
||||
formatted_pkgs.url = package.second.package_url;
|
||||
formatted_pkgs.md5 = package.second.md5;
|
||||
formatted_pkgs.build_string = package.second.build_string;
|
||||
formatted_pkgs.platform = package.second.platform;
|
||||
packages.push_back(formatted_pkgs);
|
||||
}
|
||||
}
|
||||
|
@ -209,9 +213,13 @@ namespace mamba
|
|||
: compare_alphabetically;
|
||||
std::sort(packages.begin(), packages.end(), comparator);
|
||||
|
||||
// format and print table
|
||||
// format and print output
|
||||
if (options.explicit_)
|
||||
{
|
||||
if (options.canonical)
|
||||
{
|
||||
LOG_WARNING << "Option --canonical ignored because of --explicit";
|
||||
}
|
||||
for (auto p : packages)
|
||||
{
|
||||
if (options.md5)
|
||||
|
@ -224,6 +232,14 @@ namespace mamba
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (options.canonical)
|
||||
{
|
||||
for (auto p : packages)
|
||||
{
|
||||
std::cout << p.channel << "/" << p.platform << "::" << p.name << "-"
|
||||
<< p.version << "-" << p.build_string << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto requested_specs = prefix_data.history().get_requested_specs_map();
|
||||
|
@ -268,6 +284,7 @@ namespace mamba
|
|||
options.reverse = config.at("reverse").value<bool>();
|
||||
options.explicit_ = config.at("explicit").value<bool>();
|
||||
options.md5 = config.at("md5").value<bool>();
|
||||
options.canonical = config.at("canonical").value<bool>();
|
||||
|
||||
auto channel_context = ChannelContext::make_conda_compatible(config.context());
|
||||
detail::list_packages(config.context(), regex, channel_context, std::move(options));
|
||||
|
|
|
@ -50,12 +50,12 @@ init_list_parser(CLI::App* subcom, Configuration& config)
|
|||
);
|
||||
subcom->add_flag("--md5", md5.get_cli_config<bool>(), md5.description());
|
||||
|
||||
|
||||
// TODO: implement this in libmamba/list.cpp
|
||||
/*auto& canonical = config.insert(Configurable("canonical", false)
|
||||
.group("cli")
|
||||
.description("Output canonical names of packages only."));
|
||||
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());*/
|
||||
auto& canonical = config.insert(
|
||||
Configurable("canonical", false)
|
||||
.group("cli")
|
||||
.description("Output canonical names of packages only. Ignored if --explicit.")
|
||||
);
|
||||
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -81,17 +81,25 @@ def test_list_no_json(
|
|||
|
||||
@pytest.mark.parametrize("explicit_flag", ["", "--explicit"])
|
||||
@pytest.mark.parametrize("md5_flag", ["", "--md5"])
|
||||
@pytest.mark.parametrize("canonical_flag", ["", "-c", "--canonical"])
|
||||
@pytest.mark.parametrize("env_selector", ["", "name", "prefix"])
|
||||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
||||
def test_list_explicit(
|
||||
tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag, md5_flag
|
||||
def test_list_subcommands(
|
||||
tmp_home,
|
||||
tmp_root_prefix,
|
||||
tmp_env_name,
|
||||
tmp_xtensor_env,
|
||||
env_selector,
|
||||
explicit_flag,
|
||||
md5_flag,
|
||||
canonical_flag,
|
||||
):
|
||||
if env_selector == "prefix":
|
||||
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag)
|
||||
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag, canonical_flag)
|
||||
elif env_selector == "name":
|
||||
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag)
|
||||
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag, canonical_flag)
|
||||
else:
|
||||
res = helpers.umamba_list(explicit_flag, md5_flag)
|
||||
res = helpers.umamba_list(explicit_flag, md5_flag, canonical_flag)
|
||||
|
||||
outputs_list = res.strip().split("\n")[2:]
|
||||
if explicit_flag == "--explicit":
|
||||
|
@ -101,6 +109,12 @@ def test_list_explicit(
|
|||
assert "#" in output
|
||||
else:
|
||||
assert "#" not in output
|
||||
else:
|
||||
if canonical_flag == "--canonical":
|
||||
items = ["conda-forge/", "::"]
|
||||
for output in outputs_list:
|
||||
assert all(i in output for i in items)
|
||||
assert " " not in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])
|
||||
|
|
Loading…
Reference in New Issue