Skip to content

Commit 6b90e1d

Browse files
committed
Add Free-Threading and Limited API/Stable ABI
Add support for building wheels with the free-threaded interpreter and also with the limited API/stable ABI on Python 3.11+. There is limited testing for the free-threading setup but this become usable for people running on that interpreter without reverting back to locking the GIL.
1 parent 55df351 commit 6b90e1d

File tree

6 files changed

+85
-56
lines changed

6 files changed

+85
-56
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Check out code
14-
uses: actions/checkout@v5
14+
uses: actions/checkout@v6
1515

1616
- name: Select python
17-
uses: actions/setup-python@v5
17+
uses: actions/setup-python@v6
1818
with:
1919
python-version: 3.12
2020

@@ -28,7 +28,7 @@ jobs:
2828
GSSAPI_COMPILER_ARGS: ''
2929

3030
- name: Upload sdist
31-
uses: actions/upload-artifact@v4
31+
uses: actions/upload-artifact@v5
3232
with:
3333
name: artifact-sdist
3434
path: ./dist/*.tar.gz
@@ -43,47 +43,31 @@ jobs:
4343
fail-fast: false
4444
matrix:
4545
include:
46-
- os: macOS-13
47-
version: cp314-macosx_x86_64
48-
prerelease: true
49-
- os: macOS-15
50-
version: cp314-macosx_arm64
51-
prerelease: true
52-
- os: macOS-13
53-
version: cp313-macosx_x86_64
54-
- os: macOS-15
55-
version: cp313-macosx_arm64
56-
- os: macOS-13
57-
version: cp312-macosx_x86_64
58-
- os: macOS-15
59-
version: cp312-macosx_arm64
60-
- os: macOS-13
46+
# Free-threading does not support Limited API/Stable ABI yet
47+
# 3.11+ can use the Limited API/Stable ABI
48+
- os: macos-15-intel
49+
version: cp314t-macosx_x86_64
50+
- os: macos-15
51+
version: cp314t-macosx_arm64
52+
53+
- os: macos-15-intel
6154
version: cp311-macosx_x86_64
62-
- os: macOS-15
55+
- os: macos-15
6356
version: cp311-macosx_arm64
64-
- os: macOS-13
57+
- os: macos-15-intel
6558
version: cp310-macosx_x86_64
66-
- os: macOS-15
59+
- os: macos-15
6760
version: cp310-macosx_arm64
68-
- os: macOS-13
61+
- os: macos-15-intel
6962
version: cp39-macosx_x86_64
70-
- os: macOS-15
63+
- os: macos-15
7164
version: cp39-macosx_arm64
7265

7366
- os: windows-2022
74-
version: cp314-win_amd64
75-
prerelease: true
67+
version: cp314t-win_amd64
7668
- os: windows-2022
77-
version: cp314-win32
78-
prerelease: true
79-
- os: windows-2022
80-
version: cp313-win_amd64
81-
- os: windows-2022
82-
version: cp313-win32
83-
- os: windows-2022
84-
version: cp312-win_amd64
85-
- os: windows-2022
86-
version: cp312-win32
69+
version: cp314t-win32
70+
8771
- os: windows-2022
8872
version: cp311-win_amd64
8973
- os: windows-2022
@@ -113,7 +97,7 @@ jobs:
11397
echo "C:\Program Files${{ endsWith(matrix.version, '-win32') && ' (x86)' || '' }}\MIT\Kerberos\bin;$PATH" >> $GITHUB_PATH
11498
11599
- name: Download gssapi sdist
116-
uses: actions/download-artifact@v5
100+
uses: actions/download-artifact@v6
117101
with:
118102
name: artifact-sdist
119103
path: ./
@@ -127,14 +111,14 @@ jobs:
127111
rm gssapi-*.tar.gz
128112
129113
- name: Build wheel
130-
uses: pypa/cibuildwheel@v3.1.4
114+
uses: pypa/cibuildwheel@v3.3.0
131115
env:
132116
CIBW_BUILD: ${{ matrix.version }}
133117
CIBW_BUILD_VERBOSITY: 1
134118
CIBW_PRERELEASE_PYTHONS: ${{ matrix.prerelease || 'false' }}
135119

136120
- name: Upload wheel
137-
uses: actions/upload-artifact@v4
121+
uses: actions/upload-artifact@v5
138122
with:
139123
path: ./wheelhouse/*.whl
140124
name: artifact-wheel-${{ matrix.version }}
@@ -147,7 +131,7 @@ jobs:
147131
runs-on: ubuntu-latest
148132
steps:
149133
- name: Download gssapi sdist
150-
uses: actions/download-artifact@v5
134+
uses: actions/download-artifact@v6
151135
with:
152136
name: artifact-sdist
153137
path: ./dist
@@ -204,10 +188,10 @@ jobs:
204188

205189
steps:
206190
- name: Check out code
207-
uses: actions/checkout@v5
191+
uses: actions/checkout@v6
208192

209193
- name: Download built project
210-
uses: actions/download-artifact@v5
194+
uses: actions/download-artifact@v6
211195
with:
212196
pattern: artifact-*
213197
merge-multiple: true
@@ -230,6 +214,7 @@ jobs:
230214
fail-fast: false
231215
matrix:
232216
name:
217+
- win-py-3.14t
233218
- win-py-3.14
234219
- win-py-3.13
235220
- win-py-3.12
@@ -240,8 +225,10 @@ jobs:
240225
- x64
241226
- x86
242227
include:
228+
- name: win-py-3.14t
229+
pyenv: '3.14t'
243230
- name: win-py-3.14
244-
pyenv: '3.14.0-rc.2'
231+
pyenv: '3.14'
245232
- name: win-py-3.13
246233
pyenv: '3.13'
247234
- name: win-py-3.12
@@ -255,17 +242,17 @@ jobs:
255242

256243
steps:
257244
- name: Check out code
258-
uses: actions/checkout@v5
245+
uses: actions/checkout@v6
259246

260247
- name: Download built project
261-
uses: actions/download-artifact@v5
248+
uses: actions/download-artifact@v6
262249
with:
263250
pattern: artifact-*
264251
merge-multiple: true
265252
path: ./dist
266253

267254
- name: Install the right python
268-
uses: actions/setup-python@v5
255+
uses: actions/setup-python@v6
269256
with:
270257
python-version: ${{ matrix.pyenv }}
271258
architecture: ${{ matrix.arch }}
@@ -284,10 +271,10 @@ jobs:
284271
runs-on: macos-latest
285272
steps:
286273
- name: Check out code
287-
uses: actions/checkout@v5
274+
uses: actions/checkout@v6
288275

289276
- name: Download built project
290-
uses: actions/download-artifact@v5
277+
uses: actions/download-artifact@v6
291278
with:
292279
pattern: artifact-*
293280
merge-multiple: true
@@ -316,10 +303,10 @@ jobs:
316303

317304
steps:
318305
- name: Check out code
319-
uses: actions/checkout@v5
306+
uses: actions/checkout@v6
320307

321308
- name: Download built project
322-
uses: actions/download-artifact@v5
309+
uses: actions/download-artifact@v6
323310
with:
324311
pattern: artifact-*
325312
merge-multiple: true
@@ -339,7 +326,7 @@ jobs:
339326
run: echo "checksum=`ls tag_build/*.sha512sum | awk -F/ '{print $2}'`" >> $GITHUB_OUTPUT
340327

341328
- name: Upload tagged build artifact
342-
uses: actions/upload-artifact@v4
329+
uses: actions/upload-artifact@v5
343330
with:
344331
path: tag_build/${{ steps.tarball.outputs.tarball }}
345332
name: release-asset

.github/workflows/deploy-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Check out code
11-
uses: actions/checkout@v5
11+
uses: actions/checkout@v6
1212

1313
- name: Select python
14-
uses: actions/setup-python@v5
14+
uses: actions/setup-python@v6
1515
with:
1616
python-version: 3.12
1717

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/stale@v9.1.0
14+
- uses: actions/stale@v10.1.1
1515
id: stale
1616
with:
1717
days-before-stale: -1

README.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ In addition to RFC 2743/2744, Python-GSSAPI also has support for:
161161

162162
* Kerberos specific extensions
163163

164+
Python Free-Threading (PEP 779)
165+
-------------------------------
166+
167+
This library supports Python Free-Threading and will build
168+
free-threading-compatible extension files if installed under a free-threading
169+
interpreter. Python 3.14t is tested in CI and a wheel will be created for
170+
3.14t+. Python 3.13t is not officially tested or supported but may or may not
171+
work. There is limited testing for free-threading in this library and it does
172+
not aim to be thread safe out of the box. If you encounter any issues or
173+
problems with this scenario please raise an issue and we can look at possible
174+
options to fix this.
175+
164176
The Team
165177
========
166178

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"Cython == 3.1.3",
3+
"Cython == 3.2.1",
44
"setuptools >= 40.6.0", # Start of PEP 517 support for setuptools
55
]
66
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import platform
44
import re
55
import sys
6+
import sysconfig
67
import os
78
import shutil
89
import shlex
@@ -18,6 +19,17 @@
1819
from Cython.Build import cythonize # noqa: E402
1920

2021

22+
# Enable limited API for Python 3.11+
23+
USE_LIMITED_API = sys.version_info >= (3, 11)
24+
LIMITED_API_VERSION = 0x030B0000 # Python 3.11 ABI
25+
26+
IS_FREE_THREADED = False
27+
if sysconfig.get_config_var("Py_GIL_DISABLED") == 1:
28+
# Free-threaded Python does not support the limited API.
29+
USE_LIMITED_API = False
30+
IS_FREE_THREADED = True
31+
32+
2133
def get_output(*args, **kwargs):
2234
res = subprocess.check_output(*args, shell=True, **kwargs)
2335
decoded = res.decode('utf-8')
@@ -215,13 +227,20 @@ def make_extension(name_fmt, module, **kwargs):
215227
source = name_fmt.replace('.', '/') % module + '.pyx'
216228
if not os.path.exists(source):
217229
raise OSError(source)
230+
231+
define_macros = kwargs.pop('define_macros', [])
232+
if USE_LIMITED_API:
233+
define_macros.append(('Py_LIMITED_API', LIMITED_API_VERSION))
234+
218235
return Extension(
219236
name_fmt % module,
220237
extra_link_args=link_args,
221238
extra_compile_args=compile_args,
222239
library_dirs=library_dirs,
223240
libraries=libraries,
224241
sources=[source],
242+
define_macros=define_macros,
243+
py_limited_api=USE_LIMITED_API,
225244
**kwargs
226245
)
227246

@@ -264,7 +283,12 @@ def gssapi_modules(lst):
264283
# add in any present enum extension files
265284
res.extend(ENUM_EXTS)
266285

267-
return cythonize(res, language_level=2)
286+
compiler_directives = {}
287+
if IS_FREE_THREADED:
288+
# Enable free-threading support in Cython
289+
compiler_directives["freethreading_compatible"] = True
290+
291+
return cythonize(res, language_level=2, compiler_directives=compiler_directives)
268292

269293

270294
long_desc = re.sub(r'\.\. role:: \w+\(code\)\s*\n\s*.+', '',
@@ -276,9 +300,13 @@ def gssapi_modules(lst):
276300
'decorator',
277301
]
278302

303+
setup_options = {}
304+
if USE_LIMITED_API:
305+
setup_options["bdist_wheel"] = {"py_limited_api": "cp311"}
306+
279307
setup(
280308
name='gssapi',
281-
version='1.10.1',
309+
version='1.11.0',
282310
author='The Python GSSAPI Team',
283311
author_email='[email protected]',
284312
packages=['gssapi', 'gssapi.raw', 'gssapi.raw._enum_extensions',
@@ -304,6 +332,7 @@ def gssapi_modules(lst):
304332
'Programming Language :: Python :: 3.12',
305333
'Programming Language :: Python :: 3.13',
306334
'Programming Language :: Python :: 3.14',
335+
"Programming Language :: Python :: Free Threading :: 2 - Beta"
307336
'Intended Audience :: Developers',
308337
'Programming Language :: Python :: Implementation :: CPython',
309338
'Programming Language :: Cython',
@@ -344,6 +373,7 @@ def gssapi_modules(lst):
344373

345374
extension_file('krb5', 'gss_krb5_ccache_name'),
346375
]),
376+
options=setup_options,
347377
keywords=['gssapi', 'security'],
348378
install_requires=install_requires
349379
)

0 commit comments

Comments
 (0)