Skip to content

Commit a23fe90

Browse files
committed
Replace the inline free-threaded checks with a function as well
Signed-off-by: Michał Górny <mgorny@quansight.com>
1 parent 0d43c65 commit a23fe90

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

mesonpy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ def _is_abi3t_capable() -> bool:
334334
return sys.version_info >= (3, 15, 0, 'beta', 2)
335335

336336

337+
def _is_free_threaded() -> bool:
338+
"""Return true if we are running a free-threaded (no-GIL) Python."""
339+
return sysconfig.get_config_var('Py_GIL_DISABLED')
340+
341+
337342
@dataclasses.dataclass
338343
class _WheelBuilder():
339344
"""Helper class to build wheels from projects."""
@@ -435,7 +440,7 @@ def _stable_abi(self) -> Optional[str]:
435440
# building 'abi3t' wheels for the time being. In the future
436441
# we will want an option to target 'abi3t' from GIL-enabled
437442
# Python too.
438-
is_abi3t = bool(sysconfig.get_config_var('Py_GIL_DISABLED')) and _is_abi3t_capable()
443+
is_abi3t = _is_free_threaded() and _is_abi3t_capable()
439444
expected_abi = 'abi3t' if is_abi3t else 'abi3'
440445

441446
# Verify stable ABI compatibility: examine files installed
@@ -886,7 +891,7 @@ def __init__(
886891
if not allow_limited_api:
887892
self._limited_api = False
888893

889-
if self._limited_api and bool(sysconfig.get_config_var('Py_GIL_DISABLED')) and not _is_abi3t_capable():
894+
if self._limited_api and _is_free_threaded() and not _is_abi3t_capable():
890895
raise BuildError(
891896
'The package targets Python\'s Limited API, which is not supported by free-threaded CPython < 3.15.0b2. '
892897
'The "python.allow_limited_api" Meson build option may be used to override the package default.')

tests/test_editable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from mesonpy import _editable
2020

21-
from .test_wheel import EXT_SUFFIX, NOGIL_BUILD
21+
from .test_wheel import EXT_SUFFIX
2222

2323

2424
def find_cython_version():
@@ -75,7 +75,7 @@ def test_collect(package_complex):
7575
assert tree['complex']['more']['__init__.py'] == os.path.join(root, 'complex', 'more', '__init__.py')
7676

7777

78-
@pytest.mark.skipif(NOGIL_BUILD and CYTHON_VERSION < (3, 1, 0),
78+
@pytest.mark.skipif(mesonpy._is_free_threaded() and CYTHON_VERSION < (3, 1, 0),
7979
reason='Cython version too old, no free-threaded CPython support')
8080
def test_mesonpy_meta_finder(package_complex, tmp_path):
8181
# build a package in a temporary directory
@@ -210,7 +210,7 @@ def test_editble_reentrant(venv, editable_imports_itself_during_build):
210210
path.write_text(code)
211211

212212

213-
@pytest.mark.skipif(NOGIL_BUILD and CYTHON_VERSION < (3, 1, 0),
213+
@pytest.mark.skipif(mesonpy._is_free_threaded() and CYTHON_VERSION < (3, 1, 0),
214214
reason='Cython version too old, no free-threaded CPython support')
215215
def test_editable_pkgutils_walk_packages(package_complex, tmp_path):
216216
# build a package in a temporary directory
@@ -296,7 +296,7 @@ def test_editable_rebuild(package_purelib_and_platlib, tmp_path, verbose, args):
296296
sys.modules.pop('pure', None)
297297

298298

299-
@pytest.mark.skipif(NOGIL_BUILD and CYTHON_VERSION < (3, 1, 0),
299+
@pytest.mark.skipif(mesonpy._is_free_threaded() and CYTHON_VERSION < (3, 1, 0),
300300
reason='Cython version too old, no free-threaded CPython support')
301301
def test_editable_verbose(venv, package_complex, editable_complex, monkeypatch):
302302
monkeypatch.setenv('MESONPY_EDITABLE_VERBOSE', '1')

tests/test_tags.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import mesonpy._tags
2020

2121
from .conftest import adjust_packaging_platform_tag
22-
from .test_wheel import NOGIL_BUILD
2322

2423

2524
# Test against the wheel tag generated by packaging module.
@@ -133,7 +132,7 @@ def test_tag_stable_abi():
133132
# PyPy does not support the stable ABI.
134133
if '__pypy__' in sys.builtin_module_names:
135134
abi = ABI
136-
elif NOGIL_BUILD and mesonpy._is_abi3t_capable():
135+
elif mesonpy._is_free_threaded() and mesonpy._is_abi3t_capable():
137136
abi = 'abi3.abi3t'
138137
else:
139138
abi = 'abi3'

tests/test_wheel.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
'win32': '.dll',
3636
}.get(sys.platform, '.so')
3737

38-
NOGIL_BUILD = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
39-
4038
# Test against the wheel tag generated by packaging module.
4139
tag = next(packaging.tags.sys_tags())
4240
ABI = tag.abi
@@ -321,7 +319,7 @@ def test_skip_subprojects(package_subproject, tmp_path, arg):
321319

322320
# Requires Meson 1.3.0, see https://github.com/mesonbuild/meson/pull/11745.
323321
@pytest.mark.skipif(MESON_VERSION < (1, 2, 99), reason='meson too old')
324-
@pytest.mark.skipif(NOGIL_BUILD, reason='Free-threaded CPython does not support the limited API')
322+
@pytest.mark.skipif(mesonpy._is_free_threaded(), reason='Free-threaded CPython does not support the limited API')
325323
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not support the abi3 platform tag for wheels')
326324
def test_limited_api(wheel_limited_api):
327325
artifact = wheel.wheelfile.WheelFile(wheel_limited_api)
@@ -333,7 +331,7 @@ def test_limited_api(wheel_limited_api):
333331

334332
# Requires Meson 1.3.0, see https://github.com/mesonbuild/meson/pull/11745.
335333
@pytest.mark.skipif(MESON_VERSION < (1, 2, 99), reason='meson too old')
336-
@pytest.mark.skipif(NOGIL_BUILD, reason='Free-threaded CPython does not support the limited API')
334+
@pytest.mark.skipif(mesonpy._is_free_threaded(), reason='Free-threaded CPython does not support the limited API')
337335
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not use special modules suffix for stable ABI')
338336
def test_limited_api_bad(package_limited_api, tmp_path):
339337
with pytest.raises(mesonpy.BuildError, match='The package declares compatibility with Python limited API but '):
@@ -421,5 +419,5 @@ def test_limited_api_ft(wheel_limited_api_ft):
421419
artifact = wheel.wheelfile.WheelFile(wheel_limited_api_ft)
422420
name = artifact.parsed_filename
423421
assert name.group('pyver') == INTERPRETER
424-
assert name.group('abi') == 'abi3.abi3t' if NOGIL_BUILD else 'abi3'
422+
assert name.group('abi') == 'abi3.abi3t' if mesonpy._is_free_threaded() else 'abi3'
425423
assert name.group('plat') == PLATFORM

0 commit comments

Comments
 (0)