Skip to content

Commit 6fa577c

Browse files
TG1999pombredanne
andcommitted
Address review comments
Co-authored-by: Philippe Ombredanne <pombredanne@nexb.com> Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent fa6ed0d commit 6fa577c

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/python_inspector/resolution.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def pdt_dfs(mapping, graph, src):
632632
Return a nested mapping of dependencies.
633633
634634
This takes ``mapping`` and ``graph`` as input. And do a dfs
635+
(aka. depth-first search see https://en.wikipedia.org/wiki/Depth-first_search)
635636
on the ``graph`` to get the dependencies of the given ``src``.
636637
And use the ``mapping`` to get the version of the given dependency.
637638
"""
@@ -640,18 +641,20 @@ def pdt_dfs(mapping, graph, src):
640641
return dict(
641642
key=src, package_name=src, installed_version=str(mapping[src].version), dependencies=[]
642643
)
643-
644+
# recurse
645+
dependencies = [pdt_dfs(mapping, graph, c) for c in children]
646+
dependencies.sort(key=lambda d: d["key"])
644647
return dict(
645648
key=src,
646649
package_name=src,
647650
installed_version=str(mapping[src].version),
648-
dependencies=sorted([pdt_dfs(mapping, graph, c) for c in children], key=lambda d: d["key"]),
651+
dependencies=dependencies,
649652
)
650653

651654

652655
def format_pdt_tree(results):
653656
"""
654-
Return a formatted tree of dependencies.
657+
Return a formatted tree of dependencies in the style of pipdeptree.
655658
"""
656659
mapping = results.mapping
657660
graph = results.graph

src/python_inspector/resolve_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
type=FileOptionType(mode="w", encoding="utf-8", lazy=True),
111111
required=False,
112112
metavar="FILE",
113-
help="Write output as pretty-printed JSON to FILE. "
113+
help="Write output as pretty-printed JSON to FILE as a tree in the style of pipdeptree. "
114114
"Use the special '-' file name to print results on screen/stdout.",
115115
)
116116
@click.option(
@@ -328,7 +328,6 @@ def resolve(
328328
pdt_output=pdt_output,
329329
)
330330

331-
print(resolved_dependencies)
332331

333332
initial_requirements = [d.to_dict() for d in direct_dependencies]
334333

0 commit comments

Comments
 (0)