Skip to content

Commit 3d70935

Browse files
authored
chore: integrate types and typecheck (#482)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent a674047 commit 3d70935

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ repos:
2828
hooks:
2929
- id: mypy
3030
files: ^(src|scripts)
31-
exclude: ^src/cmake/__init__.py$
3231
additional_dependencies: [types-requests]
3332
args: []

src/cmake/__init__.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from __future__ import annotations
2+
13
import os
24
import subprocess
35
import sys
6+
from pathlib import Path
47

58
if sys.version_info < (3, 8):
69
from importlib_metadata import distribution
@@ -9,17 +12,25 @@
912

1013
from ._version import version as __version__
1114

15+
TYPE_CHECKING = False
16+
17+
if TYPE_CHECKING:
18+
from typing import Iterable, NoReturn
19+
20+
1221
__all__ = ["__version__", "CMAKE_DATA", "CMAKE_BIN_DIR", "CMAKE_DOC_DIR", "CMAKE_SHARE_DIR", "cmake", "cpack", "ctest"]
1322

1423

15-
def __dir__():
24+
def __dir__() -> list[str]:
1625
return __all__
1726

1827

1928
cmake_executable_path = None
20-
for script in distribution("cmake").files:
29+
cmake_files = distribution("cmake").files
30+
assert cmake_files is not None, "This is the cmake package so it must be installed and have files"
31+
for script in cmake_files:
2132
if str(script).startswith("cmake/data/bin/cmake"):
22-
resolved_script = script.locate().resolve(strict=True)
33+
resolved_script = Path(script.locate()).resolve(strict=True)
2334
cmake_executable_path = resolved_script.parents[1]
2435
break
2536
CMAKE_DATA = str(cmake_executable_path) if cmake_executable_path else None
@@ -32,17 +43,17 @@ def __dir__():
3243
CMAKE_SHARE_DIR = os.path.join(CMAKE_DATA, 'share')
3344

3445

35-
def _program(name, args):
46+
def _program(name: str, args: Iterable[str]) -> int:
3647
return subprocess.call([os.path.join(CMAKE_BIN_DIR, name), *args], close_fds=False)
3748

3849

39-
def cmake():
50+
def cmake() -> NoReturn:
4051
raise SystemExit(_program('cmake', sys.argv[1:]))
4152

4253

43-
def cpack():
54+
def cpack() -> NoReturn:
4455
raise SystemExit(_program('cpack', sys.argv[1:]))
4556

4657

47-
def ctest():
58+
def ctest() -> NoReturn:
4859
raise SystemExit(_program('ctest', sys.argv[1:]))

src/cmake/__init__.pyi

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)