66import logging
77import os
88import sys
9+ import sysconfig
910from abc import ABC
1011from functools import cached_property
1112from importlib .resources import as_file , files
@@ -131,6 +132,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: PLR
131132 is_64 = sys .maxsize > 2 ** 32 ,
132133 platform = sys .platform ,
133134 extra = {},
135+ free_threaded = sysconfig .get_config_var ("Py_GIL_DISABLED" ) == 1 ,
134136 )
135137 base_path = Path (base )
136138 if base_path .is_absolute ():
@@ -142,6 +144,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: PLR
142144 is_64 = info .architecture == 64 , # noqa: PLR2004
143145 platform = info .platform ,
144146 extra = {"executable" : base },
147+ free_threaded = info .free_threaded ,
145148 )
146149 spec = PythonSpec .from_string_spec (base )
147150 return PythonInfo (
@@ -157,6 +160,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: PLR
157160 is_64 = spec .architecture == 64 , # noqa: PLR2004
158161 platform = sys .platform ,
159162 extra = {"architecture" : spec .architecture },
163+ free_threaded = spec .free_threaded ,
160164 )
161165
162166 return None # pragma: no cover
@@ -256,25 +260,28 @@ def env_version_spec(self) -> str:
256260 imp = self .base_python .impl_lower
257261 executable = self .base_python .extra .get ("executable" )
258262 architecture = self .base_python .extra .get ("architecture" )
263+ free_threaded = self .base_python .free_threaded
259264 if executable :
260265 version_spec = str (executable )
261266 elif (
262267 architecture is None
263268 and (base .major , base .minor ) == sys .version_info [:2 ]
264269 and (sys .implementation .name .lower () == imp )
270+ and ((sysconfig .get_config_var ("Py_GIL_DISABLED" ) == 1 ) == free_threaded )
265271 ):
266272 version_spec = sys .executable
267273 else :
268274 uv_imp = imp or ""
275+ free_threaded_tag = "+freethreaded" if free_threaded else ""
269276 if not base .major :
270277 version_spec = f"{ uv_imp } "
271278 elif not base .minor :
272- version_spec = f"{ uv_imp } { base .major } "
279+ version_spec = f"{ uv_imp } { base .major } { free_threaded_tag } "
273280 elif architecture is not None and self .base_python .platform == "win32" :
274281 uv_arch = {32 : "x86" , 64 : "x86_64" }[architecture ]
275- version_spec = f"{ uv_imp } -{ base .major } .{ base .minor } -windows-{ uv_arch } -none"
282+ version_spec = f"{ uv_imp } -{ base .major } .{ base .minor } { free_threaded_tag } -windows-{ uv_arch } -none"
276283 else :
277- version_spec = f"{ uv_imp } { base .major } .{ base .minor } "
284+ version_spec = f"{ uv_imp } { base .major } .{ base .minor } { free_threaded_tag } "
278285 return version_spec
279286
280287 @cached_property
0 commit comments