Skip to content

Commit 914b663

Browse files
committed
BLD/WHL: declare Python 3 wheels as abi3-compliant
1 parent b7b5a44 commit 914b663

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@
1414

1515
import os
1616
import sys
17+
import sysconfig
1718
from distutils.core import setup, Extension
1819

1920
PYTHON_SGP4_COMPILE = os.environ.get('PYTHON_SGP4_COMPILE', '')
21+
22+
# LIMITED_API is not compatible with free-threading (as of CPython 3.14)
23+
USE_PY_LIMITED_API = (
24+
sys.version_info[0] == 3
25+
and not sysconfig.get_config_var("Py_GIL_DISABLED")
26+
)
27+
ABI3_TARGET_VERSION = "".join(str(_) for _ in sys.version_info[:2])
28+
ABI3_TARGET_HEX = hex(sys.hexversion & 0xFFFF00F0)
29+
2030
ext_modules = []
31+
define_macros = []
32+
33+
if USE_PY_LIMITED_API:
34+
define_macros.append(("Py_LIMITED_API", ABI3_TARGET_HEX))
2135

2236
if sys.version_info[0] == 3 and PYTHON_SGP4_COMPILE != 'never':
2337

@@ -33,6 +47,8 @@
3347
'extension/SGP4.cpp',
3448
'extension/wrapper.cpp',
3549
],
50+
define_macros=define_macros,
51+
py_limited_api=USE_PY_LIMITED_API,
3652

3753
# TODO: can we safely figure out how to use a pair of options
3854
# like these, adapted to as many platforms as possible, to use
@@ -89,4 +105,7 @@
89105
package_data = {'sgp4': ['SGP4-VER.TLE', 'sample*', 'tcppver.out']},
90106
provides = ['sgp4'],
91107
ext_modules = ext_modules,
108+
options={
109+
"bdist_wheel": {"py_limited_api": "cp%s" % ABI3_TARGET_VERSION}
110+
} if USE_PY_LIMITED_API else {},
92111
)

0 commit comments

Comments
 (0)