@@ -1244,26 +1244,35 @@ fn find_interpreter_in_sysconfig(
12441244 let mut interpreters = Vec :: new ( ) ;
12451245 for interp in interpreter {
12461246 let python = interp. display ( ) . to_string ( ) ;
1247- let ( python_impl, python_ver) = if let Some ( ver) = python. strip_prefix ( "pypy" ) {
1248- ( InterpreterKind :: PyPy , ver. strip_prefix ( '-' ) . unwrap_or ( ver) )
1249- } else if let Some ( ver) = python. strip_prefix ( "graalpy" ) {
1247+ let ( python_impl, python_ver, abiflags) = if let Some ( ver) = python. strip_prefix ( "pypy" ) {
12501248 (
1251- InterpreterKind :: GraalPy ,
1249+ InterpreterKind :: PyPy ,
12521250 ver. strip_prefix ( '-' ) . unwrap_or ( ver) ,
1251+ "" ,
12531252 )
1254- } else if let Some ( ver) = python. strip_prefix ( "python " ) {
1253+ } else if let Some ( ver) = python. strip_prefix ( "graalpy " ) {
12551254 (
1256- InterpreterKind :: CPython ,
1255+ InterpreterKind :: GraalPy ,
12571256 ver. strip_prefix ( '-' ) . unwrap_or ( ver) ,
1257+ "" ,
12581258 )
1259+ } else if let Some ( ver) = python. strip_prefix ( "python" ) {
1260+ // Also accept things like `python3.13t` for free-threaded python
1261+ let ( ver, abiflags) =
1262+ if let Some ( ver) = ver. strip_prefix ( '-' ) . unwrap_or ( ver) . strip_suffix ( 't' ) {
1263+ ( ver, "t" )
1264+ } else {
1265+ ( ver, "" )
1266+ } ;
1267+ ( InterpreterKind :: CPython , ver, abiflags)
12591268 } else if python
12601269 . chars ( )
12611270 . next ( )
12621271 . map ( |c| c. is_ascii_digit ( ) )
12631272 . unwrap_or ( false )
12641273 {
12651274 // Eg: -i 3.9 without interpreter kind, assume it's CPython
1266- ( InterpreterKind :: CPython , & * python)
1275+ ( InterpreterKind :: CPython , & * python, "" )
12671276 } else {
12681277 // if interpreter not known
12691278 if std:: path:: Path :: new ( & python) . is_file ( ) {
@@ -1284,7 +1293,12 @@ fn find_interpreter_in_sysconfig(
12841293 let ver_minor = ver_minor. parse :: < usize > ( ) . with_context ( || {
12851294 format ! ( "Invalid python interpreter minor version '{ver_minor}', expect a digit" )
12861295 } ) ?;
1287- let sysconfig = InterpreterConfig :: lookup_one ( target, python_impl, ( ver_major, ver_minor) )
1296+
1297+ if ( ver_major, ver_minor) < ( 3 , 13 ) && abiflags == "t" {
1298+ bail ! ( "Free-threaded Python interpreter is only supported on 3.13 and later." ) ;
1299+ }
1300+
1301+ let sysconfig = InterpreterConfig :: lookup_one ( target, python_impl, ( ver_major, ver_minor) , abiflags)
12881302 . with_context ( || {
12891303 format ! ( "Failed to find a {python_impl} {ver_major}.{ver_minor} interpreter in known sysconfig" )
12901304 } ) ?;
0 commit comments