Skip to content

Commit a6be7b5

Browse files
enabling mypyc
Signed-off-by: romintomasetti <romin.tomasetti@gmail.com>
1 parent dd3ac84 commit a6be7b5

18 files changed

Lines changed: 97 additions & 93 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/setup-python@v6
3434
with:
3535
python-version: "3.10"
36-
- run: pip install mypy
36+
- run: python -m pip install -r requirements-dev.txt
3737
- run: mypy --install-types --non-interactive --strict
3838

3939
pylint:
@@ -43,5 +43,22 @@ jobs:
4343
- uses: actions/setup-python@v6
4444
with:
4545
python-version: "3.12"
46-
- run: pip install pylint
46+
- run: python -m pip install -r requirements-dev.txt
4747
- run: pylint --verbose --fail-under=10 --rcfile .pylintrc cmake_file_api
48+
49+
mypyc:
50+
runs-on: ubuntu-latest
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
py: ['3.10', '3.11', '3.12', '3.13', '3.14']
55+
steps:
56+
- uses: actions/checkout@v6
57+
- uses: actions/setup-python@v6
58+
with:
59+
python-version: ${{ matrix.py }}
60+
- run: python -m pip install -r requirements-dev.txt
61+
- run: python setup.py bdist_wheel --dist-dir wheelhouse
62+
- run: pip install --no-deps --no-index --find-links=wheelhouse/ cmake_file_api
63+
- run: rm -rf cmake_file_api/
64+
- run: pytest --log-cli-level=info -vvv tests/

cmake_file_api/kinds/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111

1212
class CMakeApiType(Protocol):
13-
KIND: ObjectKind
13+
@staticmethod
14+
def kind() -> ObjectKind:
15+
...
1416

1517
@classmethod
1618
def from_path(cls, path: Path, reply_path: Path) -> "CMakeApiType":
1719
...
1820

19-
OBJECT_KINDS_API: dict[ObjectKind, dict[int, CMakeApiType]] = {
21+
OBJECT_KINDS_API: dict[ObjectKind, dict[int, type[CMakeApiType]]] = {
2022
ObjectKind.CACHE: CACHE_API,
2123
ObjectKind.CMAKEFILES: CMAKEFILES_API,
2224
ObjectKind.CONFIGURELOG: CONFIGURELOG_API,

cmake_file_api/kinds/cache/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
if typing.TYPE_CHECKING:
77
from ..api import CMakeApiType
88

9-
CACHE_API: dict[int, CMakeApiType] = {
9+
CACHE_API: dict[int, type[CMakeApiType]] = {
1010
2: CacheV2,
1111
}

cmake_file_api/kinds/cache/v2.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
import json
44
from pathlib import Path
5-
from typing import Any, ClassVar
5+
from typing import Any
66

77
from cmake_file_api.kinds.common import VersionMajorMinor
88
from cmake_file_api.kinds.kind import ObjectKind
@@ -43,18 +43,18 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CacheEntry":
4343
properties = list(CacheEntryProperty.from_dict(cep) for cep in dikt["properties"])
4444
return cls(name, value, type, properties)
4545

46+
@dataclasses.dataclass(frozen=True, slots=True)
4647
class CacheV2:
47-
KIND: ClassVar = ObjectKind.CACHE
48+
version: VersionMajorMinor
49+
entries: list[CacheEntry]
4850

49-
__slots__ = ("version", "entries")
50-
51-
def __init__(self, version: VersionMajorMinor, entries: list[CacheEntry]):
52-
self.version = version
53-
self.entries = entries
51+
@staticmethod
52+
def kind() -> ObjectKind:
53+
return ObjectKind.CACHE
5454

5555
@classmethod
5656
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CacheV2":
57-
if dikt["kind"] != cls.KIND.value:
57+
if dikt["kind"] != cls.kind():
5858
raise ValueError
5959
version = VersionMajorMinor.from_dict(dikt["version"])
6060
entries = list(CacheEntry.from_dict(ce) for ce in dikt["entries"])
@@ -65,10 +65,3 @@ def from_path(cls, path: Path, reply_path: Path) -> "CacheV2":
6565
with path.open() as file:
6666
dikt = json.load(file)
6767
return cls.from_dict(dikt, reply_path)
68-
69-
def __repr__(self) -> str:
70-
return "{}(version={}, entries={})".format(
71-
type(self).__name__,
72-
repr(self.version),
73-
repr(self.entries),
74-
)

cmake_file_api/kinds/cmakeFiles/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
if typing.TYPE_CHECKING:
77
from ..api import CMakeApiType
88

9-
CMAKEFILES_API: dict[int, CMakeApiType] = {
9+
CMAKEFILES_API: dict[int, type[CMakeApiType]] = {
1010
1: CMakeFilesV1,
1111
}

cmake_file_api/kinds/cmakeFiles/v1.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dataclasses
12
import json
23
from pathlib import Path
34
from typing import Any, Optional
@@ -33,15 +34,15 @@ def __repr__(self) -> str:
3334
)
3435

3536

37+
@dataclasses.dataclass(frozen=True, slots=True)
3638
class CMakeFilesV1:
37-
KIND = ObjectKind.CMAKEFILES
39+
version: VersionMajorMinor
40+
paths: CMakeSourceBuildPaths
41+
inputs: list[CMakeFilesInput]
3842

39-
__slots__ = ("version", "paths", "inputs")
40-
41-
def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inputs: list[CMakeFilesInput]):
42-
self.version = version
43-
self.paths = paths
44-
self.inputs = inputs
43+
@staticmethod
44+
def kind() -> ObjectKind:
45+
return ObjectKind.CMAKEFILES
4546

4647
@classmethod
4748
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CMakeFilesV1":
@@ -55,11 +56,3 @@ def from_path(cls, path: Path, reply_path: Path) -> "CMakeFilesV1":
5556
with path.open() as file:
5657
dikt = json.load(file)
5758
return cls.from_dict(dikt, reply_path)
58-
59-
def __repr__(self) -> str:
60-
return "{}(version={}, paths={}, inputs={})".format(
61-
type(self).__name__,
62-
repr(self.version),
63-
self.paths,
64-
repr(self.inputs),
65-
)

cmake_file_api/kinds/codemodel/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
if typing.TYPE_CHECKING:
88
from ..api import CMakeApiType
99

10-
CODEMODEL_API: dict[int, CMakeApiType] = {
10+
CODEMODEL_API: dict[int, type[CMakeApiType]] = {
1111
2: CodemodelV2,
1212
}

cmake_file_api/kinds/codemodel/v2.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import dataclasses
12
import json
23
from pathlib import Path
3-
from typing import Any, ClassVar, Optional
4+
from typing import Any, Optional
45

56
from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor
67
from cmake_file_api.kinds.kind import ObjectKind
@@ -43,7 +44,7 @@ def __repr__(self) -> str:
4344
class CMakeDirectory:
4445
__slots__ = ("source", "build", "parentDirectory", "childDirectories", "project", "targets", "minimumCMakeVersion", "hasInstallRule")
4546

46-
def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool):
47+
def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool) -> None:
4748
self.source = source
4849
self.build = build
4950
self.parentDirectory: Optional[CMakeDirectory] = None
@@ -153,19 +154,19 @@ def __repr__(self) -> str:
153154
)
154155

