File: spdx2_generate_graph.py

package info (click to toggle)
python-spdx-tools 0.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,088 kB
  • sloc: python: 18,668; xml: 12,553; sh: 46; makefile: 6
file content (17 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#  SPDX-FileCopyrightText: 2023 spdx contributors
#
#  SPDX-License-Identifier: Apache-2.0
from os import path

from spdx_tools.spdx.graph_generation import export_graph_from_document
from spdx_tools.spdx.model import Document
from spdx_tools.spdx.parser.parse_anything import parse_file

# This example demonstrates how to generate a relationship graph for an SPDX2 document

# Provide a path to the input file
input_path = path.join(path.dirname(__file__), "..", "tests", "spdx", "data", "SPDXJSONExample-v2.3.spdx.json")
# Parse the file
document: Document = parse_file(input_path)
# Generate the graph (note: you need to have installed the optional dependencies networkx and pygraphviz)
export_graph_from_document(document, "graph.png")