@@ -1108,28 +1108,25 @@ def _project(config_settings: Optional[Dict[Any, Any]]) -> Iterator[Project]:
1108
1108
yield project
1109
1109
1110
1110
1111
+ def _parse_version_string (string : str ) -> Tuple [int , ...]:
1112
+ """Parse version string."""
1113
+ try :
1114
+ return tuple (map (int , string .split ('.' )[:3 ]))
1115
+ except ValueError :
1116
+ return (0 , )
1117
+
1118
+
1111
1119
def _env_ninja_command (* , version : str = _NINJA_REQUIRED_VERSION ) -> Optional [str ]:
1112
- """
1113
- Returns the path to ninja, or None if no ninja found.
1114
- """
1115
- required_version = tuple (int (v ) for v in version .split ('.' ))
1120
+ """Returns the path to ninja, or None if no ninja found."""
1121
+ required_version = _parse_version_string (version )
1116
1122
env_ninja = os .environ .get ('NINJA' )
1117
1123
ninja_candidates = [env_ninja ] if env_ninja else ['ninja' , 'ninja-build' , 'samu' ]
1118
1124
for ninja in ninja_candidates :
1119
1125
ninja_path = shutil .which (ninja )
1120
- if ninja_path is None :
1121
- continue
1122
-
1123
- result = subprocess .run ([ninja_path , '--version' ], check = False , text = True , capture_output = True )
1124
-
1125
- try :
1126
- candidate_version = tuple (int (x ) for x in result .stdout .split ('.' )[:3 ])
1127
- except ValueError :
1128
- continue
1129
- if candidate_version < required_version :
1130
- continue
1131
- return ninja_path
1132
-
1126
+ if ninja_path is not None :
1127
+ version = subprocess .run ([ninja_path , '--version' ], check = False , text = True , capture_output = True ).stdout
1128
+ if _parse_version_string (version ) >= required_version :
1129
+ return ninja_path
1133
1130
return None
1134
1131
1135
1132
0 commit comments