forked from scikit-build/cmake-python-distributions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
65 lines (42 loc) · 1.74 KB
/
Copy path__init__.py
File metadata and controls
65 lines (42 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations
import os
import subprocess
import sys
from importlib.metadata import distribution
from pathlib import Path
from ._version import version as __version__
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Iterable, NoReturn
__all__ = ["CMAKE_BIN_DIR", "CMAKE_DATA", "CMAKE_DOC_DIR", "CMAKE_SHARE_DIR", "__version__", "cmake", "cpack", "ctest"]
def __dir__() -> list[str]:
return __all__
cmake_executable_path = None
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 = 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
assert CMAKE_DATA is not None
assert os.path.exists(CMAKE_DATA)
CMAKE_BIN_DIR = os.path.join(CMAKE_DATA, 'bin')
CMAKE_DOC_DIR = os.path.join(CMAKE_DATA, 'doc')
CMAKE_SHARE_DIR = os.path.join(CMAKE_DATA, 'share')
def _program(name: str, args: Iterable[str]) -> int:
return subprocess.call([os.path.join(CMAKE_BIN_DIR, name), *args], close_fds=False)
def _program_exit(name: str, *args: str) -> NoReturn:
if sys.platform.startswith("win"):
raise SystemExit(_program(name, args))
cmake_exe = os.path.join(CMAKE_BIN_DIR, name)
os.execl(cmake_exe, cmake_exe, *args)
def ccmake() -> NoReturn:
_program_exit('ccmake', *sys.argv[1:])
def cmake() -> NoReturn:
_program_exit('cmake', *sys.argv[1:])
def cpack() -> NoReturn:
_program_exit('cpack', *sys.argv[1:])
def ctest() -> NoReturn:
_program_exit('ctest', *sys.argv[1:])