From 88d7715a298cb10eac0f79f6d6e86e838a26d646 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Sat, 24 May 2025 22:25:16 +0200 Subject: [PATCH] scripts: west_commands: zspdx: writer: Fix linter issues Fix issues reported by ruff. Signed-off-by: Pieter De Gendt --- .ruff-excludes.toml | 5 ----- scripts/west_commands/zspdx/writer.py | 25 +++++++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.ruff-excludes.toml b/.ruff-excludes.toml index a54dee955b7..e7d51e2294f 100644 --- a/.ruff-excludes.toml +++ b/.ruff-excludes.toml @@ -1190,11 +1190,6 @@ "UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes "UP032", # https://docs.astral.sh/ruff/rules/f-string ] -"./scripts/west_commands/zspdx/writer.py" = [ - "E501", # https://docs.astral.sh/ruff/rules/line-too-long - "F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders - "I001", # https://docs.astral.sh/ruff/rules/unsorted-imports -] "./scripts/zephyr_module.py" = [ "E501", # https://docs.astral.sh/ruff/rules/line-too-long "I001", # https://docs.astral.sh/ruff/rules/unsorted-imports diff --git a/scripts/west_commands/zspdx/writer.py b/scripts/west_commands/zspdx/writer.py index d1d77f7a5bb..8223d0ec1eb 100644 --- a/scripts/west_commands/zspdx/writer.py +++ b/scripts/west_commands/zspdx/writer.py @@ -2,14 +2,13 @@ # # SPDX-License-Identifier: Apache-2.0 +import re from datetime import datetime from west import log from zspdx.util import getHashes -import re - CPE23TYPE_REGEX = ( r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^' r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*" @@ -26,7 +25,10 @@ def _normalize_spdx_name(name): # 1) f: file handle for SPDX document # 2) rln: Relationship object being described def writeRelationshipSPDX(f, rln): - f.write(f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} {_normalize_spdx_name(rln.refB)}\n") + f.write( + f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} " + f"{_normalize_spdx_name(rln.refB)}\n" + ) # Output tag-value SPDX 2.3 content for the given File object. # Arguments: @@ -45,7 +47,7 @@ FileChecksum: SHA1: {bf.sha1} f.write(f"FileChecksum: MD5: {bf.md5}\n") f.write(f"LicenseConcluded: {bf.concludedLicense}\n") if len(bf.licenseInfoInFile) == 0: - f.write(f"LicenseInfoInFile: NONE\n") + f.write("LicenseInfoInFile: NONE\n") else: for licInfoInFile in bf.licenseInfoInFile: f.write(f"LicenseInfoInFile: {licInfoInFile}\n") @@ -111,10 +113,10 @@ PackageCopyrightText: {pkg.cfg.copyrightText} for licFromFiles in pkg.licenseInfoFromFiles: f.write(f"PackageLicenseInfoFromFiles: {licFromFiles}\n") else: - f.write(f"PackageLicenseInfoFromFiles: NOASSERTION\n") + f.write("PackageLicenseInfoFromFiles: NOASSERTION\n") f.write(f"FilesAnalyzed: true\nPackageVerificationCode: {pkg.verificationCode}\n\n") else: - f.write(f"FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n") + f.write("FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n") # write package relationships if len(pkg.rlns) > 0: @@ -162,14 +164,17 @@ Created: {datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")} extDocs = list(doc.externalDocuments) extDocs.sort(key = lambda x: x.cfg.docRefID) for extDoc in extDocs: - f.write(f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} SHA1: {extDoc.myDocSHA1}\n") - f.write(f"\n") + f.write( + f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} " + f"SHA1: {extDoc.myDocSHA1}\n" + ) + f.write("\n") # write relationships owned by this Document (not by its Packages, etc.), if any if len(doc.relationships) > 0: for rln in doc.relationships: writeRelationshipSPDX(f, rln) - f.write(f"\n") + f.write("\n") # write packages for pkg in doc.pkgs.values(): @@ -198,7 +203,7 @@ def writeSPDX(spdxPath, doc): # calculate hash of the document we just wrote hashes = getHashes(spdxPath) if not hashes: - log.err(f"Error: created document but unable to calculate hash values") + log.err("Error: created document but unable to calculate hash values") return False doc.myDocSHA1 = hashes[0]