Skip to content

feat(graph): add --dependencies-only and --dependents-only flags to graph subset#1253

Merged
mergify[bot] merged 2 commits into
python-wheel-build:mainfrom
dhellmann:graph-subset-dependencies-only
Jul 13, 2026
Merged

feat(graph): add --dependencies-only and --dependents-only flags to graph subset#1253
mergify[bot] merged 2 commits into
python-wheel-build:mainfrom
dhellmann:graph-subset-dependencies-only

Conversation

@dhellmann

Copy link
Copy Markdown
Member

Summary

  • Add --dependencies-only to graph subset: restricts output to the target package and its transitive dependencies, excluding any packages that depend on the target.
  • Add --dependents-only to graph subset: restricts output to the target package and its transitive dependents, excluding the target's own dependencies.
  • Using both flags together is an error.

Implementation notes

When --dependencies-only is active, ROOT is not reachable via the normal upward traversal, so:

  • ROOT is always added to the included node set to keep the graph rooted.
  • ROOT's original edges are suppressed during the edge-copy pass (to avoid spurious edges from other top-level packages that happen to be transitive deps of the target).
  • An artificial ROOT → target edge is added so the subset serializes correctly.

When --dependents-only is active, the upward traversal naturally reaches ROOT, so no special handling is needed.

Test plan

  • test_graph_subset_dependencies_only — target and its deps are included; dependents are not.
  • test_graph_subset_dependencies_only_no_dependents — confirms dependents absent vs full subset.
  • test_graph_subset_dependents_only — target and its dependents are included; target's deps are not.
  • test_graph_subset_dependents_only_and_dependencies_only_are_exclusive — combining both flags exits non-zero with a clear error message.

🤖 Generated with Claude Code

@dhellmann dhellmann requested a review from a team as a code owner July 13, 2026 13:22
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04f161bc-36ef-4aef-8f3a-4045937d438b

📥 Commits

Reviewing files that changed from the base of the PR and between 955c0d0 and fca6661.

📒 Files selected for processing (2)
  • src/fromager/commands/graph.py
  • tests/test_commands_graph.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_commands_graph.py
  • src/fromager/commands/graph.py

📝 Walkthrough

Walkthrough

The graph subset command adds mutually exclusive --dependencies-only and --dependents-only filters. Subset extraction adjusts traversal accordingly, always retains ROOT, and handles ROOT edges for dependency-only output. The subset graph builder can skip ROOT-originating edges, and CLI integration tests cover both modes and invalid combined usage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the main change: new dependencies-only and dependents-only flags for graph subset.
Description check ✅ Passed The description matches the implementation and tests, including the two flags, exclusivity, and ROOT handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify mergify Bot added the ci label Jul 13, 2026
@dhellmann

Copy link
Copy Markdown
Member Author

@rd4398 @LalatenduMohanty I had a need for this feature this morning to prep some data for an internal conversation.

@rd4398 rd4398 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!

@mergify

mergify Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@dhellmann

Copy link
Copy Markdown
Member Author

This looks good!

What's the process now for adding things to the merge queue? Do I click the button myself, for example?

@rd4398

rd4398 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@mergify rebase

@mergify

mergify Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

rebase

🛑 The pull request rule doesn't match anymore

Details

This action has been cancelled.

dhellmann and others added 2 commits July 13, 2026 18:50
Add a `--dependencies-only` flag to `graph subset` that restricts the
output to the target package and its transitive dependencies, omitting
packages that depend on the target.

When the flag is active, ROOT is always included to keep the graph
rooted, its original edges are not copied (to avoid spurious edges from
other top-level packages that happen to be transitive deps of the
target), and an artificial ROOT→target edge is added so the subset
serializes correctly.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Add a `--dependents-only` flag to `graph subset` that restricts the
output to the target package and its transitive dependents, omitting
the target's own dependencies.

Using both `--dependents-only` and `--dependencies-only` together is
an error.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
@rd4398 rd4398 force-pushed the graph-subset-dependencies-only branch from 955c0d0 to fca6661 Compare July 13, 2026 18:50
@mergify mergify Bot merged commit 5839f02 into python-wheel-build:main Jul 13, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants