@@ -1579,17 +1579,28 @@ fn read_recursion_depth_from_environment_variable() -> anyhow::Result<u32> {
1579
1579
1580
1580
/// Matches valid Python executable names and returns the version part if valid:
1581
1581
/// - ✅ "python" -> Some("")
1582
- /// - ✅ "python39" -> Some("39")
1582
+ /// - ✅ "/usr/bin/python3.9" -> Some("3.9")
1583
+ /// - ✅ "/path/to/python39" -> Some("39")
1583
1584
/// - ✅ "python3" -> Some("3")
1584
- /// - ✅ "python3.9" -> Some("3.9")
1585
+ /// - ✅ "python3.exe" -> Some("3")
1586
+ /// - ✅ "python3.9.exe" -> Some("3.9")
1585
1587
/// - ❌ "python3abc" -> None
1586
1588
/// - ❌ "python3.12b3" -> None
1587
1589
/// - ❌ "" -> None
1588
1590
/// - ❌ "python-foo" -> None
1591
+ /// - ❌ "Python" -> None // Case-sensitive
1589
1592
fn python_executable_version ( executable_command : & str ) -> Option < & str > {
1590
- executable_command
1591
- . strip_prefix ( "python" )
1592
- . filter ( |version| version. is_empty ( ) || validate_python_version ( version) . is_ok ( ) )
1593
+ const PYTHON_MARKER : & str = "python" ;
1594
+
1595
+ // Strip suffix for windows .exe
1596
+ let command = executable_command
1597
+ . strip_suffix ( ".exe" )
1598
+ . unwrap_or ( executable_command) ;
1599
+ let version_start = command. rfind ( PYTHON_MARKER ) ? + PYTHON_MARKER . len ( ) ;
1600
+ // Retrieve python version string. E.g. "python3.12" -> "3.12"
1601
+ let version = command. get ( version_start..) ?;
1602
+
1603
+ Some ( version) . filter ( |& v| v. is_empty ( ) || validate_python_version ( v) . is_ok ( ) )
1593
1604
}
1594
1605
1595
1606
/// Validates if a version string is a valid Python major.minor.patch version.
@@ -1628,6 +1639,9 @@ mod tests {
1628
1639
( "python3" , Some ( "3" ) ) ,
1629
1640
( "python3.9" , Some ( "3.9" ) ) ,
1630
1641
( "python3.10" , Some ( "3.10" ) ) ,
1642
+ ( "/usr/bin/python3.9" , Some ( "3.9" ) ) ,
1643
+ ( "python3.9.exe" , Some ( "3.9" ) ) ,
1644
+ ( "python3.9.exe" , Some ( "3.9" ) ) ,
1631
1645
( "python4" , Some ( "4" ) ) ,
1632
1646
( "python" , Some ( "" ) ) ,
1633
1647
( "python3.11.3" , Some ( "3.11.3" ) ) ,
0 commit comments