From ae0d1f5b9e69d7df4aaf7b23891285015e11708c Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 20 Aug 2024 10:28:14 -0400 Subject: [PATCH] BLD: automatically detect if in freethread build of Python Following suggestion from: https://docs.python.org/3.13/howto/free-threading-extensions.html#limited-c-api-and-stable-abi --- setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a785f3f..c42718a 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ from warnings import warn import packaging.version from wheel.bdist_wheel import bdist_wheel +import sysconfig LIBERFADIR = os.path.join('liberfa', 'erfa') @@ -19,8 +20,12 @@ os.path.join('erfa', 'ufunc.c'), ] + # build with Py_LIMITED_API unless explicitly disabled -USE_PY_LIMITED_API = os.getenv("PYERFA_LIMITED_API", "1") != "0" +USE_PY_LIMITED_API = ( + (not sysconfig.get_config_var("Py_GIL_DISABLED")) and + os.getenv("PYERFA_LIMITED_API", "1") != "0" +) class bdist_wheel_abi3(bdist_wheel): def get_tag(self): @@ -38,7 +43,7 @@ def newer(source, target): source = pathlib.Path(source) if not source.exists(): raise FileNotFoundError(f"file '{source.resolve()}' does not exist") - + target = pathlib.Path(target) if not target.exists(): return 1