Skip to content
45 changes: 0 additions & 45 deletions .ruff-excludes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1232,51 +1232,6 @@
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
"UP032", # https://docs.astral.sh/ruff/rules/f-string
]
"./scripts/west_commands/zspdx/cmakecache.py" = [
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
]
"./scripts/west_commands/zspdx/cmakefileapi.py" = [
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP008", # https://docs.astral.sh/ruff/rules/super-call-with-parameters
]
"./scripts/west_commands/zspdx/cmakefileapijson.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
"SIM116", # https://docs.astral.sh/ruff/rules/if-else-block-instead-of-dict-lookup
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
]
"./scripts/west_commands/zspdx/datatypes.py" = [
"UP008", # https://docs.astral.sh/ruff/rules/super-call-with-parameters
]
"./scripts/west_commands/zspdx/getincludes.py" = [
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP021", # https://docs.astral.sh/ruff/rules/replace-universal-newlines
"UP022", # https://docs.astral.sh/ruff/rules/replace-stdout-stderr
]
"./scripts/west_commands/zspdx/sbom.py" = [
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
"UP008", # https://docs.astral.sh/ruff/rules/super-call-with-parameters
]
"./scripts/west_commands/zspdx/scanner.py" = [
"SIM113", # https://docs.astral.sh/ruff/rules/enumerate-for-loop
"UP008", # https://docs.astral.sh/ruff/rules/super-call-with-parameters
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
]
"./scripts/west_commands/zspdx/walker.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
"UP008", # https://docs.astral.sh/ruff/rules/super-call-with-parameters
]
"./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
Expand Down
2 changes: 1 addition & 1 deletion scripts/west_commands/zspdx/cmakecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def parseCMakeCacheFile(filePath):
log.dbg(f"parsing CMake cache file at {filePath}")
kv = {}
try:
with open(filePath, "r") as f:
with open(filePath) as f:
# should be a short file, so we'll use readlines
lines = f.readlines()

Expand Down
35 changes: 18 additions & 17 deletions scripts/west_commands/zspdx/cmakefileapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from enum import Enum


class Codemodel:

def __init__(self):
super(Codemodel, self).__init__()
super().__init__()

self.paths_source = ""
self.paths_build = ""
Expand All @@ -20,7 +21,7 @@ def __repr__(self):
class Config:

def __init__(self):
super(Config, self).__init__()
super().__init__()

self.name = ""
self.directories = []
Expand All @@ -29,15 +30,15 @@ def __init__(self):

def __repr__(self):
if self.name == "":
return f"Config: [no name]"
return "Config: [no name]"
else:
return f"Config: {self.name}"

# A member of the configuration.directories array
class ConfigDir:

def __init__(self):
super(ConfigDir, self).__init__()
super().__init__()

self.source = ""
self.build = ""
Expand All @@ -61,7 +62,7 @@ def __repr__(self):
class ConfigProject:

def __init__(self):
super(ConfigProject, self).__init__()
super().__init__()

self.name = ""
self.parentIndex = -1
Expand All @@ -82,7 +83,7 @@ def __repr__(self):
class ConfigTarget:

def __init__(self):
super(ConfigTarget, self).__init__()
super().__init__()

self.name = ""
self.id = ""
Expand Down Expand Up @@ -114,7 +115,7 @@ class TargetType(Enum):
class TargetInstallDestination:

def __init__(self):
super(TargetInstallDestination, self).__init__()
super().__init__()

self.path = ""
self.backtrace = -1
Expand All @@ -127,7 +128,7 @@ def __repr__(self):
class TargetCommandFragment:

def __init__(self):
super(TargetCommandFragment, self).__init__()
super().__init__()

self.fragment = ""
self.role = ""
Expand All @@ -139,7 +140,7 @@ def __repr__(self):
class TargetDependency:

def __init__(self):
super(TargetDependency, self).__init__()
super().__init__()

self.id = ""
self.backtrace = -1
Expand All @@ -151,7 +152,7 @@ def __repr__(self):
class TargetSource:

def __init__(self):
super(TargetSource, self).__init__()
super().__init__()

