Skip to content

Commit 279e095

Browse files
fholgerarmintaenzertng
authored andcommitted
Add example for converting SPDX 2 to 3
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
1 parent 2330f4a commit 279e095

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

examples/spdx2_convert_to_spdx3.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2023 spdx contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from os import path
5+
6+
from spdx_tools.spdx3.writer.json_ld.json_ld_writer import write_payload
7+
8+
from spdx_tools.spdx3.bump_from_spdx2.spdx_document import bump_spdx_document
9+
10+
from spdx_tools.spdx.parser.parse_anything import parse_file
11+
12+
# This example demonstrates how to load an existing SPDX2 file and convert it to the SPDX3 format
13+
14+
# Provide a path to the input file
15+
input_path = path.join(path.dirname(__file__), "..", "tests", "spdx", "data", "SPDXLite.spdx")
16+
# Parse the original SPDX2 input file
17+
spdx2_document = parse_file(input_path)
18+
# Convert original document to an SPDX3 payload
19+
spdx3_payload = bump_spdx_document(spdx2_document)
20+
# Write SPDX3 payload in json-ld format
21+
write_payload(spdx3_payload, "spdx2_to_3.json")

0 commit comments

Comments
 (0)