Skip to content

Commit 4a69e30

Browse files
authored
Fix dependency and subdir in repoquery whoneeds (#3743)
1 parent 503f0aa commit 4a69e30

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

libmamba/src/core/query.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,6 @@ namespace mamba
581581
{
582582
return util::split(str, "/", 1).front(); // Has at least one element
583583
}
584-
585-
/** Get subdir from channel name. */
586-
auto get_subdir(std::string_view str) -> std::string
587-
{
588-
return util::split(str, "/").back();
589-
}
590-
591584
}
592585

593586
auto QueryResult::table(std::ostream& out, const std::vector<std::string_view>& columns) const
@@ -599,7 +592,7 @@ namespace mamba
599592
}
600593

601594
std::vector<mamba::printers::FormattedString> headers;
602-
std::vector<std::string_view> cmds, args;
595+
std::vector<std::string> cmds, args;
603596
std::vector<mamba::printers::alignment> alignments;
604597
for (auto& col : columns)
605598
{
@@ -621,7 +614,7 @@ namespace mamba
621614
else if (col.find_first_of(":") == col.npos)
622615
{
623616
headers.emplace_back(col);
624-
cmds.push_back(col);
617+
cmds.push_back(std::string(col));
625618
args.emplace_back("");
626619
}
627620
else
@@ -670,14 +663,18 @@ namespace mamba
670663
}
671664
else if (cmd == "Subdir")
672665
{
673-
row.emplace_back(get_subdir(pkg.channel));
666+
row.emplace_back(pkg.platform);
674667
}
675668
else if (cmd == "Depends")
676669
{
677670
std::string depends_qualifier;
678671
for (const auto& dep : pkg.dependencies)
679672
{
680-
if (util::starts_with(dep, args[i]))
673+
// `args[i]` can be just `spec`, `spec=version`,
674+
// or `spec` with some other constraints.
675+
// Note: The condition below may be subject to modification if
676+
// other use cases come up in the future
677+
if (util::starts_with(dep, args[i]) || util::starts_with(args[i], dep))
681678
{
682679
depends_qualifier = dep;
683680
break;

micromamba/tests/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import platform
55
import random
6+
import re
67
import shutil
78
import string
89
import subprocess
@@ -72,6 +73,11 @@ def random_string(n: int = 10) -> str:
7273
return "".join(random.choices(string.ascii_uppercase + string.digits, k=n))
7374

7475

76+
def remove_whitespaces(s: str) -> str:
77+
"""Return the input string with extra whitespaces removed."""
78+
return re.sub(r"\s+", " ", s).strip()
79+
80+
7581
def shell(*args, cwd=os.getcwd(), **kwargs):
7682
umamba = get_umamba(cwd=cwd)
7783
cmd = [umamba, "shell"] + [arg for arg in args if arg]

micromamba/tests/test_repoquery.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,9 @@ def test_whoneeds_remote(yaml_env: Path):
146146
def test_whoneeds_not_installed_with_channel(yaml_env: Path, with_platform):
147147
if with_platform:
148148
res = helpers.umamba_repoquery(
149-
"whoneeds",
150-
"-c",
151-
"conda-forge",
152-
"xtensor=0.24.5",
153-
"--platform",
154-
"osx-64",
155-
"--json",
149+
"whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--platform", "osx-64", "--json"
156150
)
157-
assert res["result"]["pkgs"][0]["subdir"] == "osx-64"
151+
assert all("osx-64" in pkg["subdir"] for pkg in res["result"]["pkgs"])
158152
else:
159153
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--json")
160154

@@ -168,6 +162,16 @@ def test_whoneeds_not_installed_with_channel(yaml_env: Path, with_platform):
168162
assert any(x["name"] == "qpot" for x in pkgs)
169163

170164

165+
# Non-regression test for: https://github.com/mamba-org/mamba/issues/3717
166+
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
167+
@pytest.mark.parametrize("spec", ("xtensor", "xtensor=0.24.5"))
168+
def test_whoneeds_not_installed_with_channel_no_json(yaml_env: Path, spec):
169+
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", spec, "--platform", "osx-64")
170+
res = helpers.remove_whitespaces(res)
171+
assert "Name Version Build Depends Channel Subdir" in res
172+
assert "cascade 0.1.1 py38h5ce3968_0 xtensor conda-forge osx-64" in res
173+
174+
171175
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
172176
def test_whoneeds_tree(yaml_env: Path):
173177
res = helpers.umamba_repoquery("whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--tree")

0 commit comments

Comments
 (0)