Skip to content

feat: add Graphviz DOT output writer - #658

Open
stark256-spec wants to merge 1 commit into
llnl:mainfrom
stark256-spec:feat/dot-output-writer
Open

feat: add Graphviz DOT output writer#658
stark256-spec wants to merge 1 commit into
llnl:mainfrom
stark256-spec:feat/dot-output-writer

Conversation

@stark256-spec

Copy link
Copy Markdown

Summary

If merged this pull request will add a Graphviz DOT output writer, so an SBOM can be exported as a graph showing how files tie together.

Closes #71.

Proposed changes

  • New surfactant/output/dot_writer.py implementing the write_sbom hook with short name dot. It emits a digraph:
    • one node per software entry, labeled with its file name (falling back to a recorded name, then the UUID, so every node is labeled);
    • one directed edge per logical relationship, labeled with the relationship type.
  • Edge selection mirrors the logical-relationship filtering already used when writing relationships to the SBOM JSON (to_dict_override): symlink edges and any edge touching a filesystem path node are skipped, so the graph reflects software relationships rather than the filesystem tree. Node/edge IDs and labels are escaped for DOT.
  • Registered the writer with the internal plugin manager.
  • Added tests/output/test_dot_writer.py covering node/edge emission, the UUID label fallback, and empty SBOMs.

Usage:

surfactant generate <config> <sbom.dot> --output_format surfactant.output.dot_writer

then e.g. dot -Tsvg sbom.dot -o sbom.svg.

Testing

  • pytest tests/output/test_dot_writer.py — 4 passed.
  • pytest tests/cmd/test_plugin.py — plugin registration still passes with the new writer.
  • Rendered a sample SBOM (tests/data/sample_sboms/helics_binaries_sbom.json) through the plugin manager: valid digraph with 6 nodes and 5 edges.
  • ruff check and ruff format --check clean.

Notes

@theStache mentioned back in 2023 that they were looking at a .DOT output; I did not find a PR for it, so I picked this up. Happy to adjust the node/edge styling or labeling if maintainers prefer a different convention.

Add a write_sbom plugin (short name 'dot') that renders the SBOM as a
Graphviz DOT digraph: each software entry becomes a node labeled with
its file name (falling back to a recorded name, then its UUID), and each
logical relationship becomes a directed edge labeled with the
relationship type.

Edge selection mirrors the logical-relationship filtering used when
writing relationships to the SBOM JSON: symlink edges and edges touching
filesystem path nodes are omitted, so the graph reflects software
relationships rather than the filesystem tree.

Registers the writer with the internal plugin manager and adds unit
tests covering node/edge emission, the UUID label fallback, and empty
SBOMs.

Closes llnl#71

Signed-off-by: stark256-spec <stark256-spec@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

✅ No SBOM Changes Detected

For commit 3302785 (Run 31562187067)
Compared against commit cfbaf38 (Run 31030106339)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add output writer for Graphviz DOT format

1 participant