Skip to content

feat(graph): add subset command to extract package-related subgraphs#915

Open
dhellmann wants to merge 2 commits intopython-wheel-build:mainfrom
dhellmann:graph-subset
Open

feat(graph): add subset command to extract package-related subgraphs#915
dhellmann wants to merge 2 commits intopython-wheel-build:mainfrom
dhellmann:graph-subset

Conversation

@dhellmann
Copy link
Member

Add new fromager graph subset command to extract a subset of a build graph containing only nodes related to a specific package.

Features:

  • Extracts dependencies and dependents of a target package
  • Optional version filtering with --version flag
  • Output to file or stdout
  • Comprehensive error handling for missing packages/versions
  • Full graph integrity preservation

Usage:

  • fromager graph subset graph.json package-name
  • fromager graph subset graph.json package-name --version 1.0.0
  • fromager graph subset graph.json package-name -o subset.json

🤖 Generated with Claude Code

@dhellmann dhellmann requested a review from a team as a code owner February 16, 2026 18:52
@mergify mergify bot added the ci label Feb 16, 2026
@dhellmann
Copy link
Member Author

I ended up needing this to extract some details about a much larger build.

@dhellmann
Copy link
Member Author

This is passing CI now and ready for review.

Copy link
Contributor

@rd4398 rd4398 left a comment

Choose a reason for hiding this comment

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

This looks good. I left one question but it is not a blocker for this MR

find_why(graph, node, depth, 0, requirement_type)


@graph.command()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add documentation for this new command?

Copy link
Member Author

Choose a reason for hiding this comment

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

The documentation for the CLI reference section is generated automatically, but I can add a how-to.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some additional docs.

for parent_edge in target_node.parents:
if parent_edge.destination_node.key == ROOT:
related_nodes.add(ROOT)
break
Copy link
Member

Choose a reason for hiding this comment

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

the code we have from line 555 to 560 is most likely dead code. Here is the analysis from a AI agent

The code is dead. By line 555, _collect_dependents (line 548) has already run. That function walks every ancestor of the target node all the way up to ROOT. ROOT is
always added to related_nodes because it's the ultimate ancestor of every node. We proved this empirically earlier:

_collect_dependents(pyyaml==6.0.2):
→ walks to imapautofiler==1.14.0
→ walks to ROOT ("")
→ ROOT.parents is empty, stops

So by the time execution reaches line 555, ROOT is already in related_nodes. The add() on line 559 is a no-op on a set that already contains the value.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll take a look through and see, thanks for catching that.

Add new `fromager graph subset` command to extract a subset of a build
graph containing only nodes related to a specific package.

Features:
- Extracts dependencies and dependents of a target package
- Optional version filtering with --version flag
- Output to file or stdout
- Comprehensive error handling for missing packages/versions
- Full graph integrity preservation

Usage:
- fromager graph subset graph.json package-name
- fromager graph subset graph.json package-name --version 1.0.0
- fromager graph subset graph.json package-name -o subset.json

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive documentation for the new `graph subset` command including:

- Updated graph commands overview to include subset command
- New dedicated tutorial with examples and use cases
- Integration with existing documentation structure via toctree
- CLI documentation auto-generates from command docstrings

The tutorial covers basic usage, version filtering, file output, common
use cases, and example workflows for debugging dependency issues.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
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.

3 participants