Skip to content

Commit fcb81eb

Browse files
setup.py: avoid build errors with PY_LIMITED_API and Python-3.13.
SWIG-generated code does not currently work with PY_LIMITED_API and Python-3.13, so we disable PY_LIMITED_API by default. This does not effect releases because they are all built with Python-3.9 and PY_LIMITED_API. But this allows standalone builds to work.
1 parent 03d284f commit fcb81eb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
153153
PYMUPDF_SETUP_PY_LIMITED_API
154154
If not '0', we build for current Python's stable ABI.
155+
156+
However if unset and we are on Python-3.13 or later, we do
157+
not build for the stable ABI because as of 2025-03-04 SWIG
158+
generates incorrect stable ABI code with Python-3.13 - see:
159+
https://github.com/swig/swig/issues/3059
155160
156161
PYMUPDF_SETUP_URL_WHEEL
157162
If set, we use an existing wheel instead of building a new wheel.
@@ -242,10 +247,16 @@ def run(command, check=1):
242247
# Name of file that identifies that we are in a PyMuPDF sdist.
243248
g_pymupdfb_sdist_marker = 'pymupdfb_sdist'
244249

250+
python_version_tuple = tuple(int(x) for x in platform.python_version_tuple()[:2])
251+
245252
PYMUPDF_SETUP_PY_LIMITED_API = os.environ.get('PYMUPDF_SETUP_PY_LIMITED_API')
246253
assert PYMUPDF_SETUP_PY_LIMITED_API in (None, '', '0', '1'), \
247254
f'Should be "", "0", "1" or undefined: {PYMUPDF_SETUP_PY_LIMITED_API=}.'
248-
g_py_limited_api = (PYMUPDF_SETUP_PY_LIMITED_API != '0')
255+
if PYMUPDF_SETUP_PY_LIMITED_API is None and python_version_tuple >= (3, 13):
256+
log(f'Not defaulting to Python limited api because {platform.python_version_tuple()=}.')
257+
g_py_limited_api = False
258+
else:
259+
g_py_limited_api = (PYMUPDF_SETUP_PY_LIMITED_API != '0')
249260

250261
PYMUPDF_SETUP_URL_WHEEL = os.environ.get('PYMUPDF_SETUP_URL_WHEEL')
251262
log(f'{PYMUPDF_SETUP_URL_WHEEL=}')

0 commit comments

Comments
 (0)