Skip to content

Commit

Permalink
Fix print_linkages
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Nov 6, 2023
1 parent c24d662 commit bbaadc1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
63 changes: 37 additions & 26 deletions conda_build/inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,37 @@ def check_install(
return None


def print_linkages(depmap, show_files=False):
# Print system and not found last
dist_depmap = {}
for k, v in depmap.items():
if hasattr(k, "dist_name"):
k = k.dist_name
dist_depmap[k] = v

depmap = dist_depmap
k = sorted(set(depmap.keys()) - {"system", "not found"})
all_deps = k if "not found" not in depmap.keys() else k + ["system", "not found"]
def print_linkages(
depmap: dict[
PrefixRecord | Literal["not found" | "system" | "untracked"],
list[tuple[str, str, str]],
],
show_files: bool = False,
) -> str:
# print system, not found, and untracked last
sort_order = {
# PrefixRecord: (0, PrefixRecord.name),
"system": (1, "system"),
"not found": (2, "not found"),
"untracked": (3, "untracked"),
# str: (4, str),
}

output_string = ""
for dep in all_deps:
output_string += "%s:\n" % dep
for prec, links in sorted(
depmap.items(),
key=(
lambda key: (0, key[0].name)
if isinstance(key[0], PrefixRecord)
else sort_order.get(key[0], (4, key[0]))
),
):
output_string += "%s:\n" % prec
if show_files:
for lib, path, binary in sorted(depmap[dep]):
for lib, path, binary in sorted(links):
output_string += f" {lib} ({path}) from {binary}\n"
else:
for lib, path in sorted(set(map(itemgetter(0, 1), depmap[dep]))):
for lib, path in sorted(set(map(itemgetter(0, 1), links))):
output_string += f" {lib} ({path})\n"
output_string += "\n"
return output_string
Expand Down Expand Up @@ -278,8 +290,13 @@ def inspect_linkages(
if path not in {"", "not found"}
else path
)
if path.startswith(prefix):
precs = list(which_package(path, prefix))
try:
relative = str(Path(path).relative_to(prefix))
except ValueError:
# ValueError: path is not relative to prefix
relative = None
if relative:
precs = list(which_package(relative, prefix))
if len(precs) > 1:
get_logger(__name__).warn(
"Warning: %s comes from multiple packages: %s",
Expand All @@ -288,17 +305,11 @@ def inspect_linkages(
)
elif not precs:
if exists(path):
depmap["untracked"].append(
(lib, path.split(prefix + "/", 1)[-1], binary)
)
depmap["untracked"].append((lib, relative, binary))
else:
depmap["not found"].append(
(lib, path.split(prefix + "/", 1)[-1], binary)
)
depmap["not found"].append((lib, relative, binary))
for prec in precs:
depmap[prec].append(
(lib, path.split(prefix + "/", 1)[-1], binary)
)
depmap[prec].append((lib, relative, binary))
elif path == "not found":
depmap["not found"].append((lib, path, binary))
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_main_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_inspect_installable(testing_workdir):
def test_inspect_linkages(testing_workdir, capfd):
# get a package that has known object output
args = ["linkages", "python"]
if sys.platform == "win32":
if on_win:
with pytest.raises(SystemExit) as exc:
main_inspect.execute(args)
assert "conda inspect linkages is only implemented in Linux and OS X" in exc
Expand Down

0 comments on commit bbaadc1

Please sign in to comment.