self.path = ""
self.compileGroupIndex = -1
Expand All @@ -170,7 +171,7 @@ def __repr__(self):
class TargetSourceGroup:

def __init__(self):
super(TargetSourceGroup, self).__init__()
super().__init__()

self.name = ""
self.sourceIndexes = []
Expand All @@ -185,7 +186,7 @@ def __repr__(self):
class TargetCompileGroupInclude:

def __init__(self):
super(TargetCompileGroupInclude, self).__init__()
super().__init__()

self.path = ""
self.isSystem = False
Expand All @@ -198,7 +199,7 @@ def __repr__(self):
class TargetCompileGroupPrecompileHeader:

def __init__(self):
super(TargetCompileGroupPrecompileHeader, self).__init__()
super().__init__()

self.header = ""
self.backtrace = -1
Expand All @@ -210,7 +211,7 @@ def __repr__(self):
class TargetCompileGroupDefine:

def __init__(self):
super(TargetCompileGroupDefine, self).__init__()
super().__init__()

self.define = ""
self.backtrace = -1
Expand All @@ -222,7 +223,7 @@ def __repr__(self):
class TargetCompileGroup:

def __init__(self):
super(TargetCompileGroup, self).__init__()
super().__init__()

self.sourceIndexes = []
self.language = ""
Expand All @@ -242,7 +243,7 @@ def __repr__(self):
class TargetBacktraceGraphNode:

def __init__(self):
super(TargetBacktraceGraphNode, self).__init__()
super().__init__()

self.file = -1
self.line = -1
Expand All @@ -257,7 +258,7 @@ def __repr__(self):
class Target:

def __init__(self):
super(Target, self).__init__()
super().__init__()

self.name = ""
self.id = ""
Expand Down
44 changes: 21 additions & 23 deletions scripts/west_commands/zspdx/cmakefileapijson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@

import zspdx.cmakefileapi


def parseReply(replyIndexPath):
replyDir, _ = os.path.split(replyIndexPath)

# first we need to find the codemodel reply file
try:
with open(replyIndexPath, 'r') as indexFile:
with open(replyIndexPath) as indexFile:
js = json.load(indexFile)

# get reply object
reply_dict = js.get("reply", {})
if reply_dict == {}:
log.err(f"no \"reply\" field found in index file")
log.err('no "reply" field found in index file')
return None
# get codemodel object
cm_dict = reply_dict.get("codemodel-v2", {})
if cm_dict == {}:
log.err(f"no \"codemodel-v2\" field found in \"reply\" object in index file")
log.err('no "codemodel-v2" field found in "reply" object in index file')
return None
# and get codemodel filename
jsonFile = cm_dict.get("jsonFile", "")
if jsonFile == "":
log.err(f"no \"jsonFile\" field found in \"codemodel-v2\" object in index file")
log.err('no "jsonFile" field found in "codemodel-v2" object in index file')
return None

return parseCodemodel(replyDir, jsonFile)
Expand All @@ -46,23 +47,26 @@ def parseCodemodel(replyDir, codemodelFile):
codemodelPath = os.path.join(replyDir, codemodelFile)

try:
with open(codemodelPath, 'r') as cmFile:
with open(codemodelPath) as cmFile:
js = json.load(cmFile)

cm = zspdx.cmakefileapi.Codemodel()

# for correctness, check kind and version
kind = js.get("kind", "")
if kind != "codemodel":
log.err(f"Error loading CMake API reply: expected \"kind\":\"codemodel\" in {codemodelPath}, got {kind}")
log.err('Error loading CMake API reply: expected "kind":"codemodel" '
f'in {codemodelPath}, got {kind}')
return None
version = js.get("version", {})
versionMajor = version.get("major", -1)
if versionMajor != 2:
if versionMajor == -1:
log.err(f"Error loading CMake API reply: expected major version 2 in {codemodelPath}, no version found")
log.err("Error loading CMake API reply: expected major version 2 "
f"in {codemodelPath}, no version found")
return None
log.err(f"Error loading CMake API reply: expected major version 2 in {codemodelPath}, got {versionMajor}")
log.err("Error loading CMake API reply: expected major version 2 "
f"in {codemodelPath}, got {versionMajor}")
return None

