Skip to content

Commit 77f0e45

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 f1cc917 commit 77f0e45

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ requests==2.28.1
6464
saneyaml==0.5.2
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

setup-mini.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ install_requires =
103103
pymaven_patch >= 0.2.8
104104
requests >= 2.7.0
105105
saneyaml >= 0.5.2
106-
spdx_tools >= 0.7.0a3
106+
spdx_tools >= 0.7.0rc0, ==0.7.*
107107
text_unidecode >= 1.0
108108
toml >= 0.10.0
109109
urlpy

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ install_requires =
104104
python-frontmatter >= 1.0.0
105105
requests >= 2.7.0
106106
saneyaml >= 0.5.2
107-
spdx_tools >= 0.7.0a3
107+
spdx_tools >= 0.7.0rc0, ==0.7.*
108108
text_unidecode >= 1.0
109109
toml >= 0.10.0
110110
urlpy

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
@@ -281,9 +283,8 @@ def write_spdx(
281283
name = './' + file_data.get('path')
282284
file_entry = File(
283285
spdx_id=f'SPDXRef-{sid}',
284-
name=name,
285-
chk_sum=Algorithm('SHA1', file_data.get('sha1') or '')
286-
)
286+
name=name)
287+
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, file_data.get('sha1') or ''))
287288

288289
file_license_detections = file_data.get('license_detections')
289290
license_matches = get_matches_from_detection_mappings(file_license_detections)
@@ -362,9 +363,11 @@ def write_spdx(
362363
else:
363364
file_entry.copyright = SPDXNone()
364365

365-
package.add_file(file_entry)
366+
doc.add_file(file_entry)
367+
relationship = Relationship(package.spdx_id + " CONTAINS " + file_entry.spdx_id)
368+
doc.add_relationship(relationship)
366369

367-
if len(package.files) == 0:
370+
if len(doc.files) == 0:
368371
if as_tagvalue:
369372
msg = "# No results for package '{}'.\n".format(package.name)
370373
else:
@@ -397,7 +400,7 @@ def write_spdx(
397400
# statements for the package.
398401
package.cr_text = '\n'.join(sorted(package.cr_text)) + '\n'
399402

400-
package.verif_code = doc.package.calc_verif_code()
403+
package.verif_code = calc_verif_code(doc.files)
401404
package.license_declared = NoAssert()
402405
package.conc_lics = NoAssert()
403406

@@ -409,7 +412,7 @@ def write_spdx(
409412
# one case we do need to deal with bytes and decode before writing (rdf) and
410413
# in the other case we deal with text all the way.
411414

412-
if package.files:
415+
if doc.files:
413416

414417
if as_tagvalue:
415418
from spdx.writers.tagvalue import write_document # NOQA

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

0 commit comments

Comments
 (0)