Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLD: target ABI3 #137

Open
neutrinoceros opened this issue Jul 18, 2023 · 5 comments · May be fixed by #304
Open

BLD: target ABI3 #137

neutrinoceros opened this issue Jul 18, 2023 · 5 comments · May be fixed by #304

Comments

@neutrinoceros
Copy link
Owner

neutrinoceros commented Jul 18, 2023

I would like to eventually target ABI3 (aka LIMITED_API) to improve future-compatibility of wheels and minimise maintenance cost.

radio-astro-tools/casa-formats-io#50 is an example of successful migration, but it doesn't use Cython.

The following is at least part of the patch necessary in this project, though, at the time of writing, Cython 3.0 (just released) only has "limited" support for Py_LIMITED_API, so it doesn't work yet.

diff --git a/pyproject.toml b/pyproject.toml
index fa26dbb..57e5314 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -20,7 +20,7 @@ classifiers = [
     "Programming Language :: Python :: 3",
     "Programming Language :: Python :: 3 :: Only",
 ]
-requires-python = ">=3.9"
+requires-python = ">=3.9" # keep in sync with< Py_LIMITED_API (setup.py)
 dependencies = [
     # keep in sync with NPY_TARGET_VERSION (setup.py)
     # https://github.com/scipy/oldest-supported-numpy/issues/76#issuecomment-1628865694
diff --git a/setup.py b/setup.py
index 51afb50..539f3cc 100644
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,9 @@ def make_ext(path: str) -> Extension:
             # keep in sync with runtime requirements (pyproject.toml)
             ("NPY_TARGET_VERSION", "NPY_1_21_API_VERSION"),
             ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
+            ("CYTHON_LIMITED_API", None),
+            ("Py_LIMITED_API", "0x3090000"),
         ],
+        py_limited_api=True,
     )
@neutrinoceros
Copy link
Owner Author

relevant query to watch Cython's progress on supported Py_LIMITED_API: https://github.com/cython/cython/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+label%3A%22limited+api%22

@neutrinoceros
Copy link
Owner Author

and here's cibuildwheel's doc on the matter: https://cibuildwheel.readthedocs.io/en/stable/faq/#abi3

@neutrinoceros neutrinoceros changed the title BLD: target Py_LIMITED_API BLD: target ABI3 Aug 9, 2023
@neutrinoceros neutrinoceros changed the title BLD: target ABI3 BLD: target ABI3 Aug 9, 2023
@neutrinoceros
Copy link
Owner Author

Given that the stability of the C API in CPython is currently heavily discussed in the wake of PEP 703, ABI3 might not be future-proof for much longer, and it seems unlikely that Cython can catch up in the near future, so I'll close this as "not planned" (but it's still something I'd like to implement in the future when and if it becomes feasible)

@neutrinoceros neutrinoceros closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
@neutrinoceros
Copy link
Owner Author

Re-opening so I don't accidentally open a dupe evenutally
Here are some relevant issues and PRs to watch for

@neutrinoceros neutrinoceros reopened this Jan 5, 2025
@neutrinoceros
Copy link
Owner Author

neutrinoceros commented Jan 5, 2025

I also note that the patch I need to test this has gotten simpler:

diff --git a/pyproject.toml b/pyproject.toml
index 2c8f222..fc65cde 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
 [build-system]
 requires = [
     "setuptools>=61.2",
-    "Cython>=3.0",
+    "Cython>=3.1.0a1",
     "numpy>=2.0.0",
 ]
 build-backend = "setuptools.build_meta"
diff --git a/setup.py b/setup.py
index 457b5a9..5ee1188 100644
--- a/setup.py
+++ b/setup.py
@@ -30,6 +30,7 @@ else:
                     # keep in sync with runtime requirements (pyproject.toml)
                     ("NPY_TARGET_VERSION", "NPY_1_25_API_VERSION"),
                     ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
+                    ("Py_LIMITED_API", "0x30b0000"),
                 ],
+                py_limited_api=True,
             )
         ],

@neutrinoceros neutrinoceros linked a pull request Jan 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant