1+ from __future__ import annotations
2+
13import os
24import subprocess
35import sys
6+ from pathlib import Path
47
58if sys .version_info < (3 , 8 ):
69 from importlib_metadata import distribution
912
1013from ._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
1928cmake_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
2536CMAKE_DATA = str (cmake_executable_path ) if cmake_executable_path else None
@@ -32,17 +43,17 @@ def __dir__():
3243CMAKE_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 :]))
0 commit comments