11import os
22import sys
3+ import sysconfig
34
45import pytest
56
1112from hatch .utils .structures import EnvVars
1213from hatchling .utils .constants import DEFAULT_BUILD_SCRIPT , DEFAULT_CONFIG_FILE
1314
15+ FREE_THREADED_BUILD = bool (sysconfig .get_config_var ("Py_GIL_DISABLED" ))
16+
1417
1518@pytest .fixture (scope = "module" )
1619def available_python_version ():
@@ -1214,6 +1217,9 @@ def test_incompatible_missing_python(hatch, helpers, temp_dir, config_file):
12141217 data_path .mkdir ()
12151218
12161219 known_version = "" .join (map (str , sys .version_info [:2 ]))
1220+ if FREE_THREADED_BUILD :
1221+ known_version += "t"
1222+
12171223 project = Project (project_path )
12181224 helpers .update_project_environment (project , "default" , {"skip-install" : True , ** project .config .envs ["default" ]})
12191225 helpers .update_project_environment (project , "test" , {"matrix" : [{"python" : [known_version , "9000" ]}]})
@@ -1222,15 +1228,18 @@ def test_incompatible_missing_python(hatch, helpers, temp_dir, config_file):
12221228 result = hatch (
12231229 "run" , "test:python" , "-c" , "import os,sys;open('test.txt', 'a').write(sys.executable+os.linesep[-1])"
12241230 )
1225-
12261231 padding = "─"
1227- if len (known_version ) < 3 :
1228- padding += "─"
1232+ if FREE_THREADED_BUILD :
1233+ pre_padding = ""
1234+ else :
1235+ pre_padding = "─"
1236+ if len (known_version ) < 3 :
1237+ padding += "─"
12291238
12301239 assert result .exit_code == 0 , result .output
12311240 assert result .output == helpers .dedent (
12321241 f"""
1233- ────────────────────────────────── test.py{ known_version } ─────────────────────────────────{ padding }
1242+ ─────────────────────────────────{ pre_padding } test.py{ known_version } ─────────────────────────────────{ padding }
12341243 Creating environment: test.py{ known_version }
12351244 Checking dependencies
12361245
@@ -2575,6 +2584,9 @@ def test_python_version_constraint_from_tool_config(self, hatch, helpers, temp_d
25752584 # Use the current minor version so that the current Python
25762585 # will be used and distributions don't have to be downloaded
25772586 major , minor = sys .version_info [:2 ]
2587+ python_version = f"{ major } .{ minor } "
2588+ if FREE_THREADED_BUILD :
2589+ python_version += "t"
25782590
25792591 script .write_text (
25802592 helpers .dedent (
@@ -2583,7 +2595,7 @@ def test_python_version_constraint_from_tool_config(self, hatch, helpers, temp_d
25832595 # requires-python = ">9000"
25842596 #
25852597 # [tool.hatch]
2586- # python = "{ major } . { minor } "
2598+ # python = "{ python_version } "
25872599 # ///
25882600 import pathlib
25892601 import sys
0 commit comments