Skip to content

Commit 7f6329f

Browse files
committed
Default free threaded off
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 395919d commit 7f6329f

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

.github/workflows/check.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
py:
26+
- "3.14t"
2627
- "3.14"
2728
- "3.13"
2829
- "3.12"
@@ -51,6 +52,8 @@ jobs:
5152
run: uv tool install --python-preference only-managed --python ${{ matrix.py }} tox@.
5253
- name: Setup test suite
5354
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py }}
55+
env:
56+
PYTHON_GIL: ${{ !endsWith(matrix.py, 't') }}
5457
- name: Run test suite
5558
run: tox run --skip-pkg-install -e ${{ matrix.py }}
5659
env:

docs/config.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,10 @@ Base options
542542
- ✅
543543
- ✅
544544
- ❌
545-
546-
545+
* - PYTHON_GIL
546+
- ✅
547+
- ✅
548+
- ✅
547549

548550
More environment variable-related information
549551
can be found in :ref:`environment variable substitutions`.
@@ -834,6 +836,7 @@ Python options
834836
Python version for a tox environment. If not specified, the virtual environments factors (e.g. name part) will be
835837
used to automatically set one. For example, ``py310`` means ``python3.10``, ``py3`` means ``python3`` and ``py``
836838
means ``python``. If the name does not match this pattern the same Python version tox is installed into will be used.
839+
A base interpreter ending with ``t`` means that only free threaded Python implementations are accepted.
837840

838841
.. versionchanged:: 3.1
839842

src/tox/tox_env/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def _default_pass_env(self) -> list[str]: # noqa: PLR6301
222222
"FORCE_COLOR", # force color output
223223
"NO_COLOR", # disable color output
224224
"NETRC", # used by pip and netrc modules
225+
"PYTHON_GIL", # allows controlling python gil
225226
]
226227
if sys.stdout.isatty(): # if we're on a interactive shell pass on the TERM
227228
env.append("TERM")

src/tox/tox_env/python/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import sys
88
import sysconfig
99
from abc import ABC, abstractmethod
10+
from dataclasses import dataclass
1011
from pathlib import Path
11-
from typing import TYPE_CHECKING, Any, List, NamedTuple, cast
12+
from typing import TYPE_CHECKING, Any, List, NamedTuple
1213

1314
from virtualenv.discovery.py_spec import PythonSpec
1415

@@ -27,14 +28,15 @@ class VersionInfo(NamedTuple):
2728
serial: int
2829

2930

30-
class PythonInfo(NamedTuple):
31+
@dataclass(frozen=True)
32+
class PythonInfo:
3133
implementation: str
3234
version_info: VersionInfo
3335
version: str
34-
free_threaded: bool
3536
is_64: bool
3637
platform: str
3738
extra: dict[str, Any]
39+
free_threaded: bool = False
3840

3941
@property
4042
def version_no_dot(self) -> str:
@@ -300,7 +302,7 @@ def base_python(self) -> PythonInfo:
300302
raise Skip(msg)
301303
raise NoInterpreter(base_pythons)
302304

303-
return cast("PythonInfo", self._base_python)
305+
return self._base_python
304306

305307
def _get_env_journal_python(self) -> dict[str, Any]:
306308
return {

src/tox/tox_env/python/virtual_env/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: ARG
143143
implementation=interpreter.implementation,
144144
version_info=interpreter.version_info,
145145
version=interpreter.version,
146-
free_threaded=interpreter.free_threaded,
147146
is_64=(interpreter.architecture == 64), # noqa: PLR2004
148147
platform=interpreter.platform,
149148
extra={"executable": Path(interpreter.system_executable).resolve()},
149+
free_threaded=interpreter.free_threaded,
150150
)
151151

152152
def prepend_env_var_path(self) -> list[Path]:

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import sysconfig
56
from pathlib import Path
67
from typing import TYPE_CHECKING, Callable, Iterator, Protocol, Sequence
78
from unittest.mock import patch
@@ -97,10 +98,10 @@ def get_python(self: VirtualEnv, base_python: list[str]) -> PythonInfo | None:
9798
implementation=impl,
9899
version_info=ver_info,
99100
version="",
100-
free_threaded=False,
101101
is_64=True,
102102
platform=sys.platform,
103103
extra={"executable": Path(sys.executable)},
104+
free_threaded=sysconfig.get_config_var("Py_GIL_DISABLED") == 1,
104105
)
105106

106107
mocker.patch.object(VirtualEnv, "_get_python", get_python)

tests/session/cmd/test_show_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_pass_env_config_default(tox_project: ToxProjectCreator, stdout_is_atty:
135135
+ (["PROGRAMDATA"] if is_win else [])
136136
+ (["PROGRAMFILES"] if is_win else [])
137137
+ (["PROGRAMFILES(x86)"] if is_win else [])
138-
+ ["REQUESTS_CA_BUNDLE", "SSL_CERT_FILE"]
138+
+ ["PYTHON_GIL", "REQUESTS_CA_BUNDLE", "SSL_CERT_FILE"]
139139
+ (["SYSTEMDRIVE", "SYSTEMROOT", "TEMP"] if is_win else [])
140140
+ (["TERM"] if stdout_is_atty else [])
141141
+ (["TMP", "USERPROFILE"] if is_win else ["TMPDIR"])

tox.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
requires = ["tox>=4.24.1"]
2-
env_list = ["fix", "3.14", "3.13", "3.12", "3.11", "3.10", "3.9", "cov", "type", "docs", "pkg_meta"]
2+
env_list = ["fix", "3.14t", "3.14", "3.13", "3.12", "3.11", "3.10", "3.9", "cov", "type", "docs", "pkg_meta"]
33
skip_missing_interpreters = true
44

55
[env_run_base]

0 commit comments

Comments
 (0)