Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- run: pip install mypy
- run: python -m pip install -r requirements-dev.txt
- run: mypy --install-types --non-interactive --strict

pylint:
Expand All @@ -43,5 +43,24 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- run: pip install pylint
- run: python -m pip install -r requirements-dev.txt
- run: pylint --verbose --fail-under=10 --rcfile .pylintrc cmake_file_api

mypyc:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py: ['3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.py }}
- run: python -m pip install -r requirements-dev.txt
- run: python setup.py bdist_wheel --dist-dir wheelhouse
- run: ls -al wheelhouse
- run: python -m pip install --no-deps --no-index --find-links=wheelhouse/ cmake_file_api
- run: python -m pip show --verbose cmake_file_api
- run: rm -rf cmake_file_api/
- run: python -m pytest --log-cli-level=info -vvv tests/
6 changes: 4 additions & 2 deletions cmake_file_api/kinds/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@


class CMakeApiType(Protocol):
KIND: ObjectKind
@staticmethod
def kind() -> ObjectKind:
...

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

OBJECT_KINDS_API: dict[ObjectKind, dict[int, CMakeApiType]] = {
OBJECT_KINDS_API: dict[ObjectKind, dict[int, type[CMakeApiType]]] = {
ObjectKind.CACHE: CACHE_API,
ObjectKind.CMAKEFILES: CMAKEFILES_API,
ObjectKind.CONFIGURELOG: CONFIGURELOG_API,
Expand Down
2 changes: 1 addition & 1 deletion cmake_file_api/kinds/cache/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
if typing.TYPE_CHECKING:
from ..api import CMakeApiType

CACHE_API: dict[int, CMakeApiType] = {
CACHE_API: dict[int, type[CMakeApiType]] = {
2: CacheV2,
}
23 changes: 8 additions & 15 deletions cmake_file_api/kinds/cache/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
import json
from pathlib import Path
from typing import Any, ClassVar
from typing import Any

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

@dataclasses.dataclass(frozen=True, slots=True)
class CacheV2:
KIND: ClassVar = ObjectKind.CACHE
version: VersionMajorMinor
entries: list[CacheEntry]

__slots__ = ("version", "entries")

def __init__(self, version: VersionMajorMinor, entries: list[CacheEntry]):
self.version = version
self.entries = entries
@staticmethod
def kind() -> ObjectKind:
return ObjectKind.CACHE

@classmethod
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CacheV2":
if dikt["kind"] != cls.KIND.value:
if dikt["kind"] != cls.kind():
raise ValueError
version = VersionMajorMinor.from_dict(dikt["version"])
entries = list(CacheEntry.from_dict(ce) for ce in dikt["entries"])
Expand All @@ -65,10 +65,3 @@ def from_path(cls, path: Path, reply_path: Path) -> "CacheV2":
with path.open() as file:
dikt = json.load(file)
return cls.from_dict(dikt, reply_path)

def __repr__(self) -> str:
return "{}(version={}, entries={})".format(
type(self).__name__,
repr(self.version),
repr(self.entries),
)
2 changes: 1 addition & 1 deletion cmake_file_api/kinds/cmakeFiles/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
if typing.TYPE_CHECKING:
from ..api import CMakeApiType

CMAKEFILES_API: dict[int, CMakeApiType] = {
CMAKEFILES_API: dict[int, type[CMakeApiType]] = {
1: CMakeFilesV1,
}
23 changes: 8 additions & 15 deletions cmake_file_api/kinds/cmakeFiles/v1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
import json
from pathlib import Path
from typing import Any, Optional
Expand Down Expand Up @@ -33,15 +34,15 @@ def __repr__(self) -> str:
)


@dataclasses.dataclass(frozen=True, slots=True)
class CMakeFilesV1:
KIND = ObjectKind.CMAKEFILES
version: VersionMajorMinor
paths: CMakeSourceBuildPaths
inputs: list[CMakeFilesInput]

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

def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, inputs: list[CMakeFilesInput]):
self.version = version
self.paths = paths
self.inputs = inputs
@staticmethod
def kind() -> ObjectKind:
return ObjectKind.CMAKEFILES

@classmethod
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CMakeFilesV1":
Expand All @@ -55,11 +56,3 @@ 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)

def __repr__(self) -> str:
return "{}(version={}, paths={}, inputs={})".format(
type(self).__name__,
repr(self.version),
self.paths,
repr(self.inputs),
)
2 changes: 1 addition & 1 deletion cmake_file_api/kinds/codemodel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
if typing.TYPE_CHECKING:
from ..api import CMakeApiType

CODEMODEL_API: dict[int, CMakeApiType] = {
CODEMODEL_API: dict[int, type[CMakeApiType]] = {
2: CodemodelV2,
}
27 changes: 10 additions & 17 deletions cmake_file_api/kinds/codemodel/v2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataclasses
import json
from pathlib import Path
from typing import Any, ClassVar, Optional
from typing import Any, Optional

from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor
from cmake_file_api.kinds.kind import ObjectKind
Expand Down Expand Up @@ -153,19 +154,19 @@ def __repr__(self) -> str:
)


@dataclasses.dataclass(frozen=True, slots=True)
class CodemodelV2:
KIND: ClassVar = ObjectKind.CODEMODEL
version: VersionMajorMinor
paths: CMakeSourceBuildPaths
configurations: list[CMakeConfiguration]

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

def __init__(self, version: VersionMajorMinor, paths: CMakeSourceBuildPaths, configurations: list[CMakeConfiguration]):
self.version = version
self.paths = paths
self.configurations = configurations
@staticmethod
def kind() -> ObjectKind:
return ObjectKind.CODEMODEL

@classmethod
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CodemodelV2":
if dikt["kind"] != cls.KIND.value:
if dikt["kind"] != cls.kind():
raise ValueError
paths = CMakeSourceBuildPaths.from_dict(dikt["paths"])
version = VersionMajorMinor.from_dict(dikt["version"])
Expand All @@ -183,11 +184,3 @@ def get_configuration(self, name: str) -> CMakeConfiguration:
return next(c for c in self.configurations if c.name == name)
except StopIteration:
raise KeyError("Unknown configuration")

def __repr__(self) -> str:
return "{}(version={}, paths={}, configurations={})".format(
type(self).__name__,
self.version,
self.paths,
self.configurations,
)
17 changes: 5 additions & 12 deletions cmake_file_api/kinds/common.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import dataclasses
from pathlib import Path
from typing import Any


@dataclasses.dataclass(frozen=True, slots=True)
class VersionMajorMinor:
__slots__ = ("major", "minor")

def __init__(self, major: int, minor: int):
self.major = major
self.minor = minor
major: int
minor: int

@classmethod
def from_dict(cls, d: dict[str, int]) -> "VersionMajorMinor":
return cls(int(d["major"]), int(d["minor"]))

def __repr__(self) -> str:
return "Version({}.{})".format(
self.major,
self.minor,
)
return cls(d["major"], d["minor"])


class CMakeSourceBuildPaths:
Expand Down
2 changes: 1 addition & 1 deletion cmake_file_api/kinds/configureLog/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
if typing.TYPE_CHECKING:
from ..api import CMakeApiType

CONFIGURELOG_API: dict[int, CMakeApiType] = {
CONFIGURELOG_API: dict[int, type[CMakeApiType]] = {
1: ConfigureLogV1,
}
27 changes: 10 additions & 17 deletions cmake_file_api/kinds/configureLog/v1.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import dataclasses
import json
from pathlib import Path
from typing import Any, ClassVar
from typing import Any

from cmake_file_api.kinds.common import VersionMajorMinor
from cmake_file_api.kinds.kind import ObjectKind


@dataclasses.dataclass(frozen=True, slots=True)
class ConfigureLogV1:
KIND: ClassVar = ObjectKind.CONFIGURELOG
version: VersionMajorMinor
path: Path
eventKindNames: list[str]

__slots__ = ("version", "path", "eventKindNames")

def __init__(self, version: VersionMajorMinor, path: Path, eventKindNames: list[str]):
self.version = version
self.path = path
self.eventKindNames = eventKindNames
@staticmethod
def kind() -> ObjectKind:
return ObjectKind.CONFIGURELOG

@classmethod
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ConfigureLogV1":
if dikt["kind"] != cls.KIND.value:
if dikt["kind"] != cls.kind():
raise ValueError
path = Path(dikt["path"])
version = VersionMajorMinor.from_dict(dikt["version"])
Expand All @@ -30,11 +31,3 @@ def from_path(cls, path: Path, reply_path: Path) -> "ConfigureLogV1":
with path.open() as file:
dikt = json.load(file)
return cls.from_dict(dikt, reply_path)

def __repr__(self) -> str:
return "{}(version={}, paths={}, configurations={})".format(
type(self).__name__,
self.version,
self.path,
self.eventKindNames,
)
8 changes: 6 additions & 2 deletions cmake_file_api/kinds/kind.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import enum
import sys

if sys.version_info >= (3, 11):
from enum import StrEnum
else:
from backports.strenum.strenum import StrEnum

class ObjectKind(enum.Enum):
class ObjectKind(StrEnum):
CACHE = "cache"
CMAKEFILES = "cmakeFiles"
CODEMODEL = "codemodel"
Expand Down
2 changes: 1 addition & 1 deletion cmake_file_api/kinds/toolchains/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
if typing.TYPE_CHECKING:
from ..api import CMakeApiType

TOOLCHAINS_API: dict[int, CMakeApiType] = {
TOOLCHAINS_API: dict[int, type[CMakeApiType]] = {
1: ToolchainsV1,
}
6 changes: 4 additions & 2 deletions cmake_file_api/kinds/toolchains/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CMakeToolchain":

@dataclasses.dataclass(frozen=True, slots=True)
class ToolchainsV1:
KIND = ObjectKind.TOOLCHAINS

version: VersionMajorMinor
toolchains: list[CMakeToolchain]

@staticmethod
def kind() -> ObjectKind:
return ObjectKind.TOOLCHAINS

@classmethod
def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ToolchainsV1":
return cls(
Expand Down
2 changes: 1 addition & 1 deletion cmake_file_api/reply/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeApiType]
data_path = index.reply.stateless.get((kind, kind_version), None)
if data_path is None:
return None
api: Optional[CMakeApiType] = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None)
api: Optional[type[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)
Expand Down
5 changes: 4 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
backports.strenum
pylint
pytest
mypy
mypy[mypyc]
typeguard
vcs-versioning
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ python_requires = >=3.10
packages=find:
setup_requires =
setuptools_scm
install_requires =
backports.strenum; python_version < "3.11"

[options.packages.find]
exclude =
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from setuptools import setup

from mypyc.build import mypycify

setup(use_scm_version=True)
setup(
use_scm_version=True,
ext_modules=mypycify(paths=['cmake_file_api/'], verbose=True),
)