Skip to content

Commit f0dd4a2

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

16 files changed

Lines changed: 71 additions & 41 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
python -m pip install -r requirements-dev.txt
2525
- name: "Run pytest"
2626
run: |
27-
pytest
27+
pytest -vvv --typeguard-packages=cmake_file_api
2828
2929
check-typing:
3030
runs-on: ubuntu-latest
@@ -35,3 +35,21 @@ jobs:
3535
python-version: "3.10"
3636
- run: pip install mypy
3737
- run: mypy --install-types --non-interactive
38+
39+
mypyc:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
py: ['3.10', '3.11', '3.12', '3.13', '3.14']
45+
steps:
46+
- uses: actions/checkout@v6
47+
- uses: actions/setup-python@v6
48+
with:
49+
python-version: ${{ matrix.py }}
50+
- run: pip install -r requirements-dev.txt
51+
- run: |
52+
mypyc --strict
53+
python setup.py bdist_wheel --outdir wheelhouse
54+
pip install --no-deps --no-index --find-links=wheelhouse/ cmake_file_api
55+
pytest --log-cli-level=info -vvv tests/

cmake_file_api/kinds/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import Protocol
2+
from typing import ClassVar, Protocol
33

44
from .kind import ObjectKind
55
from .cache.api import CACHE_API
@@ -10,13 +10,13 @@
1010

1111

1212
class CMakeApiType(Protocol):
13-
KIND: ObjectKind
13+
KIND: ClassVar[ObjectKind]
1414

1515
@classmethod
1616
def from_path(cls, path: Path, reply_path: Path) -> "CMakeApiType":
1717
...
1818

19-
OBJECT_KINDS_API: dict[ObjectKind, dict[int, CMakeApiType]] = {
19+
OBJECT_KINDS_API: dict[ObjectKind, dict[int, type[CMakeApiType]]] = {
2020
ObjectKind.CACHE: CACHE_API,
2121
ObjectKind.CMAKEFILES: CMAKEFILES_API,
2222
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: 2 additions & 2 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
5+
from typing import Any, ClassVar
66

77
from cmake_file_api.kinds.common import VersionMajorMinor
88
from cmake_file_api.kinds.kind import ObjectKind
@@ -44,7 +44,7 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CacheEntry":
4444
return cls(name, value, type, properties)
4545

4646
class CacheV2:
47-
KIND = ObjectKind.CACHE
47+
KIND: ClassVar = ObjectKind.CACHE
4848

4949
__slots__ = ("version", "entries")
5050

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from pathlib import Path
3-
from typing import Any, Optional
3+
from typing import Any, ClassVar, Optional
44

55
from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor
66
from cmake_file_api.kinds.kind import ObjectKind
@@ -34,7 +34,7 @@ def __repr__(self) -> str:
3434

3535

3636
class CMakeFilesV1:
37-
KIND = ObjectKind.CMAKEFILES
37+
KIND: ClassVar = ObjectKind.CMAKEFILES
3838

3939
__slots__ = ("version", "paths", "inputs")
4040

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from pathlib import Path
3-
from typing import Any, Optional
3+
from typing import Any, ClassVar, Optional
44

55
from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor
66
from cmake_file_api.kinds.kind import ObjectKind
@@ -18,7 +18,7 @@ def __init__(self, name: str):
1818
self.targets: list[CMakeTarget] = []
1919

2020
@classmethod
21-
def from_dict(cls, dikt: dict[str, str]) -> "CMakeProject":
21+
def from_dict(cls, dikt: dict[str, Any]) -> "CMakeProject":
2222
name = dikt["name"]
2323
return cls(name)
2424

@@ -43,7 +43,7 @@ def __repr__(self) -> str:
4343
class CMakeDirectory:
4444
__slots__ = ("source", "build", "parentDirectory", "childDirectories", "project", "targets", "minimumCMakeVersion", "hasInstallRule")
4545

46-
def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool):
46+
def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str], hasInstallRule: bool) -> None:
4747
self.source = source
4848
self.build = build
4949
self.parentDirectory: Optional[CMakeDirectory] = None
@@ -57,7 +57,10 @@ def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str]
5757
def from_dict(cls, dikt: dict[str, Any]) -> "CMakeDirectory":
5858
source = Path(dikt["source"])
5959
build = Path(dikt["build"])
60-
minimumCMakeVersion = dikt.get("minimumCMakeVersion", None)
60+
if dikt.get("minimumCMakeVersion", None) is not None:
61+
minimumCMakeVersion = dikt["minimumCMakeVersion"]["string"]
62+
else:
63+
minimumCMakeVersion = None
6164
hasInstallRule = dikt.get("hasInstallRule", False)
6265
return cls(source, build, minimumCMakeVersion, hasInstallRule)
6366

@@ -154,7 +157,7 @@ def __repr__(self) -> str:
154157

155158

156159
class CodemodelV2:
157-
KIND = ObjectKind.CODEMODEL
160+
KIND: ClassVar = ObjectKind.CODEMODEL
158161

159162
__slots__ = ("version", "paths", "configurations")
160163

cmake_file_api/kinds/common.py

Lines changed: 6 additions & 13 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
13-
def from_dict(cls, d: dict[str, str]) -> "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-
)
12+
def from_dict(cls, d: dict[str, int]) -> "VersionMajorMinor":
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)