Support --depth for graphviz output format#538
Conversation
The --depth option was only supported for text and freeze output formats. This change extends it to graphviz output as well, using BFS from root nodes to limit the depth of the rendered graph. Both forward and reverse graph modes support depth limiting. Fixes tox-dev#494 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
gaborbernat
left a comment
There was a problem hiding this comment.
Please run and fix the pre-ocmmit checks.
Add noqa comments for too-many-branches, too-many-statements, and too-many-nested-blocks in dump_graphviz. The function already has C901 suppressed; depth-limiting inherently adds branches to the graph rendering logic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Fixed — added All pre-commit checks pass locally. |
|
check / test (type) (pull_request) |
PackageDAG.__getitem__ returns list[ReqPackage] | None, so guard against None before iterating. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Fixed — the type check failure was a mypy |
- Extract _build_reverse_graph() and _build_forward_graph() helpers to reduce complexity of dump_graphviz() - Use tree.get_node_as_parent(key) for O(1) lookup instead of looping over all tree nodes in reverse BFS - Add tests for reverse mode with finite depth and infinite depth Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed all review items:
All tests pass (the test_local_only failure is pre-existing — virtualenv path issue on the test environment). |
pre-commit.ci - pr — checks completed with failures Please always check this passes before you say any PR is ready. |
Simplifies the parent lookup in the reverse depth-limited BFS by using tree.get_children(), consistent with the forward graph builder. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Good catch — switched to |
The BFS traversal + graph construction logic requires branching that exceeds ruff's default limits. These are inherited from the original dump_graphviz function. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
All feedback addressed. Pre-commit.ci and all CI checks now pass. Ready for re-review. |
|
Hi @kemzeb — all your feedback from the latest review round is addressed:
All CI green. Ready for re-review when you have time. |
kemzeb
left a comment
There was a problem hiding this comment.
I believe this looks good
Summary
--depthsupport to graphviz output format (was text/freeze only)Details
The
--depthflag was explicitly limited to "text and freeze render only". This PR extends it to graphviz output by performing a BFS traversal from root nodes and only including nodes/edges within the specified depth.For forward mode, root nodes are packages that aren't dependencies of any other package. For reverse mode, root nodes are packages that aren't parents of any other package.
When
max_depthis infinite (the default), the original flat iteration is used unchanged for zero overhead.Fixes #494