74
74
'reset' : '\33 [0m' ,
75
75
}
76
76
_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'
79
78
80
79
81
80
class _depstr :
@@ -84,7 +83,7 @@ class _depstr:
84
83
"""
85
84
patchelf = 'patchelf >= 0.11.0'
86
85
wheel = 'wheel >= 0.36.0' # noqa: F811
87
- ninja = f'ninja >= { _NINJA_REQUIRED_VERSION_STR } '
86
+ ninja = f'ninja >= { _NINJA_REQUIRED_VERSION } '
88
87
89
88
90
89
def _init_colors () -> Dict [str , str ]:
@@ -560,6 +559,12 @@ def __init__(
560
559
self ._build_dir = pathlib .Path (build_dir ).absolute () if build_dir else (self ._working_dir / 'build' )
561
560
self ._install_dir = self ._working_dir / 'install'
562
561
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 ))
563
568
564
569
# load config -- PEP 621 support is optional
565
570
self ._config = tomllib .loads (self ._source_dir .joinpath ('pyproject.toml' ).read_text ())
@@ -614,7 +619,7 @@ def __init__(
614
619
def _proc (self , * args : str ) -> None :
615
620
"""Invoke a subprocess."""
616
621
print ('{cyan}{bold}+ {}{reset}' .format (' ' .join (args ), ** _STYLES ))
617
- subprocess .check_call (list (args ))
622
+ subprocess .check_call (list (args ), env = self . _env )
618
623
619
624
def _meson (self , * args : str ) -> None :
620
625
"""Invoke Meson."""
@@ -891,7 +896,11 @@ def _project(config_settings: Optional[Dict[Any, Any]]) -> Iterator[Project]:
891
896
yield project
892
897
893
898
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 ('.' ))
895
904
env_ninja = os .environ .get ('NINJA' , None )
896
905
ninja_candidates = [env_ninja ] if env_ninja else ['ninja' , 'ninja-build' , 'samu' ]
897
906
for ninja in ninja_candidates :
@@ -905,18 +914,17 @@ def _env_has_ninja_command() -> bool:
905
914
candidate_version = tuple (int (x ) for x in result .stdout .split ('.' )[:3 ])
906
915
except ValueError :
907
916
continue
908
- if candidate_version < _NINJA_REQUIRED_VERSION :
917
+ if candidate_version < required_version :
909
918
continue
910
- return True
919
+ return pathlib . Path ( ninja_path )
911
920
912
- return False
921
+ return None
913
922
914
923
915
924
def get_requires_for_build_sdist (
916
925
config_settings : Optional [Dict [str , str ]] = None ,
917
926
) -> List [str ]:
918
-
919
- return [] if _env_has_ninja_command () else [_depstr .ninja ]
927
+ return [_depstr .ninja ] if _env_ninja_command () is None else []
920
928
921
929
922
930
def build_sdist (
@@ -935,7 +943,7 @@ def get_requires_for_build_wheel(
935
943
) -> List [str ]:
936
944
dependencies = [_depstr .wheel ]
937
945
938
- if not _env_has_ninja_command () :
946
+ if _env_ninja_command () is None :
939
947
dependencies .append (_depstr .ninja )
940
948
941
949
if sys .platform .startswith ('linux' ):
0 commit comments