Skip to content

Commit d89ab65

Browse files
committed
adapt code to new spdx-tools release
With the new release, the checksum class has been renamed, the license class has been moved to its own file, and files are now only allowed at document level. Signed-off-by: Meret Behrens <[email protected]>
1 parent cc14890 commit d89ab65

File tree

9 files changed

+21
-23
lines changed

9 files changed

+21
-23
lines changed

Diff for: requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ requests==2.28.1
6464
saneyaml==0.6.0
6565
six==1.16.0
6666
soupsieve==2.3.2.post1
67-
spdx-tools==0.7.0a3
67+
spdx-tools==0.7.0rc0
6868
text-unidecode==1.3
6969
toml==0.10.2
7070
typecode==30.0.0

Diff for: setup-mini.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ install_requires =
8080
gemfileparser2 >= 0.9.0
8181
html5lib
8282
importlib_metadata
83-
intbitset >= 3.0.2
83+
intbitset >= 3.0.2
8484
jaraco.functools
8585
javaproperties >= 0.5
8686
jinja2 >= 2.7.0
@@ -105,7 +105,7 @@ install_requires =
105105
pymaven_patch >= 0.2.8
106106
requests >= 2.7.0
107107
saneyaml >= 0.6.0
108-
spdx_tools == 0.7.0a3
108+
spdx_tools == 0.7.0rc0, ==0.7.*
109109
text_unidecode >= 1.0
110110
toml >= 0.10.0
111111
urlpy

Diff for: setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ install_requires =
105105
pymaven_patch >= 0.2.8
106106
requests >= 2.7.0
107107
saneyaml >= 0.6.0
108-
spdx_tools == 0.7.0a3
108+
spdx_tools == 0.7.0rc0, ==0.7.*
109109
text_unidecode >= 1.0
110110
toml >= 0.10.0
111111
urlpy

Diff for: src/formattedcode/output_spdx.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
from io import BytesIO
1313
from io import StringIO
1414

15-
from spdx.checksum import Algorithm
15+
from spdx.checksum import Checksum, ChecksumAlgorithm
1616
from spdx.creationinfo import Tool
1717
from spdx.document import ExtractedLicense
1818
from spdx.document import Document
19-
from spdx.document import License
19+
from spdx.license import License
2020
from spdx.file import File
2121
from spdx.package import Package
22+
from spdx.relationship import Relationship
23+
from spdx.utils import calc_verif_code
2224
from spdx.utils import NoAssert
2325
from spdx.utils import SPDXNone
2426
from spdx.version import Version
@@ -280,9 +282,8 @@ def write_spdx(
280282
name = './' + file_data.get('path')
281283
file_entry = File(
282284
spdx_id=f'SPDXRef-{sid}',
283-
name=name,
284-
chk_sum=Algorithm('SHA1', file_data.get('sha1') or '')
285-
)
285+
name=name)
286+
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, file_data.get('sha1') or ''))
286287

287288
file_license_detections = file_data.get('license_detections')
288289
license_matches = get_matches_from_detection_mappings(file_license_detections)
@@ -357,9 +358,11 @@ def write_spdx(
357358
else:
358359
file_entry.copyright = SPDXNone()
359360

360-
package.add_file(file_entry)
361+
doc.add_file(file_entry)
362+
relationship = Relationship(package.spdx_id + " CONTAINS " + file_entry.spdx_id)
363+
doc.add_relationship(relationship)
361364

362-
if len(package.files) == 0:
365+
if len(doc.files) == 0:
363366
if as_tagvalue:
364367
msg = "# No results for package '{}'.\n".format(package.name)
365368
else:
@@ -392,7 +395,7 @@ def write_spdx(
392395
# statements for the package.
393396
package.cr_text = '\n'.join(sorted(package.cr_text)) + '\n'
394397

395-
package.verif_code = doc.package.calc_verif_code()
398+
package.verif_code = calc_verif_code(doc.files)
396399
package.license_declared = NoAssert()
397400
package.conc_lics = NoAssert()
398401

@@ -404,7 +407,7 @@ def write_spdx(
404407
# one case we do need to deal with bytes and decode before writing (rdf) and
405408
# in the other case we deal with text all the way.
406409

407-
if package.files:
410+
if doc.files:
408411

409412
if as_tagvalue:
410413
from spdx.writers.tagvalue import write_document # NOQA

Diff for: tests/formattedcode/data/spdx/license_known/expected.tv

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ SPDXID: SPDXRef-3
3535
FileChecksum: SHA1: 172444e7c137eb5cd3cae530aca0879c90f7fada
3636
LicenseConcluded: NOASSERTION
3737
LicenseInfoInFile: CC0-1.0
38-
FileCopyrightText: NONE
39-
# Extracted Licenses
38+
FileCopyrightText: NONE

Diff for: tests/formattedcode/data/spdx/license_known/expected_with_text.tv

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ SPDXID: SPDXRef-3
3535
FileChecksum: SHA1: 172444e7c137eb5cd3cae530aca0879c90f7fada
3636
LicenseConcluded: NOASSERTION
3737
LicenseInfoInFile: CC0-1.0
38-
FileCopyrightText: NONE
39-
# Extracted Licenses
38+
FileCopyrightText: NONE

Diff for: tests/formattedcode/data/spdx/simple/expected.tv

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ SPDXID: SPDXRef-1
2727
FileChecksum: SHA1: b8a793cce3c3a4cd3a4646ddbe86edd542ed0cd8
2828
LicenseConcluded: NOASSERTION
2929
LicenseInfoInFile: NONE
30-
FileCopyrightText: NONE
31-
# Extracted Licenses
30+
FileCopyrightText: NONE

Diff for: tests/formattedcode/data/spdx/tree/expected.tv

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,4 @@ FileChecksum: SHA1: 58748872d25374160692f1ed7075d0fe80a544b1
7777
LicenseConcluded: NOASSERTION
7878
LicenseInfoInFile: NONE
7979
FileCopyrightText: <text>Copyright (c) 2000 ACME, Inc.
80-
</text>
81-
# Extracted Licenses
80+
</text>

Diff for: tests/formattedcode/data/templated/tree/expected.tv

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,4 @@ FileChecksum: SHA1: 58748872d25374160692f1ed7075d0fe80a544b1
6565
LicenseConcluded: NOASSERTION
6666
LicenseInfoInFile: NONE
6767
FileCopyrightText: <text>Copyright (c) 2000 ACME, Inc.
68-
</text>
69-
# Extracted Licenses
68+
</text>

0 commit comments

Comments
 (0)