Skip to content

Commit 56fd602

Browse files
fholgerarmintaenzertng
authored andcommitted
Address review comments
Signed-off-by: Holger Frydrych <[email protected]>
1 parent 70b54e0 commit 56fd602

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

examples/spdx2_convert_format.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# SPDX-License-Identifier: Apache-2.0
44
from os import path
55

6+
from spdx_tools.spdx.model import Document
67
from spdx_tools.spdx.writer.write_anything import write_file
78
from spdx_tools.spdx.parser.parse_anything import parse_file
89

910
# This example demonstrates how to load an existing SPDX2 file and convert it to a different SPDX2 format
1011

11-
# Provide a path to the input file in tagvalue format
12+
# Provide a path to the input file in the originating format
1213
input_path = path.join(path.dirname(__file__), "..", "tests", "spdx", "data", "SPDXLite.spdx")
13-
# Parse the original input file
14-
document = parse_file(input_path)
15-
# Write to XML file format
14+
# Parse the original input file (format is deduced automatically from the file extension)
15+
document: Document = parse_file(input_path)
16+
# Write to a different file format (e.g. XML, format is deduced automatically from the file extension)
1617
write_file(document, "converted_format.xml")

examples/spdx2_convert_to_spdx3.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
# SPDX-License-Identifier: Apache-2.0
44
from os import path
55

6+
from spdx_tools.spdx.model import Document
7+
from spdx_tools.spdx3.payload import Payload
68
from spdx_tools.spdx3.writer.json_ld.json_ld_writer import write_payload
7-
89
from spdx_tools.spdx3.bump_from_spdx2.spdx_document import bump_spdx_document
9-
1010
from spdx_tools.spdx.parser.parse_anything import parse_file
1111

1212
# This example demonstrates how to load an existing SPDX2 file and convert it to the SPDX3 format
1313

1414
# Provide a path to the input file
1515
input_path = path.join(path.dirname(__file__), "..", "tests", "spdx", "data", "SPDXLite.spdx")
1616
# Parse the original SPDX2 input file
17-
spdx2_document = parse_file(input_path)
17+
spdx2_document: Document = parse_file(input_path)
1818
# Convert original document to an SPDX3 payload
19-
spdx3_payload = bump_spdx_document(spdx2_document)
19+
spdx3_payload: Payload = bump_spdx_document(spdx2_document)
2020
# Write SPDX3 payload in json-ld format
2121
write_payload(spdx3_payload, "spdx2_to_3")

examples/spdx2_generate_graph.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
from os import path
55

66
from spdx_tools.spdx.graph_generation import export_graph_from_document
7+
from spdx_tools.spdx.model import Document
78
from spdx_tools.spdx.parser.parse_anything import parse_file
89

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

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

examples/spdx2_parse_file.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
# Provide a path to the input file
1414
input_path = path.join(path.dirname(__file__), "..", "tests", "spdx", "data", "SPDXLite.spdx")
15-
document: Document
1615
try:
1716
# Try to parse the input file. If successful, returns a Document, otherwise raises an SPDXParsingError
18-
document = parse_file(input_path)
17+
document: Document = parse_file(input_path)
1918
except SPDXParsingError:
2019
logging.exception("Failed to parse spdx file")
2120

0 commit comments

Comments
 (0)