feat: add md5 flag to list command (#3773)

This commit is contained in:
Sandrine Pataut 2025-01-28 15:19:11 +01:00 committed by GitHub
parent 71e4545022
commit 7b6516d2fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 11 deletions

View File

@ -26,11 +26,12 @@ namespace mamba
bool no_pip;
bool reverse;
bool explicit_;
bool md5;
};
struct formatted_pkg
{
std::string name, version, build, channel, url;
std::string name, version, build, channel, url, md5;
};
bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b)
@ -199,6 +200,7 @@ namespace mamba
formatted_pkgs.version = package.second.version;
formatted_pkgs.build = package.second.build_string;
formatted_pkgs.url = package.second.package_url;
formatted_pkgs.md5 = package.second.md5;
packages.push_back(formatted_pkgs);
}
}
@ -212,7 +214,14 @@ namespace mamba
{
for (auto p : packages)
{
std::cout << p.url << std::endl;
if (options.md5)
{
std::cout << p.url << "#" << p.md5 << std::endl;
}
else
{
std::cout << p.url << std::endl;
}
}
}
else
@ -258,6 +267,7 @@ namespace mamba
options.no_pip = config.at("no_pip").value<bool>();
options.reverse = config.at("reverse").value<bool>();
options.explicit_ = config.at("explicit").value<bool>();
options.md5 = config.at("md5").value<bool>();
auto channel_context = ChannelContext::make_conda_compatible(config.context());
detail::list_packages(config.context(), regex, channel_context, std::move(options));

View File

@ -45,6 +45,11 @@ init_list_parser(CLI::App* subcom, Configuration& config)
));
subcom->add_flag("--explicit", explicit_.get_cli_config<bool>(), explicit_.description());
auto& md5 = config.insert(
Configurable("md5", false).group("cli").description("Add MD5 hashsum when using --explicit")
);
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)

View File

@ -1675,6 +1675,7 @@ def test_glob_in_build_string(monkeypatch, tmp_path):
for package in out["actions"]["FETCH"]
)
def test_non_url_encoding(tmp_path):
# Non-regression test for https://github.com/mamba-org/mamba/issues/3737
env_prefix = tmp_path / "env-non_url_encoding"
@ -1692,4 +1693,3 @@ def test_non_url_encoding(tmp_path):
non_encoded_url_start = "https://conda.anaconda.org/conda-forge/linux-64/x264-1!"
out = helpers.run_env("export", "-p", env_prefix, "--explicit")
assert non_encoded_url_start in out

View File

@ -80,22 +80,27 @@ def test_list_no_json(
@pytest.mark.parametrize("explicit_flag", ["", "--explicit"])
@pytest.mark.parametrize("md5_flag", ["", "--md5"])
@pytest.mark.parametrize("env_selector", ["", "name", "prefix"])
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_list_explicit_no_json(
tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag
def test_list_explicit(
tmp_home, tmp_root_prefix, tmp_env_name, tmp_xtensor_env, env_selector, explicit_flag, md5_flag
):
if env_selector == "prefix":
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag)
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag)
elif env_selector == "name":
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag)
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag)
else:
res = helpers.umamba_list(explicit_flag)
res = helpers.umamba_list(explicit_flag, md5_flag)
packages_url_list = res.strip().split("\n")[2:]
outputs_list = res.strip().split("\n")[2:]
if explicit_flag == "--explicit":
for url in packages_url_list:
assert "conda-forge" in url
for output in outputs_list:
assert "/conda-forge/" in output
if md5_flag == "--md5":
assert "#" in output
else:
assert "#" not in output
@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])