Skip to content

Commit 1492f7e

Browse files
Declare Python 3 wheels abi3-compliant (#151)
1 parent f27534b commit 1492f7e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,26 @@
1414

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

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

2338
if sys.version_info[0] == 3 and PYTHON_SGP4_COMPILE != 'never':
2439

@@ -44,6 +59,8 @@
4459
'extension/wrapper.cpp',
4560
],
4661
extra_compile_args=extra_compile_args,
62+
define_macros=define_macros,
63+
py_limited_api=USE_PY_LIMITED_API,
4764
))
4865

4966
# Read the package's docstring and "__version__" without importing it.
@@ -98,5 +115,8 @@
98115
package_data = {'sgp4': ['SGP4-VER.TLE', 'sample*', 'tcppver.out']},
99116
provides = ['sgp4'],
100117
ext_modules = ext_modules,
118+
options={
119+
"bdist_wheel": {"py_limited_api": "cp%s" % ABI3_TARGET_VERSION}
120+
} if USE_PY_LIMITED_API else {},
101121
**setup_kwargs,
102122
)

0 commit comments

Comments
 (0)