Skip to content

Commit caec256

Browse files
authored
Merge pull request #3173 from meretp/python_tools_release
adapt code to new spdx-tools release
2 parents 3722dd1 + 4677510 commit caec256

File tree

10 files changed

+24
-23
lines changed

10 files changed

+24
-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
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
109109
text_unidecode >= 1.0
110110
toml >= 0.10.0
111111
urlpy

Diff for: src/formattedcode/output_spdx.py

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

15-
from spdx.checksum import Algorithm
15+
from spdx.checksum import Checksum
16+
from spdx.checksum import ChecksumAlgorithm
1617
from spdx.creationinfo import Tool
1718
from spdx.document import ExtractedLicense
1819
from spdx.document import Document
19-
from spdx.document import License
20+
from spdx.license import License
2021
from spdx.file import File
2122
from spdx.package import Package
23+
from spdx.relationship import Relationship
24+
from spdx.utils import calc_verif_code
2225
from spdx.utils import NoAssert
2326
from spdx.utils import SPDXNone
2427
from spdx.version import Version
@@ -280,9 +283,8 @@ def write_spdx(
280283
name = './' + file_data.get('path')
281284
file_entry = File(
282285
spdx_id=f'SPDXRef-{sid}',
283-
name=name,
284-
chk_sum=Algorithm('SHA1', file_data.get('sha1') or '')
285-
)
286+
name=name)
287+
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, file_data.get('sha1') or ''))
286288

287289
file_license_detections = file_data.get('license_detections')
288290
license_matches = get_matches_from_detection_mappings(file_license_detections)
@@ -357,9 +359,11 @@ def write_spdx(
357359
else:
358360
file_entry.copyright = SPDXNone()
359361

360-
package.add_file(file_entry)
362+
doc.add_file(file_entry)
363+
relationship = Relationship(f'{package.spdx_id} CONTAINS {file_entry.spdx_id}')
364+
doc.add_relationship(relationship)
361365

362-
if len(package.files) == 0:
366+
if not doc.files:
363367
if as_tagvalue:
364368
msg = "# No results for package '{}'.\n".format(package.name)
365369
else:
@@ -392,7 +396,7 @@ def write_spdx(
392396
# statements for the package.
393397
package.cr_text = '\n'.join(sorted(package.cr_text)) + '\n'
394398

395-
package.verif_code = doc.package.calc_verif_code()
399+
package.verif_code = calc_verif_code(doc.files)
396400
package.license_declared = NoAssert()
397401
package.conc_lics = NoAssert()
398402

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

407-
if package.files:
411+
if doc.files:
408412

409413
if as_tagvalue:
410414
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>

Diff for: tests/formattedcode/test_output_spdx.py

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ def load_and_clean_tv(location):
149149
line = line.strip()
150150
if not line:
151151
continue
152+
if line.startswith('LicenseListVersion'):
153+
continue
152154
if line.startswith(('Creator: ', 'Created: ',)):
153155
continue
154156
if line.startswith(dns):

0 commit comments

Comments
 (0)