# get paths
Expand Down Expand Up @@ -143,7 +147,7 @@ def parseConfig(cfg_dict, replyDir):

def parseTarget(targetPath):
try:
with open(targetPath, 'r') as targetFile:
with open(targetPath) as targetFile:
js = json.load(targetFile)

target = zspdx.cmakefileapi.Target()
Expand Down Expand Up @@ -191,20 +195,14 @@ def parseTarget(targetPath):
return None

def parseTargetType(targetType):
if targetType == "EXECUTABLE":
return zspdx.cmakefileapi.TargetType.EXECUTABLE
elif targetType == "STATIC_LIBRARY":
return zspdx.cmakefileapi.TargetType.STATIC_LIBRARY
elif targetType == "SHARED_LIBRARY":
return zspdx.cmakefileapi.TargetType.SHARED_LIBRARY
elif targetType == "MODULE_LIBRARY":
return zspdx.cmakefileapi.TargetType.MODULE_LIBRARY
elif targetType == "OBJECT_LIBRARY":
return zspdx.cmakefileapi.TargetType.OBJECT_LIBRARY
elif targetType == "UTILITY":
return zspdx.cmakefileapi.TargetType.UTILITY
else:
return zspdx.cmakefileapi.TargetType.UNKNOWN
return {
"EXECUTABLE": zspdx.cmakefileapi.TargetType.EXECUTABLE,
"STATIC_LIBRARY": zspdx.cmakefileapi.TargetType.STATIC_LIBRARY,
"SHARED_LIBRARY": zspdx.cmakefileapi.TargetType.SHARED_LIBRARY,
"MODULE_LIBRARY": zspdx.cmakefileapi.TargetType.MODULE_LIBRARY,
"OBJECT_LIBRARY": zspdx.cmakefileapi.TargetType.OBJECT_LIBRARY,
"UTILITY": zspdx.cmakefileapi.TargetType.UTILITY,
}.get(targetType, zspdx.cmakefileapi.TargetType.UNKNOWN)

def parseTargetInstall(target, js):
install_dict = js.get("install", {})
Expand Down
14 changes: 7 additions & 7 deletions scripts/west_commands/zspdx/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# should be built.
class DocumentConfig:
def __init__(self):
super(DocumentConfig, self).__init__()
super().__init__()

# name of document
self.name = ""
Expand All @@ -27,7 +27,7 @@ def __init__(self):
class Document:
# initialize with a DocumentConfig
def __init__(self, cfg):
super(Document, self).__init__()
super().__init__()

# configuration - DocumentConfig
self.cfg = cfg
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self, cfg):
# be built.
class PackageConfig:
def __init__(self):
super(PackageConfig, self).__init__()
super().__init__()

# package name
self.name = ""
Expand Down Expand Up @@ -106,7 +106,7 @@ class Package:
# 1) PackageConfig
# 2) the Document that owns this Package
def __init__(self, cfg, doc):
super(Package, self).__init__()
super().__init__()

# configuration - PackageConfig
self.cfg = cfg
Expand Down Expand Up @@ -153,7 +153,7 @@ class RelationshipDataElementType(Enum):
# Relationship after we have organized the SPDX Package and File data.
class RelationshipData:
def __init__(self):
super(RelationshipData, self).__init__()
super().__init__()

# for the "owner" element (e.g., the left side of the Relationship),
# is it a filename or a target name (e.g., a Package in the build doc)
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self):
# Document's context.
class Relationship:
def __init__(self):
super(Relationship, self).__init__()
super().__init__()

# SPDX ID for left side of relationship
# including "SPDXRef-" as well as "DocumentRef-" if needed
Expand All @@ -213,7 +213,7 @@ class File:
# 1) Document containing this File
# 2) Package containing this File
def __init__(self, doc, pkg):
super(File, self).__init__()
super().__init__()

# absolute path to this file on disk
self.abspath = ""
Expand Down
Loading
Loading