Skip to content

Commit ffed30e

Browse files
committed
scripts: west_commands: zspdx: writer: Fix linter issues
Fix issues reported by ruff. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
1 parent a98e750 commit ffed30e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,6 @@
12321232
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
12331233
"UP032", # https://docs.astral.sh/ruff/rules/f-string
12341234
]
1235-
"./scripts/west_commands/zspdx/writer.py" = [
1236-
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
1237-
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
1238-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
1239-
]
12401235
"./scripts/zephyr_module.py" = [
12411236
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
12421237
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports

scripts/west_commands/zspdx/writer.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import re
56
from datetime import datetime
67

78
from west import log
89

910
from zspdx.util import getHashes
1011

11-
import re
12-
1312
CPE23TYPE_REGEX = (
1413
r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^'
1514
r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*"
@@ -26,7 +25,10 @@ def _normalize_spdx_name(name):
2625
# 1) f: file handle for SPDX document
2726
# 2) rln: Relationship object being described
2827
def writeRelationshipSPDX(f, rln):
29-
f.write(f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} {_normalize_spdx_name(rln.refB)}\n")
28+
f.write(
29+
f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} "
30+
f"{_normalize_spdx_name(rln.refB)}\n"
31+
)
3032

3133
# Output tag-value SPDX 2.3 content for the given File object.
3234
# Arguments:
@@ -45,7 +47,7 @@ def writeFileSPDX(f, bf):
4547
f.write(f"FileChecksum: MD5: {bf.md5}\n")
4648
f.write(f"LicenseConcluded: {bf.concludedLicense}\n")
4749
if len(bf.licenseInfoInFile) == 0:
48-
f.write(f"LicenseInfoInFile: NONE\n")
50+
f.write("LicenseInfoInFile: NONE\n")
4951
else:
5052
for licInfoInFile in bf.licenseInfoInFile:
5153
f.write(f"LicenseInfoInFile: {licInfoInFile}\n")
@@ -111,10 +113,10 @@ def writePackageSPDX(f, pkg):
111113
for licFromFiles in pkg.licenseInfoFromFiles:
112114
f.write(f"PackageLicenseInfoFromFiles: {licFromFiles}\n")
113115
else:
114-
f.write(f"PackageLicenseInfoFromFiles: NOASSERTION\n")
116+
f.write("PackageLicenseInfoFromFiles: NOASSERTION\n")
115117
f.write(f"FilesAnalyzed: true\nPackageVerificationCode: {pkg.verificationCode}\n\n")
116118
else:
117-
f.write(f"FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n")
119+
f.write("FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n")
118120

119121
# write package relationships
120122
if len(pkg.rlns) > 0:
@@ -162,14 +164,17 @@ def writeDocumentSPDX(f, doc):
162164
extDocs = list(doc.externalDocuments)
163165
extDocs.sort(key = lambda x: x.cfg.docRefID)
164166
for extDoc in extDocs:
165-
f.write(f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} SHA1: {extDoc.myDocSHA1}\n")
166-
f.write(f"\n")
167+
f.write(
168+
f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} "
169+
f"SHA1: {extDoc.myDocSHA1}\n"
170+
)
171+
f.write("\n")
167172

168173
# write relationships owned by this Document (not by its Packages, etc.), if any
169174
if len(doc.relationships) > 0:
170175
for rln in doc.relationships:
171176
writeRelationshipSPDX(f, rln)
172-
f.write(f"\n")
177+
f.write("\n")
173178

174179
# write packages
175180
for pkg in doc.pkgs.values():
@@ -198,7 +203,7 @@ def writeSPDX(spdxPath, doc):
198203
# calculate hash of the document we just wrote
199204
hashes = getHashes(spdxPath)
200205
if not hashes:
201-
log.err(f"Error: created document but unable to calculate hash values")
206+
log.err("Error: created document but unable to calculate hash values")
202207
return False
203208
doc.myDocSHA1 = hashes[0]
204209

0 commit comments

Comments
 (0)