From 6986528bf31ad21f95810670d738319459fe3b37 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 12:50:49 +0200 Subject: [PATCH 01/13] wip: full typing with mypy --- cmake_file_api/kinds/cache/v2.py | 4 ++-- cmake_file_api/kinds/cmakeFiles/v1.py | 2 +- cmake_file_api/kinds/codemodel/target/v2.py | 2 +- cmake_file_api/kinds/configureLog/target/v2.py | 14 +++++++------- cmake_file_api/py.typed | 0 requirements-dev.txt | 1 + 6 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 cmake_file_api/py.typed diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index 82e0f61..a8b2e2c 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -75,7 +75,7 @@ def __init__(self, version: VersionMajorMinor, entries: List[CacheEntry]): self.entries = entries @classmethod - def from_dict(cls, dikt: Dict, reply_path) -> "CacheModelV2": + def from_dict(cls, dikt: Dict, reply_path) -> "CacheV2": if dikt["kind"] != cls.KIND.value: raise ValueError version = VersionMajorMinor.from_dict(dikt["version"]) @@ -83,7 +83,7 @@ def from_dict(cls, dikt: Dict, reply_path) -> "CacheModelV2": return cls(version, entries) @classmethod - def from_path(cls, path: Path, reply_path: Path) -> "CacheModelV2": + def from_path(cls, path: Path, reply_path: Path) -> "CacheV2": dikt = json.load(path.open()) return cls.from_dict(dikt, reply_path) diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index 164de4c..ca64890 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -16,7 +16,7 @@ def __init__(self, path: Path, isGenerator: Optional[bool], isExternal: Optional self.isCMake = isCMake @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeFileInput": + def from_dict(cls, dikt: Dict) -> "CMakeFilesInput": path = Path(dikt["path"]) isGenerator = dikt.get("isGenerator") isExternal = dikt.get("isExternal") diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 0ec3928..d84d658 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -206,7 +206,7 @@ def __init__(self, commandFragments: List[TargetArchiveFragment], lto: Optional[ def from_dict(cls, dikt: Dict) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: - commandFragments = list(TargetLinkFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) + commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) lto = dikt.get("lto") return cls(commandFragments, lto) diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index a9a8575..1146387 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -61,7 +61,7 @@ class BacktraceGraph(object): __slots__ = ("nodes", ) def __init__(self, nodes: List[BacktraceNode]): - self.nodes = nodes + self.nodes: List[BacktraceNode] = nodes @classmethod def from_dict(cls, dikt: Dict) -> "BacktraceGraph": @@ -205,7 +205,7 @@ def __init__(self, commandFragments: List[TargetArchiveFragment], lto: Optional[ def from_dict(cls, dikt: Dict) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: - commandFragments = list(TargetLinkFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) + commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) lto = dikt.get("lto") return cls(commandFragments, lto) @@ -222,7 +222,7 @@ class TargetSourceGroup(object): def __init__(self, name: str, sources: List["TargetSource"]): self.name = name - self.sources = [] + self.sources: list[TargetSource] = [] @classmethod def from_dict(cls, dikt: Dict, target_sources: List["TargetSource"]) -> "TargetSourceGroup": @@ -283,7 +283,7 @@ def __repr__(self) -> str: class TargetCompileGroupPCH(object): __slots__ = ("header", "backtrace") - def __init__(self, header: Path, backtrace: BacktraceNode): + def __init__(self, header: Path, backtrace: BacktraceNode | None): self.header = header self.backtrace = backtrace @@ -306,7 +306,7 @@ def __repr__(self) -> str: class TargetCompileGroupDefine(object): __slots__ = ("define", "backtrace") - def __init__(self, define: str, backtrace: BacktraceNode): + def __init__(self, define: str, backtrace: BacktraceNode | None): self.define = define self.backtrace = backtrace @@ -370,7 +370,7 @@ class TargetDependency(object): def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.id = id - self.target = None # type: CodemodelTargetV2 + self.target: CodemodelTargetV2 | None = None self.backtrace = backtrace def update_dependency(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): @@ -462,7 +462,7 @@ def update_dependencies(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): dependency.update_dependency(lut_id_target) @classmethod - def from_dict(cls, dikt: Dict, reply_path: Path) -> "CodemodelTargetV2": + def from_dict(cls, dikt: Dict) -> "CodemodelTargetV2": name = dikt["name"] id = dikt["id"] type = TargetType(dikt["type"]) diff --git a/cmake_file_api/py.typed b/cmake_file_api/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/requirements-dev.txt b/requirements-dev.txt index e079f8a..4bfa28c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,2 @@ pytest +mypy From 69bebb792c6f22fdccb9da234f216d9c15b1fb4f Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 15:03:41 +0200 Subject: [PATCH 02/13] fix some more errors --- .gitignore | 1 + cmake_file_api/cmake.py | 7 ++++--- cmake_file_api/kinds/codemodel/target/v2.py | 2 +- cmake_file_api/kinds/codemodel/v2.py | 10 +++++----- cmake_file_api/kinds/common.py | 3 ++- cmake_file_api/kinds/configureLog/v1.py | 4 ++-- mypy.ini | 0 setup.cfg | 4 ++-- 8 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 mypy.ini diff --git a/.gitignore b/.gitignore index a7edc71..dfdbb0e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ /build/ /.eggs/ /venv/ +/.venv *.egg-info *.py[co] diff --git a/cmake_file_api/cmake.py b/cmake_file_api/cmake.py index 610ae9a..64b1e9f 100644 --- a/cmake_file_api/cmake.py +++ b/cmake_file_api/cmake.py @@ -3,6 +3,7 @@ from typing import List, Optional, Union from .reply.api import REPLY_API +from .reply.v1.api import CMakeFileApiV1 PathLike = Union[Path, str] @@ -57,14 +58,14 @@ def _cache_lookup(name: str, cache: PathLike) -> str: _, value = line.split("=", 1) return value - def configure(self, args: Optional[List[str]]=None, quiet=False): + def configure(self, args: Optional[List[str]]=None, quiet: bool = False) -> None: if self._source_path is None: raise ValueError("Cannot configure with no source path") stdout = subprocess.DEVNULL if quiet else None args = [str(self._cmake), str(self._source_path)] + (args if args else []) subprocess.check_call(args, cwd=str(self._build_path), stdout=stdout) - def reconfigure(self, quiet=False): + def reconfigure(self, quiet: bool = False) -> None: stdout = subprocess.DEVNULL if quiet else None args = [str(self._cmake)] if self._source_path: @@ -74,5 +75,5 @@ def reconfigure(self, quiet=False): subprocess.check_call(args, cwd=str(self._build_path), stdout=stdout) @property - def cmake_file_api(self): + def cmake_file_api(self) -> CMakeFileApiV1: return REPLY_API[self._api_version](self._build_path) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index d84d658..fa541a5 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -458,7 +458,7 @@ def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNod self.sourceGroups = sourceGroups self.compileGroups = compileGroups - def update_dependencies(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): + def update_dependencies(self, lut_id_target: Dict[str, "CodemodelTargetV2"]) -> None: for dependency in self.dependencies: dependency.update_dependency(lut_id_target) diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index 51aa422..dbec0ef 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -18,11 +18,11 @@ def __init__(self, name: str): self.targets = [] # type:List[CMakeTarget] @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeProject": + def from_dict(cls, dikt: Dict[str, str]) -> "CMakeProject": name = dikt["name"] return cls(name) - def update_from_dict(self, dikt: Dict, configuration: "CMakeConfiguration") -> None: + def update_from_dict(self, dikt: Dict[str, Any], configuration: "CMakeConfiguration") -> None: if "parentIndex" in dikt: self.parentProject = configuration.projects[dikt["parentIndex"]] self.childProjects = list(configuration.projects[ti] for ti in dikt.get("childIndexes", ())) @@ -75,7 +75,7 @@ def __repr__(self) -> str: self.build, '{}'.format(self.parentDirectory) if self.parentDirectory else None, len(self.childDirectories), - self.project.name, + self.project.name if self.project else "", len(self.targets), self.minimumCMakeVersion, self.hasInstallRule, @@ -164,7 +164,7 @@ def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, con self.configurations = configurations @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "CodemodelV2": + def from_dict(cls, dikt: Dict[str, Any], reply_path: Path) -> "CodemodelV2": if dikt["kind"] != cls.KIND.value: raise ValueError paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) diff --git a/cmake_file_api/kinds/common.py b/cmake_file_api/kinds/common.py index 070d124..aa64bce 100644 --- a/cmake_file_api/kinds/common.py +++ b/cmake_file_api/kinds/common.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Dict class VersionMajorMinor(object): @@ -9,7 +10,7 @@ def __init__(self, major: int, minor: int): self.minor = minor @classmethod - def from_dict(cls, d) -> "VersionMajorMinor": + def from_dict(cls, d: Dict[str, str]) -> "VersionMajorMinor": return cls(int(d["major"]), int(d["minor"])) def __repr__(self) -> str: diff --git a/cmake_file_api/kinds/configureLog/v1.py b/cmake_file_api/kinds/configureLog/v1.py index 6cb3d75..9754c66 100644 --- a/cmake_file_api/kinds/configureLog/v1.py +++ b/cmake_file_api/kinds/configureLog/v1.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -18,7 +18,7 @@ def __init__(self, version: VersionMajorMinor, path: Path, eventKindNames: List[ self.eventKindNames = eventKindNames @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "ConfigureLogV1": + def from_dict(cls, dikt: Dict[str, Any], reply_path: Path) -> "ConfigureLogV1": if dikt["kind"] != cls.KIND.value: raise ValueError path = Path(dikt["path"]) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg index 2c6cbac..019511c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,9 +16,9 @@ classifiers = Operating System :: OS Independent [options] -python_requires = >=3.6 +python_requires = >=3.9 packages=find: -setup_requires = +setup_requires = setuptools_scm [options.packages.find] From 36c9fc9ae4f903bcfafa14a162582291bfeaaacb Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 15:04:30 +0200 Subject: [PATCH 03/13] use >3.9 syntax --- cmake_file_api/cmake.py | 4 +- cmake_file_api/kinds/cache/v2.py | 16 +-- cmake_file_api/kinds/cmakeFiles/v1.py | 10 +- cmake_file_api/kinds/codemodel/target/v2.py | 104 ++++++++--------- cmake_file_api/kinds/codemodel/v2.py | 32 +++--- cmake_file_api/kinds/common.py | 6 +- .../kinds/configureLog/target/v2.py | 106 +++++++++--------- cmake_file_api/kinds/configureLog/v1.py | 6 +- cmake_file_api/kinds/toolchains/v1.py | 20 ++-- cmake_file_api/reply/index/file/v1.py | 4 +- cmake_file_api/reply/index/v1.py | 30 ++--- cmake_file_api/reply/v1/api.py | 10 +- 12 files changed, 174 insertions(+), 174 deletions(-) diff --git a/cmake_file_api/cmake.py b/cmake_file_api/cmake.py index 64b1e9f..d1c00e8 100644 --- a/cmake_file_api/cmake.py +++ b/cmake_file_api/cmake.py @@ -8,7 +8,7 @@ PathLike = Union[Path, str] -class CMakeProject(object): +class CMakeProject: __slots__ = ("_source_path", "_build_path", "_api_version", "_cmake") def __init__(self, build_path: PathLike, source_path: Optional[PathLike]=None, api_version: Optional[int]=None, cmake: Optional[str]=None): @@ -58,7 +58,7 @@ def _cache_lookup(name: str, cache: PathLike) -> str: _, value = line.split("=", 1) return value - def configure(self, args: Optional[List[str]]=None, quiet: bool = False) -> None: + def configure(self, args: Optional[list[str]]=None, quiet: bool = False) -> None: if self._source_path is None: raise ValueError("Cannot configure with no source path") stdout = subprocess.DEVNULL if quiet else None diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index a8b2e2c..97835ce 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -17,7 +17,7 @@ class CacheEntryType(Enum): TYPE_UNINITIALIZED = "UNINITIALIZED" -class CacheEntryProperty(object): +class CacheEntryProperty: __slots__ = ("name", "value") def __init__(self, name: str, value: str): @@ -25,7 +25,7 @@ def __init__(self, name: str, value: str): self.value = value @classmethod - def from_dict(cls, dikt: Dict) -> "CacheEntryProperty": + def from_dict(cls, dikt: dict) -> "CacheEntryProperty": name = dikt["name"] value = dikt["value"] return cls(name, value) @@ -38,17 +38,17 @@ def __repr__(self) -> str: ) -class CacheEntry(object): +class CacheEntry: __slots__ = ("name", "value", "type", "properties") - def __init__(self, name: str, value: str, type: CacheEntryType, properties: List[CacheEntryProperty]): + def __init__(self, name: str, value: str, type: CacheEntryType, properties: list[CacheEntryProperty]): self.name = name self.value = value self.type = type self.properties = properties @classmethod - def from_dict(cls, dikt: Dict) -> "CacheEntry": + def from_dict(cls, dikt: dict) -> "CacheEntry": name = dikt["name"] value = dikt["value"] type = CacheEntryType(dikt["type"]) @@ -65,17 +65,17 @@ def __repr__(self) -> str: ) -class CacheV2(object): +class CacheV2: KIND = ObjectKind.CACHE __slots__ = ("version", "entries") - def __init__(self, version: VersionMajorMinor, entries: List[CacheEntry]): + def __init__(self, version: VersionMajorMinor, entries: list[CacheEntry]): self.version = version self.entries = entries @classmethod - def from_dict(cls, dikt: Dict, reply_path) -> "CacheV2": + def from_dict(cls, dikt: dict, reply_path) -> "CacheV2": if dikt["kind"] != cls.KIND.value: raise ValueError version = VersionMajorMinor.from_dict(dikt["version"]) diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index ca64890..9d81bac 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -6,7 +6,7 @@ from cmake_file_api.kinds.kind import ObjectKind -class CMakeFilesInput(object): +class CMakeFilesInput: __slots__ = ("path", "isGenerator", "isExternal", "isCMake") def __init__(self, path: Path, isGenerator: Optional[bool], isExternal: Optional[bool], isCMake: Optional[bool]): @@ -16,7 +16,7 @@ def __init__(self, path: Path, isGenerator: Optional[bool], isExternal: Optional self.isCMake = isCMake @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeFilesInput": + def from_dict(cls, dikt: dict) -> "CMakeFilesInput": path = Path(dikt["path"]) isGenerator = dikt.get("isGenerator") isExternal = dikt.get("isExternal") @@ -33,18 +33,18 @@ def __repr__(self) -> str: ) -class CMakeFilesV1(object): +class CMakeFilesV1: KIND = ObjectKind.CMAKEFILES __slots__ = ("version", "paths", "inputs") - def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inputs: List[CMakeFilesInput]): + def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inputs: list[CMakeFilesInput]): self.version = version self.paths = paths self.inputs = inputs @classmethod - def from_dict(cls, dikt: Dict, reply_path: Path) -> "CmakeFilesV2": + def from_dict(cls, dikt: dict, reply_path: Path) -> "CmakeFilesV2": version = VersionMajorMinor.from_dict(dikt["version"]) paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) inputs = list(CMakeFilesInput.from_dict(cmi) for cmi in dikt["inputs"]) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index fa541a5..e3adacf 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -27,7 +27,7 @@ class ArchiveFragmentRole(enum.Enum): ARCHIVER_FLAGS = "flags" -class BacktraceNode(object): +class BacktraceNode: __slots__ = ("file", "line", "command", "parent") def __init__(self, file: Path, line: Optional[int], command: Optional[str]): @@ -37,7 +37,7 @@ def __init__(self, file: Path, line: Optional[int], command: Optional[str]): self.parent = None @classmethod - def from_dict(cls, dikt: Dict, commands: List[str], files: List[Path]) -> "BacktraceNode": + def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "BacktraceNode": file = files[dikt["file"]] line = dikt.get("line") command = None @@ -45,7 +45,7 @@ def from_dict(cls, dikt: Dict, commands: List[str], files: List[Path]) -> "Backt command = commands[dikt["command"]] return cls(file, line, command) - def update_from_dict(self, dikt: Dict, nodes: List["BacktraceNode"]) -> None: + def update_from_dict(self, dikt: dict, nodes: list["BacktraceNode"]) -> None: if "parent" in dikt: self.parent = nodes[dikt["parent"]] @@ -58,14 +58,14 @@ def __repr__(self) -> str: ) -class BacktraceGraph(object): +class BacktraceGraph: __slots__ = ("nodes", ) - def __init__(self, nodes: List[BacktraceNode]): + def __init__(self, nodes: list[BacktraceNode]): self.nodes = nodes @classmethod - def from_dict(cls, dikt: Dict) -> "BacktraceGraph": + def from_dict(cls, dikt: dict) -> "BacktraceGraph": commands = dikt["commands"] files = list(Path(f) for f in dikt["files"]) nodes = list(BacktraceNode.from_dict(btn, commands, files) for btn in dikt["nodes"]) @@ -80,7 +80,7 @@ def __repr__(self) -> str: ) -class TargetDestination(object): +class TargetDestination: __slots__ = ("path", "backtrace") def __init__(self, path: Path, backtrace: BacktraceNode): @@ -88,7 +88,7 @@ def __init__(self, path: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": path = Path(dikt["path"]) backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, backtrace) @@ -101,15 +101,15 @@ def __repr__(self) -> str: ) -class TargetInstall(object): +class TargetInstall: __slots__ = ("prefix", "destinations") - def __init__(self, prefix: Path, destinations: List[TargetDestination]): + def __init__(self, prefix: Path, destinations: list[TargetDestination]): self.prefix = prefix self.destinations = destinations @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": prefix = Path(dikt["prefix"]["path"]) destinations = list(TargetDestination.from_dict(td, backtraceGraph) for td in dikt["destinations"]) return cls(prefix, destinations) @@ -122,7 +122,7 @@ def __repr__(self) -> str: ) -class TargetLinkFragment(object): +class TargetLinkFragment: __slots__ = ("fragment", "role") def __init__(self, fragment: str, role: LinkFragmentRole): @@ -130,7 +130,7 @@ def __init__(self, fragment: str, role: LinkFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: Dict) -> "TargetLinkFragment": + def from_dict(cls, dikt: dict) -> "TargetLinkFragment": fragment = dikt["fragment"] role = LinkFragmentRole(dikt["role"]) return cls(fragment, role) @@ -143,17 +143,17 @@ def __repr__(self) -> str: ) -class TargetLink(object): +class TargetLink: __slots__ = ("language", "commandFragments", "lto", "sysroot") - def __init__(self, language: str, commandFragments: List[TargetLinkFragment], lto: Optional[bool], sysroot: Optional[Path]): + def __init__(self, language: str, commandFragments: list[TargetLinkFragment], lto: Optional[bool], sysroot: Optional[Path]): self.language = language self.commandFragments = commandFragments self.lto = lto self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: Dict) -> "TargetLink": + def from_dict(cls, dikt: dict) -> "TargetLink": language = dikt["language"] commandFragments = [] if "commandFragments" in dikt: @@ -170,11 +170,11 @@ def __repr__(self) -> str: self.language, self.commandFragments, self.lto, - "'{}'".format(self.sysroot) if self.sysroot else None, + f"'{self.sysroot}'" if self.sysroot else None, ) -class TargetArchiveFragment(object): +class TargetArchiveFragment: __slots__ = ("fragment", "role") def __init__(self, fragment: str, role: ArchiveFragmentRole): @@ -182,7 +182,7 @@ def __init__(self, fragment: str, role: ArchiveFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: Dict) -> "TargetArchiveFragment": + def from_dict(cls, dikt: dict) -> "TargetArchiveFragment": fragment = dikt["fragment"] role = ArchiveFragmentRole(dikt["role"]) return cls(fragment, role) @@ -195,15 +195,15 @@ def __repr__(self) -> str: ) -class TargetArchive(object): +class TargetArchive: __slots__ = ("commandFragments", "lto") - def __init__(self, commandFragments: List[TargetArchiveFragment], lto: Optional[bool]): + def __init__(self, commandFragments: list[TargetArchiveFragment], lto: Optional[bool]): self.commandFragments = commandFragments self.lto = lto @classmethod - def from_dict(cls, dikt: Dict) -> "TargetArchive": + def from_dict(cls, dikt: dict) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) @@ -218,15 +218,15 @@ def __repr__(self) -> str: ) -class TargetSourceGroup(object): +class TargetSourceGroup: __slots__ = ("name", "sources") - def __init__(self, name: str, sources: List["TargetSource"]): + def __init__(self, name: str, sources: list["TargetSource"]): self.name = name self.sources = [] @classmethod - def from_dict(cls, dikt: Dict, target_sources: List["TargetSource"]) -> "TargetSourceGroup": + def from_dict(cls, dikt: dict, target_sources: list["TargetSource"]) -> "TargetSourceGroup": name = dikt["name"] sources = list(target_sources[tsi] for tsi in dikt["sourceIndexes"]) return cls(name, sources) @@ -237,14 +237,14 @@ def __repr__(self) -> str: ) -class TargetCompileFragment(object): +class TargetCompileFragment: __slots__ = ("fragment", ) def __init__(self, fragment: str): self.fragment = fragment @classmethod - def from_dict(cls, dikt: Dict) -> "TargetCompileFragment": + def from_dict(cls, dikt: dict) -> "TargetCompileFragment": fragment = dikt["fragment"] return cls(fragment) @@ -255,7 +255,7 @@ def __repr__(self) -> str: ) -class TargetCompileGroupInclude(object): +class TargetCompileGroupInclude: __slots__ = ("path", "isSystem", "backtrace") def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[BacktraceNode]): @@ -264,7 +264,7 @@ def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[Bac self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": path = Path(dikt["path"]) isSystem = dikt.get("isSystem") backtrace = None @@ -275,13 +275,13 @@ def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompile def __repr__(self) -> str: return "{}(path={}, system={}, backtrace={})".format( type(self).__name__, - "'{}'".format(self.path) if self.path else None, + f"'{self.path}'" if self.path else None, self.isSystem, self.backtrace, ) -class TargetCompileGroupPCH(object): +class TargetCompileGroupPCH: __slots__ = ("header", "backtrace") def __init__(self, header: Path, backtrace: BacktraceNode): @@ -289,7 +289,7 @@ def __init__(self, header: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": header = Path(dikt["header"]) backtrace = None if "backtrace" in dikt: @@ -304,7 +304,7 @@ def __repr__(self) -> str: ) -class TargetCompileGroupDefine(object): +class TargetCompileGroupDefine: __slots__ = ("define", "backtrace") def __init__(self, define: str, backtrace: BacktraceNode): @@ -312,7 +312,7 @@ def __init__(self, define: str, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": define = dikt["define"] backtrace = None if "backtrace" in dikt: @@ -327,12 +327,12 @@ def __repr__(self) -> str: ) -class TargetCompileGroup(object): +class TargetCompileGroup: __slots__ = ("sources", "language", "compileCommandFragments", "includes", "precompileHeaders", "defines", "sysroot") - def __init__(self, sources: List["TargetSource"], language: str, - compileCommandFragments: List[TargetCompileFragment], includes: List[TargetCompileGroupInclude], - precompileHeaders: List[TargetCompileGroupPCH], defines: List[TargetCompileGroupDefine], + def __init__(self, sources: list["TargetSource"], language: str, + compileCommandFragments: list[TargetCompileFragment], includes: list[TargetCompileGroupInclude], + precompileHeaders: list[TargetCompileGroupPCH], defines: list[TargetCompileGroupDefine], sysroot: Optional[Path]): self.sources = sources self.language = language @@ -343,7 +343,7 @@ def __init__(self, sources: List["TargetSource"], language: str, self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: Dict, target_sources: List["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": + def from_dict(cls, dikt: dict, target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": language = dikt["language"] compileCommandFragments = list(TargetCompileFragment.from_dict(tcf) for tcf in dikt.get("compileCommandFragments", ())) includes = list(TargetCompileGroupInclude.from_dict(tci, backtraceGraph) for tci in dikt.get("includes", ())) @@ -362,11 +362,11 @@ def __repr__(self) -> str: len(self.includes), len(self.precompileHeaders), len(self.defines), - "'{}'".format(self.sysroot) if self.sysroot else None, + f"'{self.sysroot}'" if self.sysroot else None, ) -class TargetDependency(object): +class TargetDependency: __slots__ = ("id", "target", "backtrace") def __init__(self, id: str, backtrace: Optional[BacktraceNode]): @@ -374,11 +374,11 @@ def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.target = None # type: CodemodelTargetV2 self.backtrace = backtrace - def update_dependency(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): + def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): self.target = lut_id_target[self.id] @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": id = dikt["id"] backtrace = None if "backtrace" in dikt: @@ -394,7 +394,7 @@ def __repr__(self) -> str: ) -class TargetSource(object): +class TargetSource: __slots__ = ("path", "isGenerated", "backtrace", "compileGroup", "sourceGroup") def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[BacktraceNode]): @@ -405,7 +405,7 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.sourceGroup = None # type: Optional[TargetSourceGroup] @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetSource": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": path = Path(dikt["path"]) isGenerated = dikt.get("isGenerated") backtrace = None @@ -413,7 +413,7 @@ def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetSource" backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, isGenerated, backtrace) - def update_from_dict(self, dikt: Dict, modelTarget: "CodemodelTargetV2"): + def update_from_dict(self, dikt: dict, modelTarget: "CodemodelTargetV2"): if "compileGroupIndex" in dikt: self.compileGroup = modelTarget.compileGroups[dikt["compileGroupIndex"]] if "sourceGroupIndex" in dikt: @@ -430,17 +430,17 @@ def __repr__(self) -> str: ) -class CodemodelTargetV2(object): +class CodemodelTargetV2: __slots__ = ("name", "id", "type", "backtrace", "folder", "paths", "nameOnDisk", "artifacts", "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Path, - paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: List[Path], + paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], - dependencies: List[TargetDependency], sources: List[TargetSource], - sourceGroups: List[TargetSourceGroup], compileGroups: List[TargetCompileGroup]): + dependencies: list[TargetDependency], sources: list[TargetSource], + sourceGroups: list[TargetSourceGroup], compileGroups: list[TargetCompileGroup]): self.name = name self.id = id self.type = type @@ -458,12 +458,12 @@ def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNod self.sourceGroups = sourceGroups self.compileGroups = compileGroups - def update_dependencies(self, lut_id_target: Dict[str, "CodemodelTargetV2"]) -> None: + def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> None: for dependency in self.dependencies: dependency.update_dependency(lut_id_target) @classmethod - def from_dict(cls, dikt: Dict, reply_path: Path) -> "CodemodelTargetV2": + def from_dict(cls, dikt: dict, reply_path: Path) -> "CodemodelTargetV2": name = dikt["name"] id = dikt["id"] type = TargetType(dikt["type"]) diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index dbec0ef..8ecca0a 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -7,7 +7,7 @@ from .target.v2 import CodemodelTargetV2 -class CMakeProject(object): +class CMakeProject: __slots__ = ("name", "parentProject", "childProjects", "directories", "targets") def __init__(self, name: str): @@ -18,11 +18,11 @@ def __init__(self, name: str): self.targets = [] # type:List[CMakeTarget] @classmethod - def from_dict(cls, dikt: Dict[str, str]) -> "CMakeProject": + def from_dict(cls, dikt: dict[str, str]) -> "CMakeProject": name = dikt["name"] return cls(name) - def update_from_dict(self, dikt: Dict[str, Any], configuration: "CMakeConfiguration") -> None: + def update_from_dict(self, dikt: dict[str, Any], configuration: "CMakeConfiguration") -> None: if "parentIndex" in dikt: self.parentProject = configuration.projects[dikt["parentIndex"]] self.childProjects = list(configuration.projects[ti] for ti in dikt.get("childIndexes", ())) @@ -40,7 +40,7 @@ def __repr__(self) -> str: ) -class CMakeDirectory(object): +class CMakeDirectory: __slots__ = ("source", "build", "parentDirectory", "childDirectories", "project", "targets", "minimumCMakeVersion", "hasInstallRule") def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool): @@ -54,14 +54,14 @@ def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str] self.hasInstallRule = hasInstallRule @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeDirectory": + def from_dict(cls, dikt: dict) -> "CMakeDirectory": source = Path(dikt["source"]) build = Path(dikt["build"]) minimumCMakeVersion = dikt.get("minimumCMakeVersion", None) hasInstallRule = dikt.get("hasInstallRule", False) return cls(source, build, minimumCMakeVersion, hasInstallRule) - def update_from_dict(self, dikt: Dict, configuration: "CMakeConfiguration") -> None: + def update_from_dict(self, dikt: dict, configuration: "CMakeConfiguration") -> None: if "parentIndex" in dikt: self.parentDirectory = configuration.directories[dikt["parentIndex"]] self.childDirectories = list(configuration.directories[di] for di in dikt.get("childIndexes", ())) @@ -73,7 +73,7 @@ def __repr__(self) -> str: type(self).__name__, self.source, self.build, - '{}'.format(self.parentDirectory) if self.parentDirectory else None, + f'{self.parentDirectory}' if self.parentDirectory else None, len(self.childDirectories), self.project.name if self.project else "", len(self.targets), @@ -82,7 +82,7 @@ def __repr__(self) -> str: ) -class CMakeTarget(object): +class CMakeTarget: __slots__ = ("name", "directory", "project", "jsonFile", "target") def __init__(self, name: str, directory: CMakeDirectory, project: CMakeProject, jsonFile: Path, target: CodemodelTargetV2): @@ -92,12 +92,12 @@ def __init__(self, name: str, directory: CMakeDirectory, project: CMakeProject, self.jsonFile = jsonFile self.target = target - def update_dependencies(self, lut_id_target: Dict[str, "CMakeTarget"]): + def update_dependencies(self, lut_id_target: dict[str, "CMakeTarget"]): lut = {k: v.target for k, v in lut_id_target.items()} self.target.update_dependencies(lut) @classmethod - def from_dict(cls, dikt: Dict, directories: List[CMakeDirectory], projects: List[CMakeProject], reply_path: Path) -> "CMakeTarget": + def from_dict(cls, dikt: dict, directories: list[CMakeDirectory], projects: list[CMakeProject], reply_path: Path) -> "CMakeTarget": name = dikt["name"] directory = directories[dikt["directoryIndex"]] project = projects[dikt["projectIndex"]] @@ -116,17 +116,17 @@ def __repr__(self) -> str: ) -class CMakeConfiguration(object): +class CMakeConfiguration: __slots__ = ("name", "directories", "projects", "targets") - def __init__(self, name: str, directories: List[CMakeDirectory], projects: List[CMakeProject], targets: List[CMakeTarget]): + def __init__(self, name: str, directories: list[CMakeDirectory], projects: list[CMakeProject], targets: list[CMakeTarget]): self.name = name self.directories = directories self.projects = projects self.targets = targets @classmethod - def from_dict(cls, dikt: Dict, reply_path: Path) -> "CMakeConfiguration": + def from_dict(cls, dikt: dict, reply_path: Path) -> "CMakeConfiguration": name = dikt["name"] directories = list(CMakeDirectory.from_dict(d) for d in dikt["directories"]) projects = list(CMakeProject.from_dict(d) for d in dikt["projects"]) @@ -153,18 +153,18 @@ def __repr__(self) -> str: ) -class CodemodelV2(object): +class CodemodelV2: KIND = ObjectKind.CODEMODEL __slots__ = ("version", "paths", "configurations") - def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, configurations: List[CMakeConfiguration]): + def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, configurations: list[CMakeConfiguration]): self.version = version self.paths = paths self.configurations = configurations @classmethod - def from_dict(cls, dikt: Dict[str, Any], reply_path: Path) -> "CodemodelV2": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CodemodelV2": if dikt["kind"] != cls.KIND.value: raise ValueError paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) diff --git a/cmake_file_api/kinds/common.py b/cmake_file_api/kinds/common.py index aa64bce..0beeef6 100644 --- a/cmake_file_api/kinds/common.py +++ b/cmake_file_api/kinds/common.py @@ -2,7 +2,7 @@ from typing import Dict -class VersionMajorMinor(object): +class VersionMajorMinor: __slots__ = ("major", "minor") def __init__(self, major: int, minor: int): @@ -10,7 +10,7 @@ def __init__(self, major: int, minor: int): self.minor = minor @classmethod - def from_dict(cls, d: Dict[str, str]) -> "VersionMajorMinor": + def from_dict(cls, d: dict[str, str]) -> "VersionMajorMinor": return cls(int(d["major"]), int(d["minor"])) def __repr__(self) -> str: @@ -20,7 +20,7 @@ def __repr__(self) -> str: ) -class CMakeSourceBuildPaths(object): +class CMakeSourceBuildPaths: __slots__ = ("source", "build") def __init__(self, source: Path, build: Path): diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index 1146387..9c9eafd 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -26,7 +26,7 @@ class ArchiveFragmentRole(enum.Enum): ARCHIVER_FLAGS = "flags" -class BacktraceNode(object): +class BacktraceNode: __slots__ = ("file", "line", "command", "parent") def __init__(self, file: Path, line: Optional[int], command: Optional[str]): @@ -36,7 +36,7 @@ def __init__(self, file: Path, line: Optional[int], command: Optional[str]): self.parent = None @classmethod - def from_dict(cls, dikt: Dict, commands: List[str], files: List[Path]) -> "BacktraceNode": + def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "BacktraceNode": file = files[dikt["file"]] line = dikt.get("line") command = None @@ -44,7 +44,7 @@ def from_dict(cls, dikt: Dict, commands: List[str], files: List[Path]) -> "Backt command = commands[dikt["command"]] return cls(file, line, command) - def update_from_dict(self, dikt: Dict, nodes: List["BacktraceNode"]) -> None: + def update_from_dict(self, dikt: dict, nodes: list["BacktraceNode"]) -> None: if "parent" in dikt: self.parent = nodes[dikt["parent"]] @@ -57,14 +57,14 @@ def __repr__(self) -> str: ) -class BacktraceGraph(object): +class BacktraceGraph: __slots__ = ("nodes", ) - def __init__(self, nodes: List[BacktraceNode]): - self.nodes: List[BacktraceNode] = nodes + def __init__(self, nodes: list[BacktraceNode]): + self.nodes: list[BacktraceNode] = nodes @classmethod - def from_dict(cls, dikt: Dict) -> "BacktraceGraph": + def from_dict(cls, dikt: dict) -> "BacktraceGraph": commands = dikt["commands"] files = list(Path(f) for f in dikt["files"]) nodes = list(BacktraceNode.from_dict(btn, commands, files) for btn in dikt["nodes"]) @@ -79,7 +79,7 @@ def __repr__(self) -> str: ) -class TargetDestination(object): +class TargetDestination: __slots__ = ("path", "backtrace") def __init__(self, path: Path, backtrace: BacktraceNode): @@ -87,7 +87,7 @@ def __init__(self, path: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": path = Path(dikt["path"]) backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, backtrace) @@ -100,15 +100,15 @@ def __repr__(self) -> str: ) -class TargetInstall(object): +class TargetInstall: __slots__ = ("prefix", "destinations") - def __init__(self, prefix: Path, destinations: List[TargetDestination]): + def __init__(self, prefix: Path, destinations: list[TargetDestination]): self.prefix = prefix self.destinations = destinations @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": prefix = Path(dikt["prefix"]["path"]) destinations = list(TargetDestination.from_dict(td, backtraceGraph) for td in dikt["destinations"]) return cls(prefix, destinations) @@ -121,7 +121,7 @@ def __repr__(self) -> str: ) -class TargetLinkFragment(object): +class TargetLinkFragment: __slots__ = ("fragment", "role") def __init__(self, fragment: str, role: LinkFragmentRole): @@ -129,7 +129,7 @@ def __init__(self, fragment: str, role: LinkFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: Dict) -> "TargetLinkFragment": + def from_dict(cls, dikt: dict) -> "TargetLinkFragment": fragment = dikt["fragment"] role = LinkFragmentRole(dikt["role"]) return cls(fragment, role) @@ -142,17 +142,17 @@ def __repr__(self) -> str: ) -class TargetLink(object): +class TargetLink: __slots__ = ("language", "commandFragments", "lto", "sysroot") - def __init__(self, language: str, commandFragments: List[TargetLinkFragment], lto: Optional[bool], sysroot: Optional[Path]): + def __init__(self, language: str, commandFragments: list[TargetLinkFragment], lto: Optional[bool], sysroot: Optional[Path]): self.language = language self.commandFragments = commandFragments self.lto = lto self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: Dict) -> "TargetLink": + def from_dict(cls, dikt: dict) -> "TargetLink": language = dikt["language"] commandFragments = [] if "commandFragments" in dikt: @@ -169,11 +169,11 @@ def __repr__(self) -> str: self.language, self.commandFragments, self.lto, - "'{}'".format(self.sysroot) if self.sysroot else None, + f"'{self.sysroot}'" if self.sysroot else None, ) -class TargetArchiveFragment(object): +class TargetArchiveFragment: __slots__ = ("fragment", "role") def __init__(self, fragment: str, role: ArchiveFragmentRole): @@ -181,7 +181,7 @@ def __init__(self, fragment: str, role: ArchiveFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: Dict) -> "TargetArchiveFragment": + def from_dict(cls, dikt: dict) -> "TargetArchiveFragment": fragment = dikt["fragment"] role = ArchiveFragmentRole(dikt["role"]) return cls(fragment, role) @@ -194,15 +194,15 @@ def __repr__(self) -> str: ) -class TargetArchive(object): +class TargetArchive: __slots__ = ("commandFragments", "lto") - def __init__(self, commandFragments: List[TargetArchiveFragment], lto: Optional[bool]): + def __init__(self, commandFragments: list[TargetArchiveFragment], lto: Optional[bool]): self.commandFragments = commandFragments self.lto = lto @classmethod - def from_dict(cls, dikt: Dict) -> "TargetArchive": + def from_dict(cls, dikt: dict) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) @@ -217,15 +217,15 @@ def __repr__(self) -> str: ) -class TargetSourceGroup(object): +class TargetSourceGroup: __slots__ = ("name", "sources") - def __init__(self, name: str, sources: List["TargetSource"]): + def __init__(self, name: str, sources: list["TargetSource"]): self.name = name self.sources: list[TargetSource] = [] @classmethod - def from_dict(cls, dikt: Dict, target_sources: List["TargetSource"]) -> "TargetSourceGroup": + def from_dict(cls, dikt: dict, target_sources: list["TargetSource"]) -> "TargetSourceGroup": name = dikt["name"] sources = list(target_sources[tsi] for tsi in dikt["sourceIndexes"]) return cls(name, sources) @@ -236,14 +236,14 @@ def __repr__(self) -> str: ) -class TargetCompileFragment(object): +class TargetCompileFragment: __slots__ = ("fragment", ) def __init__(self, fragment: str): self.fragment = fragment @classmethod - def from_dict(cls, dikt: Dict) -> "TargetCompileFragment": + def from_dict(cls, dikt: dict) -> "TargetCompileFragment": fragment = dikt["fragment"] return cls(fragment) @@ -254,7 +254,7 @@ def __repr__(self) -> str: ) -class TargetCompileGroupInclude(object): +class TargetCompileGroupInclude: __slots__ = ("path", "isSystem", "backtrace") def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[BacktraceNode]): @@ -263,7 +263,7 @@ def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[Bac self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": path = Path(dikt["path"]) isSystem = dikt.get("isSystem") backtrace = None @@ -274,13 +274,13 @@ def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompile def __repr__(self) -> str: return "{}(path={}, system={}, backtrace={})".format( type(self).__name__, - "'{}'".format(self.path) if self.path else None, + f"'{self.path}'" if self.path else None, self.isSystem, self.backtrace, ) -class TargetCompileGroupPCH(object): +class TargetCompileGroupPCH: __slots__ = ("header", "backtrace") def __init__(self, header: Path, backtrace: BacktraceNode | None): @@ -288,7 +288,7 @@ def __init__(self, header: Path, backtrace: BacktraceNode | None): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": header = Path(dikt["header"]) backtrace = None if "backtrace" in dikt: @@ -303,7 +303,7 @@ def __repr__(self) -> str: ) -class TargetCompileGroupDefine(object): +class TargetCompileGroupDefine: __slots__ = ("define", "backtrace") def __init__(self, define: str, backtrace: BacktraceNode | None): @@ -311,7 +311,7 @@ def __init__(self, define: str, backtrace: BacktraceNode | None): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": define = dikt["define"] backtrace = None if "backtrace" in dikt: @@ -326,12 +326,12 @@ def __repr__(self) -> str: ) -class TargetCompileGroup(object): +class TargetCompileGroup: __slots__ = ("sources", "language", "compileCommandFragments", "includes", "precompileHeaders", "defines", "sysroot") - def __init__(self, sources: List["TargetSource"], language: str, - compileCommandFragments: List[TargetCompileFragment], includes: List[TargetCompileGroupInclude], - precompileHeaders: List[TargetCompileGroupPCH], defines: List[TargetCompileGroupDefine], + def __init__(self, sources: list["TargetSource"], language: str, + compileCommandFragments: list[TargetCompileFragment], includes: list[TargetCompileGroupInclude], + precompileHeaders: list[TargetCompileGroupPCH], defines: list[TargetCompileGroupDefine], sysroot: Optional[Path]): self.sources = sources self.language = language @@ -342,7 +342,7 @@ def __init__(self, sources: List["TargetSource"], language: str, self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: Dict, target_sources: List["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": + def from_dict(cls, dikt: dict, target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": language = dikt["language"] compileCommandFragments = list(TargetCompileFragment.from_dict(tcf) for tcf in dikt.get("compileCommandFragments", ())) includes = list(TargetCompileGroupInclude.from_dict(tci, backtraceGraph) for tci in dikt.get("includes", ())) @@ -361,11 +361,11 @@ def __repr__(self) -> str: len(self.includes), len(self.precompileHeaders), len(self.defines), - "'{}'".format(self.sysroot) if self.sysroot else None, + f"'{self.sysroot}'" if self.sysroot else None, ) -class TargetDependency(object): +class TargetDependency: __slots__ = ("id", "target", "backtrace") def __init__(self, id: str, backtrace: Optional[BacktraceNode]): @@ -373,11 +373,11 @@ def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.target: CodemodelTargetV2 | None = None self.backtrace = backtrace - def update_dependency(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): + def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): self.target = lut_id_target[self.id] @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": id = dikt["id"] backtrace = None if "backtrace" in dikt: @@ -393,7 +393,7 @@ def __repr__(self) -> str: ) -class TargetSource(object): +class TargetSource: __slots__ = ("path", "isGenerated", "backtrace", "compileGroup", "sourceGroup") def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[BacktraceNode]): @@ -404,7 +404,7 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.sourceGroup = None # type: Optional[TargetSourceGroup] @classmethod - def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetSource": + def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": path = Path(dikt["path"]) isGenerated = dikt.get("isGenerated") backtrace = None @@ -412,7 +412,7 @@ def from_dict(cls, dikt: Dict, backtraceGraph: BacktraceGraph) -> "TargetSource" backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, isGenerated, backtrace) - def update_from_dict(self, dikt: Dict, modelTarget: "CodemodelTargetV2"): + def update_from_dict(self, dikt: dict, modelTarget: "CodemodelTargetV2"): if "compileGroupIndex" in dikt: self.compileGroup = modelTarget.compileGroups[dikt["compileGroupIndex"]] if "sourceGroupIndex" in dikt: @@ -429,17 +429,17 @@ def __repr__(self) -> str: ) -class CodemodelTargetV2(object): +class CodemodelTargetV2: __slots__ = ("name", "id", "type", "backtrace", "folder", "paths", "nameOnDisk", "artifacts", "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Path, - paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: List[Path], + paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], - dependencies: List[TargetDependency], sources: List[TargetSource], - sourceGroups: List[TargetSourceGroup], compileGroups: List[TargetCompileGroup]): + dependencies: list[TargetDependency], sources: list[TargetSource], + sourceGroups: list[TargetSourceGroup], compileGroups: list[TargetCompileGroup]): self.name = name self.id = id self.type = type @@ -457,12 +457,12 @@ def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNod self.sourceGroups = sourceGroups self.compileGroups = compileGroups - def update_dependencies(self, lut_id_target: Dict[str, "CodemodelTargetV2"]): + def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]): for dependency in self.dependencies: dependency.update_dependency(lut_id_target) @classmethod - def from_dict(cls, dikt: Dict) -> "CodemodelTargetV2": + def from_dict(cls, dikt: dict) -> "CodemodelTargetV2": name = dikt["name"] id = dikt["id"] type = TargetType(dikt["type"]) diff --git a/cmake_file_api/kinds/configureLog/v1.py b/cmake_file_api/kinds/configureLog/v1.py index 9754c66..1e9eab0 100644 --- a/cmake_file_api/kinds/configureLog/v1.py +++ b/cmake_file_api/kinds/configureLog/v1.py @@ -7,18 +7,18 @@ from .target.v2 import CodemodelTargetV2 -class ConfigureLogV1(object): +class ConfigureLogV1: KIND = ObjectKind.CONFIGURELOG __slots__ = ("version", "path", "eventKindNames") - def __init__(self, version: VersionMajorMinor, path: Path, eventKindNames: List[str]): + def __init__(self, version: VersionMajorMinor, path: Path, eventKindNames: list[str]): self.version = version self.path = path self.eventKindNames = eventKindNames @classmethod - def from_dict(cls, dikt: Dict[str, Any], reply_path: Path) -> "ConfigureLogV1": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ConfigureLogV1": if dikt["kind"] != cls.KIND.value: raise ValueError path = Path(dikt["path"]) diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index c276cf9..e0d0242 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -6,7 +6,7 @@ from cmake_file_api.kinds.kind import ObjectKind -class CMakeToolchainCompilerImplicit(object): +class CMakeToolchainCompilerImplicit: __slots__ = ("includeDirectories", "linkDirectories", "linkFrameworkDirectories", "linkLibraries") def __init__(self): @@ -16,7 +16,7 @@ def __init__(self): self.linkLibraries = [] # type: List[str] @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeToolchainCompilerImplicit": + def from_dict(cls, dikt: dict) -> "CMakeToolchainCompilerImplicit": res = cls() if "includeDirectories" in dikt: res.includeDirectories.extend(Path(p) for p in dikt["includeDirectories"]) @@ -29,7 +29,7 @@ def from_dict(cls, dikt: Dict) -> "CMakeToolchainCompilerImplicit": return res -class CMakeToolchainCompiler(object): +class CMakeToolchainCompiler: __slots__ = ("id", "path", "target", "version", "implicit") def __init__(self, id: Optional[str], path: Optional[Path], target: Optional[str], version: Optional[str], implicit: CMakeToolchainCompilerImplicit): @@ -40,7 +40,7 @@ def __init__(self, id: Optional[str], path: Optional[Path], target: Optional[str self.implicit = implicit @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeToolchainCompiler": + def from_dict(cls, dikt: dict) -> "CMakeToolchainCompiler": id = dikt.get("id") path = Path(dikt["path"]) if "path" in dikt else None target = dikt.get("target") @@ -58,16 +58,16 @@ def __repr__(self) -> str: ) -class CMakeToolchain(object): +class CMakeToolchain: __slots__ = ("language", "compiler", "sourceFileExtensions") - def __init__(self, language: str, compiler: CMakeToolchainCompiler, sourceFileExtensions: Optional[List[str]]): + def __init__(self, language: str, compiler: CMakeToolchainCompiler, sourceFileExtensions: Optional[list[str]]): self.language = language self.compiler = compiler self.sourceFileExtensions = sourceFileExtensions @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeToolchain": + def from_dict(cls, dikt: dict) -> "CMakeToolchain": language = dikt["language"] compiler = CMakeToolchainCompiler.from_dict(dikt["compiler"]) sourceFileExtensions = dikt.get("sourceFileExtensions") @@ -82,17 +82,17 @@ def __repr__(self) -> str: ) -class ToolchainsV1(object): +class ToolchainsV1: KIND = ObjectKind.TOOLCHAINS __slots__ = ("version", "toolchains") - def __init__(self, version: VersionMajorMinor, toolchains: List[CMakeToolchain]): + def __init__(self, version: VersionMajorMinor, toolchains: list[CMakeToolchain]): self.version = version self.toolchains = toolchains @classmethod - def from_dict(cls, dikt: Dict, reply_path: Path) -> "ToolchainsV1": + def from_dict(cls, dikt: dict, reply_path: Path) -> "ToolchainsV1": version = VersionMajorMinor.from_dict(dikt["version"]) toolchains = list(CMakeToolchain.from_dict(cmi) for cmi in dikt["toolchains"]) return cls(version, toolchains) diff --git a/cmake_file_api/reply/index/file/v1.py b/cmake_file_api/reply/index/file/v1.py index 3c30d2d..c5e839d 100644 --- a/cmake_file_api/reply/index/file/v1.py +++ b/cmake_file_api/reply/index/file/v1.py @@ -5,14 +5,14 @@ from cmake_file_api.kinds.common import VersionMajorMinor -class CMakeReplyFileReferenceV1(object): +class CMakeReplyFileReferenceV1: def __init__(self, kind: ObjectKind, version: VersionMajorMinor, jsonFile: Path): self.kind = kind self.version = version self.jsonFile = jsonFile @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeReplyFileReferenceV1": + def from_dict(cls, dikt: dict) -> "CMakeReplyFileReferenceV1": kind = ObjectKind(dikt["kind"]) version = VersionMajorMinor.from_dict(dikt["version"]) jsonFile = Path(dikt["jsonFile"]) diff --git a/cmake_file_api/reply/index/v1.py b/cmake_file_api/reply/index/v1.py index d3cfed0..762f5d4 100644 --- a/cmake_file_api/reply/index/v1.py +++ b/cmake_file_api/reply/index/v1.py @@ -8,7 +8,7 @@ from .file.v1 import CMakeReplyFileReferenceV1 -class CMakeGenerator(object): +class CMakeGenerator: __slots__ = ("name", "multiConfig") def __init__(self, name: str, multiConfig: bool): @@ -16,7 +16,7 @@ def __init__(self, name: str, multiConfig: bool): self.multiConfig = multiConfig @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeGenerator": + def from_dict(cls, dikt: dict) -> "CMakeGenerator": name = dikt["name"] multiConfig = dikt["multiConfig"] return cls(name, multiConfig) @@ -29,7 +29,7 @@ def __repr__(self) -> str: ) -class CMakeVersion(object): +class CMakeVersion: def __init__(self, major: int, minor: int, patch: int, string: str, suffix: str, isDirty: bool): self.major = major self.minor = minor @@ -39,7 +39,7 @@ def __init__(self, major: int, minor: int, patch: int, string: str, suffix: str, self.isDirty = isDirty @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeVersion": + def from_dict(cls, dikt: dict) -> "CMakeVersion": major = dikt["major"] minor = dikt["minor"] patch = dikt["patch"] @@ -60,7 +60,7 @@ def __repr__(self) -> str: ) -class CMakePaths(object): +class CMakePaths: __slots__ = ("cmake", "cpack", "ctest", "root") def __init__(self, cmake: Path, cpack: Path, ctest: Path, root: Path): @@ -70,7 +70,7 @@ def __init__(self, cmake: Path, cpack: Path, ctest: Path, root: Path): self.root = root @classmethod - def from_dict(cls, dikt: Dict) -> "CMakePaths": + def from_dict(cls, dikt: dict) -> "CMakePaths": cmake = Path(dikt["cmake"]) cpack = Path(dikt["cpack"]) ctest = Path(dikt["ctest"]) @@ -87,7 +87,7 @@ def __str__(self) -> str: ) -class CMakeInfo(object): +class CMakeInfo: __slots__ = ("version", "paths", "generator") def __init__(self, version: CMakeVersion, paths: CMakePaths, generator: CMakeGenerator): @@ -96,7 +96,7 @@ def __init__(self, version: CMakeVersion, paths: CMakePaths, generator: CMakeGen self.generator = generator @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeInfo": + def from_dict(cls, dikt: dict) -> "CMakeInfo": version = CMakeVersion.from_dict(dikt["version"]) paths = CMakePaths.from_dict(dikt["paths"]) generator = CMakeGenerator.from_dict(dikt["generator"]) @@ -111,17 +111,17 @@ def __str__(self) -> str: ) -class CMakeReply(object): +class CMakeReply: __slots__ = ("stateless", "stateful", "unknowns") - def __init__(self, stateless: Dict[Tuple[ObjectKind, int], CMakeReplyFileReferenceV1], - stateful: Dict[str, Dict], unknowns: List[str]): + def __init__(self, stateless: dict[tuple[ObjectKind, int], CMakeReplyFileReferenceV1], + stateful: dict[str, dict], unknowns: list[str]): self.stateless = stateless self.stateful = stateful self.unknowns = unknowns @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeReply": + def from_dict(cls, dikt: dict) -> "CMakeReply": stateless = {} stateful = {} unknowns = [] @@ -141,16 +141,16 @@ def from_dict(cls, dikt: Dict) -> "CMakeReply": return cls(stateless, stateful, unknowns) -class CMakeReplyFileV1(object): +class CMakeReplyFileV1: __slots__ = ("cmake", "objects", "reply") - def __init__(self, cmake: CMakeInfo, objects: List[CMakeReplyFileReferenceV1], reply: CMakeReply): + def __init__(self, cmake: CMakeInfo, objects: list[CMakeReplyFileReferenceV1], reply: CMakeReply): self.cmake = cmake self.objects = objects self.reply = reply @classmethod - def from_dict(cls, dikt: Dict) -> "CMakeReplyFileV1": + def from_dict(cls, dikt: dict) -> "CMakeReplyFileV1": cmake = CMakeInfo.from_dict(dikt["cmake"]) objects = list(CMakeReplyFileReferenceV1.from_dict(do) for do in dikt["objects"]) reply = CMakeReply.from_dict(dikt["reply"]) diff --git a/cmake_file_api/reply/v1/api.py b/cmake_file_api/reply/v1/api.py index a48a20d..be74b1c 100644 --- a/cmake_file_api/reply/v1/api.py +++ b/cmake_file_api/reply/v1/api.py @@ -7,7 +7,7 @@ from cmake_file_api.kinds.kind import ObjectKind -class CMakeFileApiV1(object): +class CMakeFileApiV1: __slots__ = ("_build_path", ) def __init__(self, build_path: Path): @@ -17,19 +17,19 @@ def _create_query_path(self) -> Path: result = self._build_path / ".cmake" / "api" / "v1" / "query" result.mkdir(parents=True, exist_ok=True) if not result.is_dir(): - raise NotADirectoryError("Query path '{}' is not a directory".format(result)) + raise NotADirectoryError(f"Query path '{result}' is not a directory") return result def _create_reply_path(self) -> Path: result = self._build_path / ".cmake" / "api" / "v1" / "reply" result.mkdir(parents=True, exist_ok=True) if not result.is_dir(): - raise NotADirectoryError("Reply path '{}' is not a directory".format(result)) + raise NotADirectoryError(f"Reply path '{result}' is not a directory") return result @staticmethod def _instrument_query_path(query_path: Path, kind: ObjectKind, kind_version: int) -> None: - (query_path / "{}-v{}".format(kind.value, kind_version)).touch() + (query_path / f"{kind.value}-v{kind_version}").touch() @staticmethod def _find_index_path(reply_path: Path) -> Optional[Path]: @@ -78,7 +78,7 @@ def inspect(self, kind: ObjectKind, kind_version: int): return None return api.from_path(reply_path / str(data_path.jsonFile), reply_path) - def inspect_all(self) -> Dict[ObjectKind, Dict[int, object]]: + def inspect_all(self) -> dict[ObjectKind, dict[int, object]]: reply_path = self._create_reply_path() index = self._index(reply_path) From 3d6d088d4358d2883e7ceaa420a96f04e082a89f Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 15:17:33 +0200 Subject: [PATCH 04/13] add ci job --- .github/workflows/ci.yml | 36 +++++++++++++++++++++++------------- mypy.ini | 3 +++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2de99c3..65333eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,23 +5,33 @@ on: release: types: published schedule: - - cron: 0 0 1 * * # Run once every month + - cron: 0 0 1 * * # Run once every month jobs: run-pytest: strategy: fail-fast: false matrix: - py: ['3.8', '3.9', '3.10', '3.11', '3.12'] - os: ['ubuntu-latest', 'windows-latest', 'macos-latest'] + py: [ '3.9', '3.10', '3.11', '3.12' ] + os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.py }} - - name: "Install requirements" - run: | - python -m pip install -r requirements-dev.txt - - name: "Run pytest" - run: | - pytest + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.py }} + - name: "Install requirements" + run: | + python -m pip install -r requirements-dev.txt + - name: "Run pytest" + run: | + pytest + + check-typing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.9" + - run: pip install mypy + - run: mypy --install-types --non-interactive diff --git a/mypy.ini b/mypy.ini index e69de29..601a8be 100644 --- a/mypy.ini +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] + +files = cmake_file_api From 9b866d2074bf4849cd0f1510cb47eac545da6873 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 15:17:45 +0200 Subject: [PATCH 05/13] fix more type errors --- cmake_file_api/kinds/cmakeFiles/v1.py | 4 ++-- cmake_file_api/kinds/codemodel/target/v2.py | 10 +++++----- cmake_file_api/kinds/configureLog/target/v2.py | 10 +++++----- cmake_file_api/kinds/configureLog/v1.py | 4 ++-- cmake_file_api/kinds/toolchains/v1.py | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index 9d81bac..d101bb3 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -44,14 +44,14 @@ def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inp self.inputs = inputs @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "CmakeFilesV2": + def from_dict(cls, dikt: dict, reply_path: Path) -> "CMakeFilesV1": version = VersionMajorMinor.from_dict(dikt["version"]) paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) inputs = list(CMakeFilesInput.from_dict(cmi) for cmi in dikt["inputs"]) return cls(version, paths, inputs) @classmethod - def from_path(cls, path: Path, reply_path: Path) -> "CmakeFilesV2": + def from_path(cls, path: Path, reply_path: Path) -> "CMakeFilesV1": dikt = json.load(path.open()) return cls.from_dict(dikt, reply_path) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index e3adacf..14d65a6 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -221,9 +221,9 @@ def __repr__(self) -> str: class TargetSourceGroup: __slots__ = ("name", "sources") - def __init__(self, name: str, sources: list["TargetSource"]): + def __init__(self, name: str, sources: list[TargetSource]): self.name = name - self.sources = [] + self.sources: list[TargetSource] = [] @classmethod def from_dict(cls, dikt: dict, target_sources: list["TargetSource"]) -> "TargetSourceGroup": @@ -371,7 +371,7 @@ class TargetDependency: def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.id = id - self.target = None # type: CodemodelTargetV2 + self.target = None # type: Optional[CodemodelTargetV2] self.backtrace = backtrace def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): @@ -389,7 +389,7 @@ def __repr__(self) -> str: return "{}(id='{}', target='{}', backtrace={})".format( type(self).__name__, self.id, - self.target.name, + self.target.name if self.target else None, self.backtrace, ) @@ -475,7 +475,7 @@ def from_dict(cls, dikt: dict, reply_path: Path) -> "CodemodelTargetV2": if "folder" in dikt: folder = Path(dikt["folder"]["name"]) paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) - nameOnDisk = dikt.get("nameOnDisk", None) + nameOnDisk = dikt.get("nameOnDisk", "") artifacts = list(Path(p["path"]) for p in dikt.get("artifacts", ())) isGeneratorProvided = dikt.get("isGeneratorProvided") install = None diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index 9c9eafd..bd19c7f 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -388,7 +388,7 @@ def __repr__(self) -> str: return "{}(id='{}', target='{}', backtrace={})".format( type(self).__name__, self.id, - self.target.name, + self.target.name if self.target else None, self.backtrace, ) @@ -467,14 +467,14 @@ def from_dict(cls, dikt: dict) -> "CodemodelTargetV2": id = dikt["id"] type = TargetType(dikt["type"]) backtraceGraph = BacktraceGraph.from_dict(dikt["backtraceGraph"]) - backtrace = None + backtrace: Optional[BacktraceNode] = None if "backtrace" in dikt: backtrace = backtraceGraph.nodes[dikt["backtrace"]] folder = None if "folder" in dikt: folder = Path(dikt["folder"]["name"]) paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) - nameOnDisk = dikt.get("nameOnDisk", None) + nameOnDisk = dikt.get("nameOnDisk", "") artifacts = list(Path(p["path"]) for p in dikt.get("artifacts", ())) isGeneratorProvided = dikt.get("isGeneratorProvided") install = None @@ -497,9 +497,9 @@ def from_dict(cls, dikt: dict) -> "CodemodelTargetV2": isGeneratorProvided, install, link, archive, dependencies, sources, sourceGroups, compileGroups) @classmethod - def from_path(cls, file: Path, reply_path: Path) -> "CodemodelTargetV2": + def from_path(cls, file: Path) -> "CodemodelTargetV2": dikt = json.load(file.open()) - return cls.from_dict(dikt, reply_path) + return cls.from_dict(dikt) def __repr__(self) -> str: return "{}(name='{}', type={}, backtrace={})".format( diff --git a/cmake_file_api/kinds/configureLog/v1.py b/cmake_file_api/kinds/configureLog/v1.py index 1e9eab0..ae9f2d5 100644 --- a/cmake_file_api/kinds/configureLog/v1.py +++ b/cmake_file_api/kinds/configureLog/v1.py @@ -35,6 +35,6 @@ def __repr__(self) -> str: return "{}(version={}, paths={}, configurations={})".format( type(self).__name__, self.version, - self.paths, - self.configurations, + self.path, + self.eventKindNames, ) diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index e0d0242..c4db7a2 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -9,7 +9,7 @@ class CMakeToolchainCompilerImplicit: __slots__ = ("includeDirectories", "linkDirectories", "linkFrameworkDirectories", "linkLibraries") - def __init__(self): + def __init__(self) -> None: self.includeDirectories = [] # type: List[Path] self.linkDirectories = [] # type: List[Path] self.linkFrameworkDirectories = [] # type: List[Path] From e6037da822e9f4796490a8fa56cbd84deaa7b841 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 17:10:32 +0200 Subject: [PATCH 06/13] remove unused imports --- cmake_file_api/__init__.py | 2 ++ cmake_file_api/cmake.py | 2 +- cmake_file_api/kinds/cache/__init__.py | 2 ++ cmake_file_api/kinds/cache/v2.py | 1 - cmake_file_api/kinds/cmakeFiles/v1.py | 2 +- cmake_file_api/kinds/codemodel/target/v2.py | 3 ++- cmake_file_api/kinds/codemodel/v2.py | 2 +- cmake_file_api/kinds/common.py | 1 - cmake_file_api/kinds/configureLog/target/v2.py | 2 +- cmake_file_api/kinds/configureLog/v1.py | 5 ++--- cmake_file_api/kinds/toolchains/v1.py | 2 +- cmake_file_api/reply/index/file/v1.py | 1 - cmake_file_api/reply/index/v1.py | 1 - cmake_file_api/reply/v1/api.py | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmake_file_api/__init__.py b/cmake_file_api/__init__.py index a9bcfc1..1aa5190 100644 --- a/cmake_file_api/__init__.py +++ b/cmake_file_api/__init__.py @@ -1,3 +1,5 @@ from .cmake import CMakeProject from .errors import CMakeException from .kinds.kind import ObjectKind + +__all__ = ["CMakeProject", "CMakeException", "ObjectKind"] diff --git a/cmake_file_api/cmake.py b/cmake_file_api/cmake.py index d1c00e8..c9af208 100644 --- a/cmake_file_api/cmake.py +++ b/cmake_file_api/cmake.py @@ -1,6 +1,6 @@ from pathlib import Path import subprocess -from typing import List, Optional, Union +from typing import Optional, Union from .reply.api import REPLY_API from .reply.v1.api import CMakeFileApiV1 diff --git a/cmake_file_api/kinds/cache/__init__.py b/cmake_file_api/kinds/cache/__init__.py index 16a6596..9a24926 100644 --- a/cmake_file_api/kinds/cache/__init__.py +++ b/cmake_file_api/kinds/cache/__init__.py @@ -1 +1,3 @@ from .api import CACHE_API + +__all__ = ["CACHE_API"] diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index 97835ce..89ade59 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -1,7 +1,6 @@ from enum import Enum import json from pathlib import Path -from typing import Dict, List from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index d101bb3..103fdf2 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 14d65a6..5c21980 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -1,9 +1,10 @@ import enum import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths +from cmake_file_api.kinds.configureLog.target.v2 import TargetSource class TargetType(enum.Enum): diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index 8ecca0a..d7f68e3 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind diff --git a/cmake_file_api/kinds/common.py b/cmake_file_api/kinds/common.py index 0beeef6..22cf9a5 100644 --- a/cmake_file_api/kinds/common.py +++ b/cmake_file_api/kinds/common.py @@ -1,5 +1,4 @@ from pathlib import Path -from typing import Dict class VersionMajorMinor: diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index bd19c7f..f30659c 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -1,7 +1,7 @@ import enum import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths diff --git a/cmake_file_api/kinds/configureLog/v1.py b/cmake_file_api/kinds/configureLog/v1.py index ae9f2d5..13a1187 100644 --- a/cmake_file_api/kinds/configureLog/v1.py +++ b/cmake_file_api/kinds/configureLog/v1.py @@ -1,10 +1,9 @@ import json from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any -from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor +from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind -from .target.v2 import CodemodelTargetV2 class ConfigureLogV1: diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index c4db7a2..113c93f 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Dict, List, Optional +from typing import Optional from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind diff --git a/cmake_file_api/reply/index/file/v1.py b/cmake_file_api/reply/index/file/v1.py index c5e839d..8e22cbf 100644 --- a/cmake_file_api/reply/index/file/v1.py +++ b/cmake_file_api/reply/index/file/v1.py @@ -1,5 +1,4 @@ from pathlib import Path -from typing import Dict from cmake_file_api.kinds.kind import ObjectKind from cmake_file_api.kinds.common import VersionMajorMinor diff --git a/cmake_file_api/reply/index/v1.py b/cmake_file_api/reply/index/v1.py index 762f5d4..0af3e5b 100644 --- a/cmake_file_api/reply/index/v1.py +++ b/cmake_file_api/reply/index/v1.py @@ -1,7 +1,6 @@ import json from pathlib import Path import re -from typing import Dict, List, Tuple from cmake_file_api.kinds.kind import ObjectKind diff --git a/cmake_file_api/reply/v1/api.py b/cmake_file_api/reply/v1/api.py index be74b1c..5bfea44 100644 --- a/cmake_file_api/reply/v1/api.py +++ b/cmake_file_api/reply/v1/api.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Dict, Optional +from typing import Optional from cmake_file_api.errors import CMakeException from cmake_file_api.kinds.api import OBJECT_KINDS_API From 38a8e98172ade43ed829a957d1d4fdb68b75314d Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 17:15:56 +0200 Subject: [PATCH 07/13] replace dict with dict[str,Any] --- cmake_file_api/kinds/cache/v2.py | 5 +++-- cmake_file_api/kinds/cmakeFiles/v1.py | 4 ++-- cmake_file_api/kinds/codemodel/target/v2.py | 14 +++++++------- cmake_file_api/kinds/codemodel/v2.py | 2 +- cmake_file_api/kinds/configureLog/target/v2.py | 16 ++++++++-------- cmake_file_api/kinds/toolchains/v1.py | 8 ++++---- cmake_file_api/reply/index/file/v1.py | 3 ++- cmake_file_api/reply/index/v1.py | 14 +++++++------- 8 files changed, 34 insertions(+), 32 deletions(-) diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index 89ade59..32eb470 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -1,6 +1,7 @@ from enum import Enum import json from pathlib import Path +from typing import Any from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -24,7 +25,7 @@ def __init__(self, name: str, value: str): self.value = value @classmethod - def from_dict(cls, dikt: dict) -> "CacheEntryProperty": + def from_dict(cls, dikt: dict[str, Any]) -> "CacheEntryProperty": name = dikt["name"] value = dikt["value"] return cls(name, value) @@ -47,7 +48,7 @@ def __init__(self, name: str, value: str, type: CacheEntryType, properties: list self.properties = properties @classmethod - def from_dict(cls, dikt: dict) -> "CacheEntry": + def from_dict(cls, dikt: dict[str, Any]) -> "CacheEntry": name = dikt["name"] value = dikt["value"] type = CacheEntryType(dikt["type"]) diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index 103fdf2..a52a71a 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Optional +from typing import Any, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -16,7 +16,7 @@ def __init__(self, path: Path, isGenerator: Optional[bool], isExternal: Optional self.isCMake = isCMake @classmethod - def from_dict(cls, dikt: dict) -> "CMakeFilesInput": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeFilesInput": path = Path(dikt["path"]) isGenerator = dikt.get("isGenerator") isExternal = dikt.get("isExternal") diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 5c21980..4f22d3b 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -1,7 +1,7 @@ import enum import json from pathlib import Path -from typing import Optional +from typing import Any, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths from cmake_file_api.kinds.configureLog.target.v2 import TargetSource @@ -66,7 +66,7 @@ def __init__(self, nodes: list[BacktraceNode]): self.nodes = nodes @classmethod - def from_dict(cls, dikt: dict) -> "BacktraceGraph": + def from_dict(cls, dikt: dict[str, Any]) -> "BacktraceGraph": commands = dikt["commands"] files = list(Path(f) for f in dikt["files"]) nodes = list(BacktraceNode.from_dict(btn, commands, files) for btn in dikt["nodes"]) @@ -131,7 +131,7 @@ def __init__(self, fragment: str, role: LinkFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: dict) -> "TargetLinkFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetLinkFragment": fragment = dikt["fragment"] role = LinkFragmentRole(dikt["role"]) return cls(fragment, role) @@ -154,7 +154,7 @@ def __init__(self, language: str, commandFragments: list[TargetLinkFragment], lt self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: dict) -> "TargetLink": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetLink": language = dikt["language"] commandFragments = [] if "commandFragments" in dikt: @@ -183,7 +183,7 @@ def __init__(self, fragment: str, role: ArchiveFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: dict) -> "TargetArchiveFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetArchiveFragment": fragment = dikt["fragment"] role = ArchiveFragmentRole(dikt["role"]) return cls(fragment, role) @@ -204,7 +204,7 @@ def __init__(self, commandFragments: list[TargetArchiveFragment], lto: Optional[ self.lto = lto @classmethod - def from_dict(cls, dikt: dict) -> "TargetArchive": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) @@ -245,7 +245,7 @@ def __init__(self, fragment: str): self.fragment = fragment @classmethod - def from_dict(cls, dikt: dict) -> "TargetCompileFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetCompileFragment": fragment = dikt["fragment"] return cls(fragment) diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index d7f68e3..78b6983 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -54,7 +54,7 @@ def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str] self.hasInstallRule = hasInstallRule @classmethod - def from_dict(cls, dikt: dict) -> "CMakeDirectory": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeDirectory": source = Path(dikt["source"]) build = Path(dikt["build"]) minimumCMakeVersion = dikt.get("minimumCMakeVersion", None) diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index f30659c..11538ac 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -1,7 +1,7 @@ import enum import json from pathlib import Path -from typing import Optional +from typing import Any, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths @@ -64,7 +64,7 @@ def __init__(self, nodes: list[BacktraceNode]): self.nodes: list[BacktraceNode] = nodes @classmethod - def from_dict(cls, dikt: dict) -> "BacktraceGraph": + def from_dict(cls, dikt: dict[str, Any]) -> "BacktraceGraph": commands = dikt["commands"] files = list(Path(f) for f in dikt["files"]) nodes = list(BacktraceNode.from_dict(btn, commands, files) for btn in dikt["nodes"]) @@ -129,7 +129,7 @@ def __init__(self, fragment: str, role: LinkFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: dict) -> "TargetLinkFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetLinkFragment": fragment = dikt["fragment"] role = LinkFragmentRole(dikt["role"]) return cls(fragment, role) @@ -152,7 +152,7 @@ def __init__(self, language: str, commandFragments: list[TargetLinkFragment], lt self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: dict) -> "TargetLink": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetLink": language = dikt["language"] commandFragments = [] if "commandFragments" in dikt: @@ -181,7 +181,7 @@ def __init__(self, fragment: str, role: ArchiveFragmentRole): self.role = role @classmethod - def from_dict(cls, dikt: dict) -> "TargetArchiveFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetArchiveFragment": fragment = dikt["fragment"] role = ArchiveFragmentRole(dikt["role"]) return cls(fragment, role) @@ -202,7 +202,7 @@ def __init__(self, commandFragments: list[TargetArchiveFragment], lto: Optional[ self.lto = lto @classmethod - def from_dict(cls, dikt: dict) -> "TargetArchive": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetArchive": commandFragments = [] if "commandFragments" in dikt: commandFragments = list(TargetArchiveFragment.from_dict(tlf) for tlf in dikt["commandFragments"]) @@ -243,7 +243,7 @@ def __init__(self, fragment: str): self.fragment = fragment @classmethod - def from_dict(cls, dikt: dict) -> "TargetCompileFragment": + def from_dict(cls, dikt: dict[str, Any]) -> "TargetCompileFragment": fragment = dikt["fragment"] return cls(fragment) @@ -462,7 +462,7 @@ def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]): dependency.update_dependency(lut_id_target) @classmethod - def from_dict(cls, dikt: dict) -> "CodemodelTargetV2": + def from_dict(cls, dikt: dict[str, Any]) -> "CodemodelTargetV2": name = dikt["name"] id = dikt["id"] type = TargetType(dikt["type"]) diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index 113c93f..bac2c8f 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Optional +from typing import Any, Optional from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -16,7 +16,7 @@ def __init__(self) -> None: self.linkLibraries = [] # type: List[str] @classmethod - def from_dict(cls, dikt: dict) -> "CMakeToolchainCompilerImplicit": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeToolchainCompilerImplicit": res = cls() if "includeDirectories" in dikt: res.includeDirectories.extend(Path(p) for p in dikt["includeDirectories"]) @@ -40,7 +40,7 @@ def __init__(self, id: Optional[str], path: Optional[Path], target: Optional[str self.implicit = implicit @classmethod - def from_dict(cls, dikt: dict) -> "CMakeToolchainCompiler": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeToolchainCompiler": id = dikt.get("id") path = Path(dikt["path"]) if "path" in dikt else None target = dikt.get("target") @@ -67,7 +67,7 @@ def __init__(self, language: str, compiler: CMakeToolchainCompiler, sourceFileEx self.sourceFileExtensions = sourceFileExtensions @classmethod - def from_dict(cls, dikt: dict) -> "CMakeToolchain": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeToolchain": language = dikt["language"] compiler = CMakeToolchainCompiler.from_dict(dikt["compiler"]) sourceFileExtensions = dikt.get("sourceFileExtensions") diff --git a/cmake_file_api/reply/index/file/v1.py b/cmake_file_api/reply/index/file/v1.py index 8e22cbf..22f539b 100644 --- a/cmake_file_api/reply/index/file/v1.py +++ b/cmake_file_api/reply/index/file/v1.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Any from cmake_file_api.kinds.kind import ObjectKind from cmake_file_api.kinds.common import VersionMajorMinor @@ -11,7 +12,7 @@ def __init__(self, kind: ObjectKind, version: VersionMajorMinor, jsonFile: Path) self.jsonFile = jsonFile @classmethod - def from_dict(cls, dikt: dict) -> "CMakeReplyFileReferenceV1": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeReplyFileReferenceV1": kind = ObjectKind(dikt["kind"]) version = VersionMajorMinor.from_dict(dikt["version"]) jsonFile = Path(dikt["jsonFile"]) diff --git a/cmake_file_api/reply/index/v1.py b/cmake_file_api/reply/index/v1.py index 0af3e5b..30547af 100644 --- a/cmake_file_api/reply/index/v1.py +++ b/cmake_file_api/reply/index/v1.py @@ -1,7 +1,7 @@ import json from pathlib import Path import re - +from typing import Any from cmake_file_api.kinds.kind import ObjectKind from .file.v1 import CMakeReplyFileReferenceV1 @@ -15,7 +15,7 @@ def __init__(self, name: str, multiConfig: bool): self.multiConfig = multiConfig @classmethod - def from_dict(cls, dikt: dict) -> "CMakeGenerator": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeGenerator": name = dikt["name"] multiConfig = dikt["multiConfig"] return cls(name, multiConfig) @@ -38,7 +38,7 @@ def __init__(self, major: int, minor: int, patch: int, string: str, suffix: str, self.isDirty = isDirty @classmethod - def from_dict(cls, dikt: dict) -> "CMakeVersion": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeVersion": major = dikt["major"] minor = dikt["minor"] patch = dikt["patch"] @@ -69,7 +69,7 @@ def __init__(self, cmake: Path, cpack: Path, ctest: Path, root: Path): self.root = root @classmethod - def from_dict(cls, dikt: dict) -> "CMakePaths": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakePaths": cmake = Path(dikt["cmake"]) cpack = Path(dikt["cpack"]) ctest = Path(dikt["ctest"]) @@ -95,7 +95,7 @@ def __init__(self, version: CMakeVersion, paths: CMakePaths, generator: CMakeGen self.generator = generator @classmethod - def from_dict(cls, dikt: dict) -> "CMakeInfo": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeInfo": version = CMakeVersion.from_dict(dikt["version"]) paths = CMakePaths.from_dict(dikt["paths"]) generator = CMakeGenerator.from_dict(dikt["generator"]) @@ -120,7 +120,7 @@ def __init__(self, stateless: dict[tuple[ObjectKind, int], CMakeReplyFileReferen self.unknowns = unknowns @classmethod - def from_dict(cls, dikt: dict) -> "CMakeReply": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeReply": stateless = {} stateful = {} unknowns = [] @@ -149,7 +149,7 @@ def __init__(self, cmake: CMakeInfo, objects: list[CMakeReplyFileReferenceV1], r self.reply = reply @classmethod - def from_dict(cls, dikt: dict) -> "CMakeReplyFileV1": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeReplyFileV1": cmake = CMakeInfo.from_dict(dikt["cmake"]) objects = list(CMakeReplyFileReferenceV1.from_dict(do) for do in dikt["objects"]) reply = CMakeReply.from_dict(dikt["reply"]) From 1fcd7d704a73939086cf1849abacea7defd47f30 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 17:20:45 +0200 Subject: [PATCH 08/13] com2ann: comments to native annotations --- cmake_file_api/kinds/codemodel/target/v2.py | 6 +++--- cmake_file_api/kinds/codemodel/v2.py | 16 ++++++++-------- cmake_file_api/kinds/configureLog/target/v2.py | 4 ++-- cmake_file_api/kinds/toolchains/v1.py | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 4f22d3b..4222d70 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -372,7 +372,7 @@ class TargetDependency: def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.id = id - self.target = None # type: Optional[CodemodelTargetV2] + self.target: Optional[CodemodelTargetV2] = None self.backtrace = backtrace def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): @@ -402,8 +402,8 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.path = path self.isGenerated = isGenerated self.backtrace = backtrace - self.compileGroup = None # type: Optional[TargetCompileGroup] - self.sourceGroup = None # type: Optional[TargetSourceGroup] + self.compileGroup: Optional[TargetCompileGroup] = None + self.sourceGroup: Optional[TargetSourceGroup] = None @classmethod def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index 78b6983..ebd98af 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -12,10 +12,10 @@ class CMakeProject: def __init__(self, name: str): self.name = name - self.parentProject = None # type: Optional[CMakeProject] - self.childProjects = [] # type: List[CMakeProject] - self.directories = [] # type: List[CMakeDirectory] - self.targets = [] # type:List[CMakeTarget] + self.parentProject: Optional[CMakeProject] = None + self.childProjects: list[CMakeProject] = [] + self.directories: list[CMakeDirectory] = [] + self.targets: list[CMakeTarget] = [] @classmethod def from_dict(cls, dikt: dict[str, str]) -> "CMakeProject": @@ -46,10 +46,10 @@ class CMakeDirectory: def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool): self.source = source self.build = build - self.parentDirectory = None # type: Optional[CMakeDirectory] - self.childDirectories = [] # type: List[CMakeDirectory] - self.project = None # type: Optional[CMakeProject] - self.targets = [] # type: List[CMakeTarget] + self.parentDirectory: Optional[CMakeDirectory] = None + self.childDirectories: list[CMakeDirectory] = [] + self.project: Optional[CMakeProject] = None + self.targets: list[CMakeTarget] = [] self.minimumCMakeVersion = minimumCMakeVersion self.hasInstallRule = hasInstallRule diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index 11538ac..f77a3fa 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -400,8 +400,8 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.path = path self.isGenerated = isGenerated self.backtrace = backtrace - self.compileGroup = None # type: Optional[TargetCompileGroup] - self.sourceGroup = None # type: Optional[TargetSourceGroup] + self.compileGroup: Optional[TargetCompileGroup] = None + self.sourceGroup: Optional[TargetSourceGroup] = None @classmethod def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index bac2c8f..010d7e9 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -10,10 +10,10 @@ class CMakeToolchainCompilerImplicit: __slots__ = ("includeDirectories", "linkDirectories", "linkFrameworkDirectories", "linkLibraries") def __init__(self) -> None: - self.includeDirectories = [] # type: List[Path] - self.linkDirectories = [] # type: List[Path] - self.linkFrameworkDirectories = [] # type: List[Path] - self.linkLibraries = [] # type: List[str] + self.includeDirectories: list[Path] = [] + self.linkDirectories: list[Path] = [] + self.linkFrameworkDirectories: list[Path] = [] + self.linkLibraries: list[str] = [] @classmethod def from_dict(cls, dikt: dict[str, Any]) -> "CMakeToolchainCompilerImplicit": From d6bf9e074f146f675e4289b9df9e999759da7809 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 8 Aug 2024 17:31:50 +0200 Subject: [PATCH 09/13] fix more mypy issues --- cmake_file_api/kinds/cache/v2.py | 2 +- cmake_file_api/kinds/cmakeFiles/v1.py | 2 +- cmake_file_api/kinds/codemodel/target/v2.py | 33 +++++++++---------- cmake_file_api/kinds/codemodel/v2.py | 8 ++--- cmake_file_api/kinds/common.py | 3 +- .../kinds/configureLog/target/v2.py | 30 ++++++++--------- cmake_file_api/kinds/toolchains/v1.py | 2 +- cmake_file_api/reply/index/v1.py | 2 +- cmake_file_api/reply/v1/api.py | 8 +++-- 9 files changed, 46 insertions(+), 44 deletions(-) diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index 32eb470..8cc3040 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -75,7 +75,7 @@ def __init__(self, version: VersionMajorMinor, entries: list[CacheEntry]): self.entries = entries @classmethod - def from_dict(cls, dikt: dict, reply_path) -> "CacheV2": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CacheV2": if dikt["kind"] != cls.KIND.value: raise ValueError version = VersionMajorMinor.from_dict(dikt["version"]) diff --git a/cmake_file_api/kinds/cmakeFiles/v1.py b/cmake_file_api/kinds/cmakeFiles/v1.py index a52a71a..8879b7b 100644 --- a/cmake_file_api/kinds/cmakeFiles/v1.py +++ b/cmake_file_api/kinds/cmakeFiles/v1.py @@ -44,7 +44,7 @@ def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inp self.inputs = inputs @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "CMakeFilesV1": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CMakeFilesV1": version = VersionMajorMinor.from_dict(dikt["version"]) paths = CMakeSourceBuildPaths.from_dict(dikt["paths"]) inputs = list(CMakeFilesInput.from_dict(cmi) for cmi in dikt["inputs"]) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 4222d70..a476bae 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -4,7 +4,6 @@ from typing import Any, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths -from cmake_file_api.kinds.configureLog.target.v2 import TargetSource class TargetType(enum.Enum): @@ -38,7 +37,7 @@ def __init__(self, file: Path, line: Optional[int], command: Optional[str]): self.parent = None @classmethod - def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "BacktraceNode": + def from_dict(cls, dikt: dict[str, Any], commands: list[str], files: list[Path]) -> "BacktraceNode": file = files[dikt["file"]] line = dikt.get("line") command = None @@ -46,7 +45,7 @@ def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "Backt command = commands[dikt["command"]] return cls(file, line, command) - def update_from_dict(self, dikt: dict, nodes: list["BacktraceNode"]) -> None: + def update_from_dict(self, dikt: dict[str, Any], nodes: list["BacktraceNode"]) -> None: if "parent" in dikt: self.parent = nodes[dikt["parent"]] @@ -89,7 +88,7 @@ def __init__(self, path: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetDestination": path = Path(dikt["path"]) backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, backtrace) @@ -110,7 +109,7 @@ def __init__(self, prefix: Path, destinations: list[TargetDestination]): self.destinations = destinations @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetInstall": prefix = Path(dikt["prefix"]["path"]) destinations = list(TargetDestination.from_dict(td, backtraceGraph) for td in dikt["destinations"]) return cls(prefix, destinations) @@ -222,12 +221,12 @@ def __repr__(self) -> str: class TargetSourceGroup: __slots__ = ("name", "sources") - def __init__(self, name: str, sources: list[TargetSource]): + def __init__(self, name: str, sources: list["TargetSource"]): self.name = name self.sources: list[TargetSource] = [] @classmethod - def from_dict(cls, dikt: dict, target_sources: list["TargetSource"]) -> "TargetSourceGroup": + def from_dict(cls, dikt: dict[str, Any], target_sources: list["TargetSource"]) -> "TargetSourceGroup": name = dikt["name"] sources = list(target_sources[tsi] for tsi in dikt["sourceIndexes"]) return cls(name, sources) @@ -265,7 +264,7 @@ def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[Bac self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": path = Path(dikt["path"]) isSystem = dikt.get("isSystem") backtrace = None @@ -290,7 +289,7 @@ def __init__(self, header: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": header = Path(dikt["header"]) backtrace = None if "backtrace" in dikt: @@ -313,7 +312,7 @@ def __init__(self, define: str, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": define = dikt["define"] backtrace = None if "backtrace" in dikt: @@ -344,7 +343,7 @@ def __init__(self, sources: list["TargetSource"], language: str, self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: dict, target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": + def from_dict(cls, dikt: dict[str, Any], target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": language = dikt["language"] compileCommandFragments = list(TargetCompileFragment.from_dict(tcf) for tcf in dikt.get("compileCommandFragments", ())) includes = list(TargetCompileGroupInclude.from_dict(tci, backtraceGraph) for tci in dikt.get("includes", ())) @@ -375,11 +374,11 @@ def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.target: Optional[CodemodelTargetV2] = None self.backtrace = backtrace - def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): + def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> None: self.target = lut_id_target[self.id] @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetDependency": id = dikt["id"] backtrace = None if "backtrace" in dikt: @@ -406,7 +405,7 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.sourceGroup: Optional[TargetSourceGroup] = None @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetSource": path = Path(dikt["path"]) isGenerated = dikt.get("isGenerated") backtrace = None @@ -414,7 +413,7 @@ def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource" backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, isGenerated, backtrace) - def update_from_dict(self, dikt: dict, modelTarget: "CodemodelTargetV2"): + def update_from_dict(self, dikt: dict[str, Any], modelTarget: "CodemodelTargetV2") -> None: if "compileGroupIndex" in dikt: self.compileGroup = modelTarget.compileGroups[dikt["compileGroupIndex"]] if "sourceGroupIndex" in dikt: @@ -436,7 +435,7 @@ class CodemodelTargetV2: "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") - def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Path, + def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Optional[Path], paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], @@ -464,7 +463,7 @@ def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> dependency.update_dependency(lut_id_target) @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "CodemodelTargetV2": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CodemodelTargetV2": name = dikt["name"] id = dikt["id"] type = TargetType(dikt["type"]) diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index ebd98af..d597f0a 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -61,7 +61,7 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CMakeDirectory": hasInstallRule = dikt.get("hasInstallRule", False) return cls(source, build, minimumCMakeVersion, hasInstallRule) - def update_from_dict(self, dikt: dict, configuration: "CMakeConfiguration") -> None: + def update_from_dict(self, dikt: dict[str, Any], configuration: "CMakeConfiguration") -> None: if "parentIndex" in dikt: self.parentDirectory = configuration.directories[dikt["parentIndex"]] self.childDirectories = list(configuration.directories[di] for di in dikt.get("childIndexes", ())) @@ -92,12 +92,12 @@ def __init__(self, name: str, directory: CMakeDirectory, project: CMakeProject, self.jsonFile = jsonFile self.target = target - def update_dependencies(self, lut_id_target: dict[str, "CMakeTarget"]): + def update_dependencies(self, lut_id_target: dict[str, "CMakeTarget"]) -> None: lut = {k: v.target for k, v in lut_id_target.items()} self.target.update_dependencies(lut) @classmethod - def from_dict(cls, dikt: dict, directories: list[CMakeDirectory], projects: list[CMakeProject], reply_path: Path) -> "CMakeTarget": + def from_dict(cls, dikt: dict[str, Any], directories: list[CMakeDirectory], projects: list[CMakeProject], reply_path: Path) -> "CMakeTarget": name = dikt["name"] directory = directories[dikt["directoryIndex"]] project = projects[dikt["projectIndex"]] @@ -126,7 +126,7 @@ def __init__(self, name: str, directories: list[CMakeDirectory], projects: list[ self.targets = targets @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "CMakeConfiguration": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CMakeConfiguration": name = dikt["name"] directories = list(CMakeDirectory.from_dict(d) for d in dikt["directories"]) projects = list(CMakeProject.from_dict(d) for d in dikt["projects"]) diff --git a/cmake_file_api/kinds/common.py b/cmake_file_api/kinds/common.py index 22cf9a5..92efb6f 100644 --- a/cmake_file_api/kinds/common.py +++ b/cmake_file_api/kinds/common.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Any class VersionMajorMinor: @@ -27,7 +28,7 @@ def __init__(self, source: Path, build: Path): self.build = build @classmethod - def from_dict(cls, d) -> "CMakeSourceBuildPaths": + def from_dict(cls, d: dict[str, Any]) -> "CMakeSourceBuildPaths": return cls(Path(d["source"]), Path(d["build"])) def __repr__(self) -> str: diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index f77a3fa..ed1118d 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -36,7 +36,7 @@ def __init__(self, file: Path, line: Optional[int], command: Optional[str]): self.parent = None @classmethod - def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "BacktraceNode": + def from_dict(cls, dikt: dict[str, Any], commands: list[str], files: list[Path]) -> "BacktraceNode": file = files[dikt["file"]] line = dikt.get("line") command = None @@ -44,7 +44,7 @@ def from_dict(cls, dikt: dict, commands: list[str], files: list[Path]) -> "Backt command = commands[dikt["command"]] return cls(file, line, command) - def update_from_dict(self, dikt: dict, nodes: list["BacktraceNode"]) -> None: + def update_from_dict(self, dikt: dict[str, Any], nodes: list["BacktraceNode"]) -> None: if "parent" in dikt: self.parent = nodes[dikt["parent"]] @@ -87,7 +87,7 @@ def __init__(self, path: Path, backtrace: BacktraceNode): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDestination": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetDestination": path = Path(dikt["path"]) backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, backtrace) @@ -108,7 +108,7 @@ def __init__(self, prefix: Path, destinations: list[TargetDestination]): self.destinations = destinations @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetInstall": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetInstall": prefix = Path(dikt["prefix"]["path"]) destinations = list(TargetDestination.from_dict(td, backtraceGraph) for td in dikt["destinations"]) return cls(prefix, destinations) @@ -225,7 +225,7 @@ def __init__(self, name: str, sources: list["TargetSource"]): self.sources: list[TargetSource] = [] @classmethod - def from_dict(cls, dikt: dict, target_sources: list["TargetSource"]) -> "TargetSourceGroup": + def from_dict(cls, dikt: dict[str, Any], target_sources: list["TargetSource"]) -> "TargetSourceGroup": name = dikt["name"] sources = list(target_sources[tsi] for tsi in dikt["sourceIndexes"]) return cls(name, sources) @@ -263,7 +263,7 @@ def __init__(self, path: Path, isSystem: Optional[bool], backtrace: Optional[Bac self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupInclude": path = Path(dikt["path"]) isSystem = dikt.get("isSystem") backtrace = None @@ -288,7 +288,7 @@ def __init__(self, header: Path, backtrace: BacktraceNode | None): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupPCH": header = Path(dikt["header"]) backtrace = None if "backtrace" in dikt: @@ -311,7 +311,7 @@ def __init__(self, define: str, backtrace: BacktraceNode | None): self.backtrace = backtrace @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetCompileGroupDefine": define = dikt["define"] backtrace = None if "backtrace" in dikt: @@ -342,7 +342,7 @@ def __init__(self, sources: list["TargetSource"], language: str, self.sysroot = sysroot @classmethod - def from_dict(cls, dikt: dict, target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": + def from_dict(cls, dikt: dict[str, Any], target_sources: list["TargetSource"], backtraceGraph: BacktraceGraph) -> "TargetCompileGroup": language = dikt["language"] compileCommandFragments = list(TargetCompileFragment.from_dict(tcf) for tcf in dikt.get("compileCommandFragments", ())) includes = list(TargetCompileGroupInclude.from_dict(tci, backtraceGraph) for tci in dikt.get("includes", ())) @@ -373,11 +373,11 @@ def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.target: CodemodelTargetV2 | None = None self.backtrace = backtrace - def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]): + def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> None: self.target = lut_id_target[self.id] @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetDependency": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetDependency": id = dikt["id"] backtrace = None if "backtrace" in dikt: @@ -404,7 +404,7 @@ def __init__(self, path: Path, isGenerated: Optional[bool], backtrace: Optional[ self.sourceGroup: Optional[TargetSourceGroup] = None @classmethod - def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource": + def from_dict(cls, dikt: dict[str, Any], backtraceGraph: BacktraceGraph) -> "TargetSource": path = Path(dikt["path"]) isGenerated = dikt.get("isGenerated") backtrace = None @@ -412,7 +412,7 @@ def from_dict(cls, dikt: dict, backtraceGraph: BacktraceGraph) -> "TargetSource" backtrace = backtraceGraph.nodes[dikt["backtrace"]] return cls(path, isGenerated, backtrace) - def update_from_dict(self, dikt: dict, modelTarget: "CodemodelTargetV2"): + def update_from_dict(self, dikt: dict[str, Any], modelTarget: "CodemodelTargetV2") -> None: if "compileGroupIndex" in dikt: self.compileGroup = modelTarget.compileGroups[dikt["compileGroupIndex"]] if "sourceGroupIndex" in dikt: @@ -434,7 +434,7 @@ class CodemodelTargetV2: "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") - def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Path, + def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Optional[Path], paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], @@ -457,7 +457,7 @@ def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNod self.sourceGroups = sourceGroups self.compileGroups = compileGroups - def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]): + def update_dependencies(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> None: for dependency in self.dependencies: dependency.update_dependency(lut_id_target) diff --git a/cmake_file_api/kinds/toolchains/v1.py b/cmake_file_api/kinds/toolchains/v1.py index 010d7e9..2267209 100644 --- a/cmake_file_api/kinds/toolchains/v1.py +++ b/cmake_file_api/kinds/toolchains/v1.py @@ -92,7 +92,7 @@ def __init__(self, version: VersionMajorMinor, toolchains: list[CMakeToolchain]) self.toolchains = toolchains @classmethod - def from_dict(cls, dikt: dict, reply_path: Path) -> "ToolchainsV1": + def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ToolchainsV1": version = VersionMajorMinor.from_dict(dikt["version"]) toolchains = list(CMakeToolchain.from_dict(cmi) for cmi in dikt["toolchains"]) return cls(version, toolchains) diff --git a/cmake_file_api/reply/index/v1.py b/cmake_file_api/reply/index/v1.py index 30547af..a74e64f 100644 --- a/cmake_file_api/reply/index/v1.py +++ b/cmake_file_api/reply/index/v1.py @@ -114,7 +114,7 @@ class CMakeReply: __slots__ = ("stateless", "stateful", "unknowns") def __init__(self, stateless: dict[tuple[ObjectKind, int], CMakeReplyFileReferenceV1], - stateful: dict[str, dict], unknowns: list[str]): + stateful: dict[str, dict[str, Any]], unknowns: list[str]): self.stateless = stateless self.stateful = stateful self.unknowns = unknowns diff --git a/cmake_file_api/reply/v1/api.py b/cmake_file_api/reply/v1/api.py index 5bfea44..1cc5627 100644 --- a/cmake_file_api/reply/v1/api.py +++ b/cmake_file_api/reply/v1/api.py @@ -3,8 +3,10 @@ from cmake_file_api.errors import CMakeException from cmake_file_api.kinds.api import OBJECT_KINDS_API +from cmake_file_api.kinds.cmakeFiles.v1 import CMakeFilesV1 from cmake_file_api.reply.index.api import INDEX_API from cmake_file_api.kinds.kind import ObjectKind +from cmake_file_api.reply.index.v1 import CMakeReplyFileV1 class CMakeFileApiV1: @@ -52,7 +54,7 @@ def instrument_all(self) -> None: for kind_version in kind_api.keys(): self._instrument_query_path(query_path, kind, kind_version) - def _index(self, reply_path: Path): + def _index(self, reply_path: Path) -> CMakeReplyFileV1: index_path = self._find_index_path(reply_path) if index_path is None: raise CMakeException("CMake did not generate index file. Maybe your cmake version is too old?") @@ -62,11 +64,11 @@ def _index(self, reply_path: Path): raise CMakeException("Unknown api version") return index_api.from_path(index_path) - def index(self): + def index(self) -> CMakeReplyFileV1: reply_path = self._create_reply_path() return self._index(reply_path) - def inspect(self, kind: ObjectKind, kind_version: int): + def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeFilesV1]: reply_path = self._create_reply_path() index = self._index(reply_path) From 9095b18cb8de6d999159fc23d3e67409d052fa87 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 9 Sep 2024 18:51:25 +0200 Subject: [PATCH 10/13] suggested fix --- cmake_file_api/kinds/codemodel/target/v2.py | 2 +- cmake_file_api/kinds/configureLog/target/v2.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index a476bae..25860b9 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -435,7 +435,7 @@ class CodemodelTargetV2: "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") - def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Optional[Path], + def __init__(self, name: str, id: str, type: TargetType, backtrace: Optional[BacktraceNode], folder: Optional[Path], paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index ed1118d..3df6a99 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -434,7 +434,7 @@ class CodemodelTargetV2: "isGeneratorProvided", "install", "link", "archive", "dependencies", "sources", "sourceGroups", "compileGroups") - def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Optional[Path], + def __init__(self, name: str, id: str, type: TargetType, backtrace: Optional[BacktraceNode], folder: Optional[Path], paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path], isGeneratorProvided: Optional[bool], install: Optional[TargetInstall], link: Optional[TargetLink], archive: Optional[TargetArchive], From a8c32cc929147c26ea5c3c3d472b7a7aa7d12adf Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 9 Sep 2024 19:15:37 +0200 Subject: [PATCH 11/13] fix remaining issues --- cmake_file_api/kinds/api.py | 13 ++++++++++++- cmake_file_api/kinds/cache/api.py | 4 ++-- cmake_file_api/kinds/cmakeFiles/api.py | 4 ++-- cmake_file_api/kinds/codemodel/api.py | 4 ++-- cmake_file_api/kinds/codemodel/target/v2.py | 4 ++-- cmake_file_api/kinds/configureLog/api.py | 4 ++-- cmake_file_api/kinds/toolchains/api.py | 4 ++-- cmake_file_api/reply/v1/api.py | 10 +++++----- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/cmake_file_api/kinds/api.py b/cmake_file_api/kinds/api.py index aa60370..9346f6b 100644 --- a/cmake_file_api/kinds/api.py +++ b/cmake_file_api/kinds/api.py @@ -1,3 +1,7 @@ +from pathlib import Path +from typing import Protocol +from typing_extensions import Self + from .kind import ObjectKind from .cache.api import CACHE_API from .cmakeFiles.api import CMAKEFILES_API @@ -6,7 +10,14 @@ from .toolchains.api import TOOLCHAINS_API -OBJECT_KINDS_API = { +class CMakeApiType(Protocol): + KIND: ObjectKind + + @classmethod + def from_path(cls, path: Path, reply_path: Path) -> Self: + ... + +OBJECT_KINDS_API: dict[ObjectKind, dict[int, CMakeApiType]] = { ObjectKind.CACHE: CACHE_API, ObjectKind.CMAKEFILES: CMAKEFILES_API, ObjectKind.CONFIGURELOG: CONFIGURELOG_API, diff --git a/cmake_file_api/kinds/cache/api.py b/cmake_file_api/kinds/cache/api.py index 5d872d8..c1b8876 100644 --- a/cmake_file_api/kinds/cache/api.py +++ b/cmake_file_api/kinds/cache/api.py @@ -1,6 +1,6 @@ from .v2 import CacheV2 +from ..api import CMakeApiType - -CACHE_API = { +CACHE_API: dict[int, CMakeApiType] = { 2: CacheV2, } diff --git a/cmake_file_api/kinds/cmakeFiles/api.py b/cmake_file_api/kinds/cmakeFiles/api.py index 89f6cc8..510df99 100644 --- a/cmake_file_api/kinds/cmakeFiles/api.py +++ b/cmake_file_api/kinds/cmakeFiles/api.py @@ -1,6 +1,6 @@ from .v1 import CMakeFilesV1 +from ..api import CMakeApiType - -CMAKEFILES_API = { +CMAKEFILES_API: dict[int, CMakeApiType] = { 1: CMakeFilesV1, } diff --git a/cmake_file_api/kinds/codemodel/api.py b/cmake_file_api/kinds/codemodel/api.py index 2d53f32..27700ec 100644 --- a/cmake_file_api/kinds/codemodel/api.py +++ b/cmake_file_api/kinds/codemodel/api.py @@ -1,6 +1,6 @@ from .v2 import CodemodelV2 +from ..api import CMakeApiType - -CODEMODEL_API = { +CODEMODEL_API: dict[int, CMakeApiType] = { 2: CodemodelV2, } diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 25860b9..c81e1d8 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -284,7 +284,7 @@ def __repr__(self) -> str: class TargetCompileGroupPCH: __slots__ = ("header", "backtrace") - def __init__(self, header: Path, backtrace: BacktraceNode): + def __init__(self, header: Path, backtrace: Optional[BacktraceNode]): self.header = header self.backtrace = backtrace @@ -307,7 +307,7 @@ def __repr__(self) -> str: class TargetCompileGroupDefine: __slots__ = ("define", "backtrace") - def __init__(self, define: str, backtrace: BacktraceNode): + def __init__(self, define: str, backtrace: Optional[BacktraceNode]): self.define = define self.backtrace = backtrace diff --git a/cmake_file_api/kinds/configureLog/api.py b/cmake_file_api/kinds/configureLog/api.py index d54e28c..1567dbd 100644 --- a/cmake_file_api/kinds/configureLog/api.py +++ b/cmake_file_api/kinds/configureLog/api.py @@ -1,6 +1,6 @@ from .v1 import ConfigureLogV1 +from ..api import CMakeApiType - -CONFIGURELOG_API = { +CONFIGURELOG_API: dict[int, CMakeApiType] = { 1: ConfigureLogV1, } diff --git a/cmake_file_api/kinds/toolchains/api.py b/cmake_file_api/kinds/toolchains/api.py index bc4dece..a134b19 100644 --- a/cmake_file_api/kinds/toolchains/api.py +++ b/cmake_file_api/kinds/toolchains/api.py @@ -1,6 +1,6 @@ from .v1 import ToolchainsV1 +from ..api import CMakeApiType - -TOOLCHAINS_API = { +TOOLCHAINS_API: dict[int, CMakeApiType] = { 1: ToolchainsV1, } diff --git a/cmake_file_api/reply/v1/api.py b/cmake_file_api/reply/v1/api.py index 1cc5627..7603e21 100644 --- a/cmake_file_api/reply/v1/api.py +++ b/cmake_file_api/reply/v1/api.py @@ -1,8 +1,8 @@ from pathlib import Path -from typing import Optional +from typing import Any, Optional from cmake_file_api.errors import CMakeException -from cmake_file_api.kinds.api import OBJECT_KINDS_API +from cmake_file_api.kinds.api import CMakeApiType, OBJECT_KINDS_API from cmake_file_api.kinds.cmakeFiles.v1 import CMakeFilesV1 from cmake_file_api.reply.index.api import INDEX_API from cmake_file_api.kinds.kind import ObjectKind @@ -68,14 +68,14 @@ def index(self) -> CMakeReplyFileV1: reply_path = self._create_reply_path() return self._index(reply_path) - def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeFilesV1]: + def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeApiType]: reply_path = self._create_reply_path() index = self._index(reply_path) data_path = index.reply.stateless.get((kind, kind_version), None) if data_path is None: return None - api = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None) + api: Optional[CMakeApiType] = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None) if api is None: return None return api.from_path(reply_path / str(data_path.jsonFile), reply_path) @@ -84,7 +84,7 @@ def inspect_all(self) -> dict[ObjectKind, dict[int, object]]: reply_path = self._create_reply_path() index = self._index(reply_path) - result = {} + result: dict[ObjectKind, dict[int, Any]] = {} for (kind, kind_version), reply_file_ref in index.reply.stateless.items(): api = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None) if api is None: From 95c3c3aeee86bc4ad81431a6bd893d4527c0a826 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 9 Sep 2024 19:23:36 +0200 Subject: [PATCH 12/13] fix circular import --- cmake_file_api/kinds/cache/api.py | 7 ++++++- cmake_file_api/kinds/cmakeFiles/api.py | 7 ++++++- cmake_file_api/kinds/codemodel/api.py | 8 +++++++- cmake_file_api/kinds/configureLog/api.py | 7 ++++++- cmake_file_api/kinds/toolchains/api.py | 7 ++++++- cmake_file_api/reply/v1/api.py | 1 - 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cmake_file_api/kinds/cache/api.py b/cmake_file_api/kinds/cache/api.py index c1b8876..863faac 100644 --- a/cmake_file_api/kinds/cache/api.py +++ b/cmake_file_api/kinds/cache/api.py @@ -1,5 +1,10 @@ +from __future__ import annotations +import typing + from .v2 import CacheV2 -from ..api import CMakeApiType + +if typing.TYPE_CHECKING: + from ..api import CMakeApiType CACHE_API: dict[int, CMakeApiType] = { 2: CacheV2, diff --git a/cmake_file_api/kinds/cmakeFiles/api.py b/cmake_file_api/kinds/cmakeFiles/api.py index 510df99..2d2d58e 100644 --- a/cmake_file_api/kinds/cmakeFiles/api.py +++ b/cmake_file_api/kinds/cmakeFiles/api.py @@ -1,5 +1,10 @@ +from __future__ import annotations +import typing + from .v1 import CMakeFilesV1 -from ..api import CMakeApiType + +if typing.TYPE_CHECKING: + from ..api import CMakeApiType CMAKEFILES_API: dict[int, CMakeApiType] = { 1: CMakeFilesV1, diff --git a/cmake_file_api/kinds/codemodel/api.py b/cmake_file_api/kinds/codemodel/api.py index 27700ec..c76998c 100644 --- a/cmake_file_api/kinds/codemodel/api.py +++ b/cmake_file_api/kinds/codemodel/api.py @@ -1,5 +1,11 @@ +from __future__ import annotations +import typing + from .v2 import CodemodelV2 -from ..api import CMakeApiType + + +if typing.TYPE_CHECKING: + from ..api import CMakeApiType CODEMODEL_API: dict[int, CMakeApiType] = { 2: CodemodelV2, diff --git a/cmake_file_api/kinds/configureLog/api.py b/cmake_file_api/kinds/configureLog/api.py index 1567dbd..f0b9e45 100644 --- a/cmake_file_api/kinds/configureLog/api.py +++ b/cmake_file_api/kinds/configureLog/api.py @@ -1,5 +1,10 @@ +from __future__ import annotations +import typing + from .v1 import ConfigureLogV1 -from ..api import CMakeApiType + +if typing.TYPE_CHECKING: + from ..api import CMakeApiType CONFIGURELOG_API: dict[int, CMakeApiType] = { 1: ConfigureLogV1, diff --git a/cmake_file_api/kinds/toolchains/api.py b/cmake_file_api/kinds/toolchains/api.py index a134b19..d37d362 100644 --- a/cmake_file_api/kinds/toolchains/api.py +++ b/cmake_file_api/kinds/toolchains/api.py @@ -1,5 +1,10 @@ +from __future__ import annotations +import typing + from .v1 import ToolchainsV1 -from ..api import CMakeApiType + +if typing.TYPE_CHECKING: + from ..api import CMakeApiType TOOLCHAINS_API: dict[int, CMakeApiType] = { 1: ToolchainsV1, diff --git a/cmake_file_api/reply/v1/api.py b/cmake_file_api/reply/v1/api.py index 7603e21..5ac3745 100644 --- a/cmake_file_api/reply/v1/api.py +++ b/cmake_file_api/reply/v1/api.py @@ -3,7 +3,6 @@ from cmake_file_api.errors import CMakeException from cmake_file_api.kinds.api import CMakeApiType, OBJECT_KINDS_API -from cmake_file_api.kinds.cmakeFiles.v1 import CMakeFilesV1 from cmake_file_api.reply.index.api import INDEX_API from cmake_file_api.kinds.kind import ObjectKind from cmake_file_api.reply.index.v1 import CMakeReplyFileV1 From d982884868301979bf2122f312e48aba9386d635 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 9 Sep 2024 19:26:03 +0200 Subject: [PATCH 13/13] fix 3.9 incompatibilities --- cmake_file_api/kinds/configureLog/target/v2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake_file_api/kinds/configureLog/target/v2.py b/cmake_file_api/kinds/configureLog/target/v2.py index 3df6a99..cc7139f 100644 --- a/cmake_file_api/kinds/configureLog/target/v2.py +++ b/cmake_file_api/kinds/configureLog/target/v2.py @@ -283,7 +283,7 @@ def __repr__(self) -> str: class TargetCompileGroupPCH: __slots__ = ("header", "backtrace") - def __init__(self, header: Path, backtrace: BacktraceNode | None): + def __init__(self, header: Path, backtrace: Optional[BacktraceNode]): self.header = header self.backtrace = backtrace @@ -306,7 +306,7 @@ def __repr__(self) -> str: class TargetCompileGroupDefine: __slots__ = ("define", "backtrace") - def __init__(self, define: str, backtrace: BacktraceNode | None): + def __init__(self, define: str, backtrace: Optional[BacktraceNode]): self.define = define self.backtrace = backtrace @@ -370,7 +370,7 @@ class TargetDependency: def __init__(self, id: str, backtrace: Optional[BacktraceNode]): self.id = id - self.target: CodemodelTargetV2 | None = None + self.target: Optional[CodemodelTargetV2] = None self.backtrace = backtrace def update_dependency(self, lut_id_target: dict[str, "CodemodelTargetV2"]) -> None: