changeset 546:adf65c31f8fc

Automatically select the proper API when building the speedup C-extension: Build the C-extension for Python 3.5+ and build against the stable API for Python 3.7+.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 01 Jan 2022 21:03:05 +0100
parents 6501fe0e116c
children 1cbe8b0f2b78
files setup.py
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Sat Jan 01 20:36:46 2022 +0100
+++ b/setup.py	Sat Jan 01 21:03:05 2022 +0100
@@ -53,11 +53,16 @@
 # PyPy does not need this.
 #
 
+# The C-extension uses multi-phase module initialization (PEP 489, PY 3.5+)
 if (platform.python_implementation() == "CPython"
     and (sys.version_info[0] > 3
-         or (sys.version_info[0] == 3 and sys.version_info[1] >= 7))):
+         or (sys.version_info[0] == 3 and sys.version_info[1] >= 5))):
 
-    py_limited_api = True
+    # The stable API for Python 3.7+ is used
+    if sys.version_info[0] == 3 and sys.version_info[1] < 7:
+        py_limited_api = False
+    else:
+        py_limited_api = True
 
     if py_limited_api:
         define_macros = [("Py_LIMITED_API", "0x03070000")]