Skip to content

Commit eec41b9

Browse files
committed
Build for limited API only on supported interpreters
Pass the limited API options only when building for non-free-threading CPython versions. Passing the flags on other interpreters (such as PyPy or GraalPy) or free-threading CPython versions results in build failures due to the limited API not being supported. While this package doesn't support free-threading Python right now, I think it makes sense to make the condition future-proof while I'm already fixing PyPy builds. See also cython/cython#7279 Signed-off-by: Michał Górny <mgorny@gentoo.org>
1 parent be367c8 commit eec41b9

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

setup.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
import sysconfig
3+
14
from setuptools import Extension, setup
25
from Cython.Build import cythonize
36

@@ -11,17 +14,27 @@
1114
# 0x030B0000 - Python 3.11 - support typed memoryviews.
1215
# 0x030C0000 - Python 3.12 - support vectorcall (performance improvement).
1316

17+
py_limited_api_kwargs = {}
18+
if sys.implementation.name == "cpython" and not sysconfig.get_config_var(
19+
"Py_GIL_DISABLED"
20+
):
21+
py_limited_api_kwargs = {
22+
"define_macros": [
23+
# For now we are at python 3.8 as we still support 3.10.
24+
("Py_LIMITED_API", 0x03080000),
25+
],
26+
"py_limited_api": True,
27+
}
28+
1429
setup(
15-
ext_modules=cythonize([
16-
Extension(
17-
name="raiser",
18-
sources=["cython_test_exception_raiser/raiser.pyx"],
19-
define_macros=[
20-
# For now we are at python 3.8 as we still support 3.10.
21-
("Py_LIMITED_API", 0x03080000),
22-
],
23-
py_limited_api=True
24-
),
25-
]),
30+
ext_modules=cythonize(
31+
[
32+
Extension(
33+
name="raiser",
34+
sources=["cython_test_exception_raiser/raiser.pyx"],
35+
**py_limited_api_kwargs
36+
),
37+
]
38+
),
2639
options={"bdist_wheel": {"py_limited_api": "cp38"}},
2740
)

0 commit comments

Comments
 (0)