155156

157+
@dataclasses.dataclass(frozen=True, slots=True)
156158
class CodemodelV2:
157-
KIND: ClassVar = ObjectKind.CODEMODEL
159+
version: VersionMajorMinor
160+
paths: CMakeSourceBuildPaths
161+
configurations: list[CMakeConfiguration]
158162

159-
__slots__ = ("version", "paths", "configurations")
160-
161-
def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, configurations: list[CMakeConfiguration]):
162-
self.version = version
163-
self.paths = paths
164-
self.configurations = configurations
163+
@staticmethod
164+
def kind() -> ObjectKind:
165+
return ObjectKind.CODEMODEL
165166

166167
@classmethod
167168
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CodemodelV2":
168-
if dikt["kind"] != cls.KIND.value:
169+
if dikt["kind"] != cls.kind():
169170
raise ValueError
170171
paths = CMakeSourceBuildPaths.from_dict(dikt["paths"])
171172
version = VersionMajorMinor.from_dict(dikt["version"])
@@ -183,11 +184,3 @@ def get_configuration(self, name: str) -> CMakeConfiguration:
183184
return next(c for c in self.configurations if c.name == name)
184185
except StopIteration:
185186
raise KeyError("Unknown configuration")
186-
187-
def __repr__(self) -> str:
188-
return "{}(version={}, paths={}, configurations={})".format(
189-
type(self).__name__,
190-
self.version,
191-
self.paths,
192-
self.configurations,
193-
)

cmake_file_api/kinds/common.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1+
import dataclasses
12
from pathlib import Path
23
from typing import Any
34

45

6+
@dataclasses.dataclass(frozen=True, slots=True)
57
class VersionMajorMinor:
6-
__slots__ = ("major", "minor")
7-
8-
def __init__(self, major: int, minor: int):
9-
self.major = major
10-
self.minor = minor
8+
major: int
9+
minor: int
1110

1211
@classmethod
1312
def from_dict(cls, d: dict[str, int]) -> "VersionMajorMinor":
14-
return cls(int(d["major"]), int(d["minor"]))
15-
16-
def __repr__(self) -> str:
17-
return "Version({}.{})".format(
18-
self.major,
19-
self.minor,
20-
)
13+
return cls(d["major"], d["minor"])
2114

2215

2316
class CMakeSourceBuildPaths:

cmake_file_api/kinds/configureLog/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
if typing.TYPE_CHECKING:
77
from ..api import CMakeApiType
88

9-
CONFIGURELOG_API: dict[int, CMakeApiType] = {
9+
CONFIGURELOG_API: dict[int, type[CMakeApiType]] = {
1010
1: ConfigureLogV1,
1111
}

0 commit comments

Comments
 (0)