7474 'reset' : '\33 [0m' ,
7575}
7676_NO_COLORS = {color : '' for color in _COLORS }
77- _NINJA_REQUIRED_VERSION = (1 , 8 , 2 )
78- _NINJA_REQUIRED_VERSION_STR = '.' .join (str (v ) for v in _NINJA_REQUIRED_VERSION )
77+ _NINJA_REQUIRED_VERSION = '1.8.2'
7978
8079
8180class _depstr :
@@ -84,7 +83,7 @@ class _depstr:
8483 """
8584 patchelf = 'patchelf >= 0.11.0'
8685 wheel = 'wheel >= 0.36.0' # noqa: F811
87- ninja = f'ninja >= { _NINJA_REQUIRED_VERSION_STR } '
86+ ninja = f'ninja >= { _NINJA_REQUIRED_VERSION } '
8887
8988
9089def _init_colors () -> Dict [str , str ]:
@@ -560,6 +559,12 @@ def __init__(
560559 self ._build_dir = pathlib .Path (build_dir ).absolute () if build_dir else (self ._working_dir / 'build' )
561560 self ._install_dir = self ._working_dir / 'install'
562561 self ._meson_native_file = self ._source_dir / '.mesonpy-native-file.ini'
562+ self ._env = os .environ .copy ()
563+
564+ # prepare environment
565+ ninja_path = _env_ninja_command ()
566+ if ninja_path is not None :
567+ self ._env .setdefault ('NINJA' , str (ninja_path ))
563568
564569 # load config -- PEP 621 support is optional
565570 self ._config = tomllib .loads (self ._source_dir .joinpath ('pyproject.toml' ).read_text ())
@@ -614,7 +619,7 @@ def __init__(
614619 def _proc (self , * args : str ) -> None :
615620 """Invoke a subprocess."""
616621 print ('{cyan}{bold}+ {}{reset}' .format (' ' .join (args ), ** _STYLES ))
617- subprocess .check_call (list (args ))
622+ subprocess .check_call (list (args ), env = self . _env )
618623
619624 def _meson (self , * args : str ) -> None :
620625 """Invoke Meson."""
@@ -891,7 +896,11 @@ def _project(config_settings: Optional[Dict[Any, Any]]) -> Iterator[Project]:
891896 yield project
892897
893898
894- def _env_has_ninja_command () -> bool :
899+ def _env_ninja_command (* , version : str = _NINJA_REQUIRED_VERSION ) -> Optional [pathlib .Path ]:
900+ """
901+ Returns the path to ninja, or None if no ninja found.
902+ """
903+ required_version = tuple (int (v ) for v in version .split ('.' ))
895904 env_ninja = os .environ .get ('NINJA' , None )
896905 ninja_candidates = [env_ninja ] if env_ninja else ['ninja' , 'ninja-build' , 'samu' ]
897906 for ninja in ninja_candidates :
@@ -905,18 +914,17 @@ def _env_has_ninja_command() -> bool:
905914 candidate_version = tuple (int (x ) for x in result .stdout .split ('.' )[:3 ])
906915 except ValueError :
907916 continue
908- if candidate_version < _NINJA_REQUIRED_VERSION :
917+ if candidate_version < required_version :
909918 continue
910- return True
919+ return pathlib . Path ( ninja_path )
911920
912- return False
921+ return None
913922
914923
915924def get_requires_for_build_sdist (
916925 config_settings : Optional [Dict [str , str ]] = None ,
917926) -> List [str ]:
918-
919- return [] if _env_has_ninja_command () else [_depstr .ninja ]
927+ return [_depstr .ninja ] if _env_ninja_command () is None else []
920928
921929
922930def build_sdist (
@@ -935,7 +943,7 @@ def get_requires_for_build_wheel(
935943) -> List [str ]:
936944 dependencies = [_depstr .wheel ]
937945
938- if not _env_has_ninja_command () :
946+ if _env_ninja_command () is None :
939947 dependencies .append (_depstr .ninja )
940948
941949 if sys .platform .startswith ('linux' ):
0 commit comments