@@ -74,9 +74,13 @@ def run(self):
74
74
try : os .remove (g )
75
75
except OSError : pass
76
76
77
+ command_classes = {
78
+ 'clean' : Clean ,
79
+ }
77
80
78
81
# Platform information
79
82
noc99 = sys .version_info [0 ] == 3 and sys .version_info [1 ] <= 4
83
+ stable_abi = sys .version_info [0 ] == 3 and sys .version_info [1 ] >= 11
80
84
windows = sys .platform .startswith ("win" )
81
85
testing = 'INDEXED_GZIP_TESTING' in os .environ
82
86
thisdir = op .dirname (__file__ )
@@ -96,6 +100,7 @@ def run(self):
96
100
have_numpy = True
97
101
98
102
try :
103
+ import Cython
99
104
from Cython .Build import cythonize
100
105
except Exception :
101
106
have_cython = False
@@ -117,6 +122,10 @@ def run(self):
117
122
print (' testing: {} (if True, code will be compiled with line '
118
123
'tracing enabled)' .format (testing ))
119
124
125
+ if stable_abi and have_cython :
126
+ cython_version_info = tuple (map (int , Cython .__version__ .split ('.' )[:2 ]))
127
+ # Cython 3.1 is/will be the first version to support the stable ABI
128
+ stable_abi = cython_version_info >= (3 , 1 )
120
129
121
130
# compile flags
122
131
include_dirs = ['indexed_gzip' ]
@@ -128,6 +137,11 @@ def run(self):
128
137
define_macros = [
129
138
('NPY_NO_DEPRECATED_API' , 'NPY_1_7_API_VERSION' ),
130
139
]
140
+ if stable_abi :
141
+ define_macros += [
142
+ ('CYTHON_LIMITED_API' , '1' ),
143
+ ('Py_LIMITED_API' , '0x030b0000' ),
144
+ ]
131
145
132
146
if ZLIB_HOME is not None :
133
147
include_dirs .append (ZLIB_HOME )
@@ -174,7 +188,9 @@ def run(self):
174
188
library_dirs = lib_dirs ,
175
189
include_dirs = include_dirs ,
176
190
extra_compile_args = extra_compile_args ,
177
- define_macros = define_macros )
191
+ define_macros = define_macros ,
192
+ py_limited_api = stable_abi ,
193
+ )
178
194
179
195
# Optional test modules
180
196
test_exts = []
@@ -190,7 +206,9 @@ def run(self):
190
206
library_dirs = lib_dirs ,
191
207
include_dirs = include_dirs ,
192
208
extra_compile_args = extra_compile_args ,
193
- define_macros = define_macros ))
209
+ define_macros = define_macros ,
210
+ py_limited_api = stable_abi ,
211
+ ))
194
212
195
213
# If we have numpy, we can compile the tests
196
214
if have_numpy : extensions = [igzip_ext ] + test_exts
@@ -201,8 +219,20 @@ def run(self):
201
219
if have_cython :
202
220
extensions = cythonize (extensions , compiler_directives = compiler_directives )
203
221
222
+ if stable_abi :
223
+ from wheel .bdist_wheel import bdist_wheel
224
+
225
+ class bdist_wheel_abi3 (bdist_wheel ):
226
+ def get_tag (self ):
227
+ python , abi , plat = super ().get_tag ()
228
+ if python .startswith ('cp3' ):
229
+ python , abi = 'cp311' , 'abi3'
230
+ return python , abi , plat
231
+
232
+ command_classes ['bdist_wheel' ] = bdist_wheel_abi3
233
+
204
234
setup (
205
235
name = 'indexed_gzip' ,
206
- cmdclass = { 'clean' : Clean } ,
236
+ cmdclass = command_classes ,
207
237
ext_modules = extensions ,
208
238
)
0 commit comments