Skip to content

Commit

Permalink
chore: integrate types and typecheck (#482)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Apr 7, 2024
1 parent a674047 commit 3d70935
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ repos:
hooks:
- id: mypy
files: ^(src|scripts)
exclude: ^src/cmake/__init__.py$
additional_dependencies: [types-requests]
args: []
25 changes: 18 additions & 7 deletions src/cmake/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import os
import subprocess
import sys
from pathlib import Path

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

from ._version import version as __version__

TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Iterable, NoReturn


__all__ = ["__version__", "CMAKE_DATA", "CMAKE_BIN_DIR", "CMAKE_DOC_DIR", "CMAKE_SHARE_DIR", "cmake", "cpack", "ctest"]


def __dir__():
def __dir__() -> list[str]:
return __all__


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


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


def cmake():
def cmake() -> NoReturn:
raise SystemExit(_program('cmake', sys.argv[1:]))


def cpack():
def cpack() -> NoReturn:
raise SystemExit(_program('cpack', sys.argv[1:]))


def ctest():
def ctest() -> NoReturn:
raise SystemExit(_program('ctest', sys.argv[1:]))
15 changes: 0 additions & 15 deletions src/cmake/__init__.pyi

This file was deleted.

0 comments on commit 3d70935

Please sign in to comment.