mirror of https://github.com/mamba-org/mamba.git
Fix dependency and `subdir` in repoquery `whoneeds` (#3743)
This commit is contained in:
parent
503f0aa9b0
commit
4a69e30d29
|
@ -581,13 +581,6 @@ namespace mamba
|
|||
{
|
||||
return util::split(str, "/", 1).front(); // Has at least one element
|
||||
}
|
||||
|
||||
/** Get subdir from channel name. */
|
||||
auto get_subdir(std::string_view str) -> std::string
|
||||
{
|
||||
return util::split(str, "/").back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto QueryResult::table(std::ostream& out, const std::vector<std::string_view>& columns) const
|
||||
|
@ -599,7 +592,7 @@ namespace mamba
|
|||
}
|
||||
|
||||
std::vector<mamba::printers::FormattedString> headers;
|
||||
std::vector<std::string_view> cmds, args;
|
||||
std::vector<std::string> cmds, args;
|
||||
std::vector<mamba::printers::alignment> alignments;
|
||||
for (auto& col : columns)
|
||||
{
|
||||
|
@ -621,7 +614,7 @@ namespace mamba
|
|||
else if (col.find_first_of(":") == col.npos)
|
||||
{
|
||||
headers.emplace_back(col);
|
||||
cmds.push_back(col);
|
||||
cmds.push_back(std::string(col));
|
||||
args.emplace_back("");
|
||||
}
|
||||
else
|
||||
|
@ -670,14 +663,18 @@ namespace mamba
|
|||
}
|
||||
else if (cmd == "Subdir")
|
||||
{
|
||||
row.emplace_back(get_subdir(pkg.channel));
|
||||
row.emplace_back(pkg.platform);
|
||||
}
|
||||
else if (cmd == "Depends")
|
||||
{
|
||||
std::string depends_qualifier;
|
||||
for (const auto& dep : pkg.dependencies)
|
||||
{
|
||||
if (util::starts_with(dep, args[i]))
|
||||
// `args[i]` can be just `spec`, `spec=version`,
|
||||
// or `spec` with some other constraints.
|
||||
// Note: The condition below may be subject to modification if
|
||||
// other use cases come up in the future
|
||||
if (util::starts_with(dep, args[i]) || util::starts_with(args[i], dep))
|
||||
{
|
||||
depends_qualifier = dep;
|
||||
break;
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
import os
|
||||
import platform
|
||||
import random
|
||||
import re
|
||||
import shutil
|
||||
import string
|
||||
import subprocess
|
||||
|
@ -72,6 +73,11 @@ def random_string(n: int = 10) -> str:
|
|||
return "".join(random.choices(string.ascii_uppercase + string.digits, k=n))
|
||||
|
||||
|
||||
def remove_whitespaces(s: str) -> str:
|
||||
"""Return the input string with extra whitespaces removed."""
|
||||
return re.sub(r"\s+", " ", s).strip()
|
||||
|
||||
|
||||
def shell(*args, cwd=os.getcwd(), **kwargs):
|
||||
umamba = get_umamba(cwd=cwd)
|
||||
cmd = [umamba, "shell"] + [arg for arg in args if arg]
|
||||
|
|
|
@ -146,15 +146,9 @@ def test_whoneeds_remote(yaml_env: Path):
|
|||
def test_whoneeds_not_installed_with_channel(yaml_env: Path, with_platform):
|
||||
if with_platform:
|
||||
res = helpers.umamba_repoquery(
|
||||
"whoneeds",
|
||||
"-c",
|
||||
"conda-forge",
|
||||
"xtensor=0.24.5",
|
||||
"--platform",
|
||||
"osx-64",
|
||||
"--json",
|
||||
"whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--platform", "osx-64", "--json"
|
||||
)
|
||||
assert res["result"]["pkgs"][0]["subdir"] == "osx-64"
|
||||
assert all("osx-64" in pkg["subdir"] for pkg in res["result"]["pkgs"])
|
||||
else:
|
||||
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--json")
|
||||
|
||||
|
@ -168,6 +162,16 @@ def test_whoneeds_not_installed_with_channel(yaml_env: Path, with_platform):
|
|||
assert any(x["name"] == "qpot" for x in pkgs)
|
||||
|
||||
|
||||
# Non-regression test for: https://github.com/mamba-org/mamba/issues/3717
|
||||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
||||
@pytest.mark.parametrize("spec", ("xtensor", "xtensor=0.24.5"))
|
||||
def test_whoneeds_not_installed_with_channel_no_json(yaml_env: Path, spec):
|
||||
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", spec, "--platform", "osx-64")
|
||||
res = helpers.remove_whitespaces(res)
|
||||
assert "Name Version Build Depends Channel Subdir" in res
|
||||
assert "cascade 0.1.1 py38h5ce3968_0 xtensor conda-forge osx-64" in res
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
||||
def test_whoneeds_tree(yaml_env: Path):
|
||||
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--tree")
|
||||
|
|
Loading…
Reference in New Issue