forked from madebr/python-cmake-file-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv1.py
More file actions
58 lines (47 loc) · 1.89 KB
/
v1.py
File metadata and controls
58 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import dataclasses
import json
from pathlib import Path
from typing import Any, Optional
from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor
from cmake_file_api.kinds.kind import ObjectKind
class CMakeFilesInput:
__slots__ = ("path", "isGenerator", "isExternal", "isCMake")
def __init__(self, path: Path, isGenerator: Optional[bool], isExternal: Optional[bool], isCMake: Optional[bool]):
self.path = path
self.isGenerator = isGenerator
self.isExternal = isExternal
self.isCMake = isCMake
@classmethod
def from_dict(cls, dikt: dict[str, Any]) -> "CMakeFilesInput":
path = Path(dikt["path"])
isGenerator = dikt.get("isGenerator")
isExternal = dikt.get("isExternal")
isCMake = dikt.get("isExternal")
return cls(path, isGenerator, isExternal, isCMake)
def __repr__(self) -> str:
return "{}(path='{}', generator={}, external={}, cmake={})".format(
type(self).__name__,
self.path,
self.isGenerator,
self.isExternal,
self.isCMake,
)
@dataclasses.dataclass(frozen=True, slots=True)
class CMakeFilesV1:
version: VersionMajorMinor
paths: CMakeSourceBuildPaths
inputs: list[CMakeFilesInput]
@staticmethod
def kind() -> ObjectKind:
return ObjectKind.CMAKEFILES
@classmethod
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"])
return cls(version, paths, inputs)
@classmethod
def from_path(cls, path: Path, reply_path: Path) -> "CMakeFilesV1":
with path.open() as file:
dikt = json.load(file)
return cls.from_dict(dikt, reply_path)