Skip to content

Commit b6ff6a0

Browse files
committed
Adopt SPDX v2.2 and fix SPDX TV correctness
This is using the SPDX 2.2 version and adding missing SPDX ids at the document and file levels. Also adds LicenseListVersion Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent a83666a commit b6ff6a0

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ saneyaml==0.5.2
6666
six==1.16.0
6767
sortedcontainers==2.4.0
6868
soupsieve==2.2.1
69-
spdx-tools==0.6.1
69+
spdx-tools==0.7.0a3
7070
text-unidecode==1.3
7171
toml==0.10.2
7272
typecode==21.6.1

setup-mini.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ install_requires =
9393
pymaven_patch >= 0.2.8
9494
requests >= 2.7.0, < 3.0.0
9595
saneyaml >= 0.5.2
96-
spdx_tools >= 0.6.0
96+
spdx_tools >= 0.7.0a3
9797
text_unidecode >= 1.0, < 2.0
9898
toml >= 0.10.0
9999
typing >=3.6, < 3.7; python_version < "3.7"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ install_requires =
9393
pymaven_patch >= 0.2.8
9494
requests >= 2.7.0, < 3.0.0
9595
saneyaml >= 0.5.2
96-
spdx_tools >= 0.6.0
96+
spdx_tools >= 0.7.0a3
9797
text_unidecode >= 1.0, < 2.0
9898
toml >= 0.10.0
9999
typing >=3.6, < 3.7; python_version < "3.7"

src/formattedcode/output_spdx.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ def write_spdx(
215215
package_name='',
216216
download_location=NoAssert(),
217217
as_tagvalue=True,
218+
spdx_version = (2, 2),
219+
with_notice_text=False,
218220
):
219221
"""
220222
Write scan output as SPDX Tag/value to ``output_file`` file-like
@@ -231,19 +233,25 @@ def write_spdx(
231233

232234
ns_prefix = '_'.join(package_name.lower().split())
233235
comment = notice + f'\nSPDX License List: {scancode_config.spdx_license_list_version}'
236+
234237
doc = Document(
235-
version=Version(2, 1),
238+
version=Version(*spdx_version),
236239
data_license=License.from_identifier('CC0-1.0'),
237240
comment=notice,
238241
namespace=f'http://spdx.org/spdxdocs/{ns_prefix}-{uuid.uuid4()}',
242+
license_list_version=scancode_config.spdx_license_list_version,
243+
name='SPDX Document created by ScanCode Toolkit'
239244
)
245+
240246
tool_name = tool_name or 'ScanCode'
241247
doc.creation_info.add_creator(Tool(f'{tool_name} {tool_version}'))
242248
doc.creation_info.set_created_now()
243249

250+
package_id = '001'
244251
package = doc.package = Package(
245252
name=package_name,
246-
download_location=download_location
253+
download_location=download_location,
254+
spdx_id=f'SPDXRef-{package_id}',
247255
)
248256

249257
# Use a set of unique copyrights for the package.
@@ -253,7 +261,7 @@ def write_spdx(
253261
all_files_have_no_copyright = True
254262

255263
# FIXME: this should walk the codebase instead!!!
256-
for file_data in files:
264+
for sid, file_data in enumerate(files, 1):
257265

258266
# Skip directories.
259267
if file_data.get('type') != 'file':
@@ -263,6 +271,7 @@ def write_spdx(
263271
# SPDX output (with explicit leading './').
264272
name = './' + file_data.get('path')
265273
file_entry = File(
274+
spdx_id=f'SPDXRef-{sid}',
266275
name=name,
267276
chk_sum=Algorithm('SHA1', file_data.get('sha1') or '')
268277
)

tests/formattedcode/data/spdx/simple/expected.rdf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"rdf:RDF": {
33
"ns1:SpdxDocument": {
4+
"ns1:name": {
5+
"@rdf:resource": "SPDX Document created by ScanCode Toolkit"
6+
},
47
"ns1:dataLicense": {
58
"@rdf:resource": "http://spdx.org/licenses/CC0-1.0"
69
},
@@ -22,11 +25,14 @@
2225
}
2326
},
2427
"ns1:fileName": "./test.txt",
25-
"@rdf:about": "http://www.spdx.org/files#None"
28+
"@rdf:about": "http://www.spdx.org/files#SPDXRef-1"
2629
}
2730
},
2831
"ns1:describesPackage": {
2932
"ns1:Package": {
33+
"ns1:Package": {
34+
"@rdf:resource": "SPDXRef-001"
35+
},
3036
"ns1:downloadLocation": {
3137
"@rdf:resource": "http://spdx.org/rdf/terms#noassertion"
3238
},
@@ -43,14 +49,14 @@
4349
"@rdf:resource": "http://spdx.org/rdf/terms#none"
4450
},
4551
"ns1:hasFile": {
46-
"@rdf:resource": "http://www.spdx.org/files#None"
52+
"@rdf:resource": "http://www.spdx.org/files#SPDXRef-1"
4753
},
4854
"@rdf:about": "http://www.spdx.org/tools#SPDXRef-Package",
4955
"ns1:name": "simple"
5056
}
5157
},
5258
"@rdf:about": "http://www.spdx.org/tools#SPDXRef-DOCUMENT",
53-
"ns1:specVersion": "SPDX-2.1"
59+
"ns1:specVersion": "SPDX-2.2"
5460
},
5561
"@xmlns:ns1": "http://spdx.org/rdf/terms#",
5662
"@xmlns:rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

tests/formattedcode/data/spdx/simple/expected.tv

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Document Information
2-
SPDXVersion: SPDX-2.1
2+
SPDXVersion: SPDX-2.2
33
DataLicense: CC0-1.0
4-
SPDXID: SPDXRef-DOCUMENT
54
DocumentNamespace: http://spdx.org/spdxdocs/simple
5+
DocumentName: SPDX Document created by ScanCode Toolkit
6+
LicenseListVersion: 3.14
7+
SPDXID: SPDXRef-DOCUMENT
68
DocumentComment: <text>Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
79
OR CONDITIONS OF ANY KIND, either express or implied. No content created from
810
ScanCode should be considered or used as legal advice. Consult an Attorney
@@ -12,6 +14,7 @@ Visit https://github.com/nexB/scancode-toolkit/ for support and download.</text>
1214
# Creation Info
1315
# Package
1416
PackageName: simple
17+
SPDXID: SPDXRef-001
1518
PackageDownloadLocation: NOASSERTION
1619
PackageVerificationCode: a83523bcfc10441aa94a575b88aa1d3269902485
1720
PackageLicenseDeclared: NOASSERTION
@@ -20,6 +23,7 @@ PackageLicenseInfoFromFiles: NONE
2023
PackageCopyrightText: NONE
2124
# File
2225
FileName: ./test.txt
26+
SPDXID: SPDXRef-1
2327
FileChecksum: SHA1: b8a793cce3c3a4cd3a4646ddbe86edd542ed0cd8
2428
LicenseConcluded: NOASSERTION
2529
LicenseInfoInFile: NONE

0 commit comments

Comments
 (0)