From 2aadceb016f9590af4cd3ed522fd6e067b655734 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 9 Sep 2026 16:07:11 +0200 Subject: [PATCH] fix: update Cython dependency to avoid ABI collisions and add warning for import failures --- pyproject.toml | 9 ++++++++- src/spatial_graph/_rtree/rtree.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 62d786b..ac0d95d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,14 @@ requires = [ "setuptools>=77", "setuptools-scm>=8", - "Cython>=3.1", + # Cython 3.3.0 makes the __pyx_CyFunctionObject layout depend on the + # limited-API target (an extra func_is_coroutine field below 0x030B0000) + # without reflecting that in the name of the module its shared types live in, + # so our cp311 modules collide with any cp310 abi3 module built by the same + # Cython -- uharfbuzz >=0.56.1, via pygfx -- and whichever imports second dies + # with "Shared Cython type ... has the wrong size". Fixed in cython/cython#7916 + # (unreleased at time of writing), so this skips the one bad release. + "Cython>=3.1,!=3.3.0", "CT3>=3.3.3", "numpy", # imported (not linked) while rendering the wrappers ] diff --git a/src/spatial_graph/_rtree/rtree.py b/src/spatial_graph/_rtree/rtree.py index 8c79055..2ff787a 100644 --- a/src/spatial_graph/_rtree/rtree.py +++ b/src/spatial_graph/_rtree/rtree.py @@ -2,6 +2,7 @@ import importlib import sys +import warnings from pathlib import Path from typing import ClassVar @@ -31,6 +32,20 @@ def _load_prebuilt( module = importlib.import_module(f"{PREBUILT_PACKAGE}.{name}") except ImportError: return None + except TypeError as e: # pragma: no cover + # A Cython module already loaded in this process can claim the same + # shared-ABI module name as ours while disagreeing about the layout of + # the types in it, and the loser of that race is whoever imports second + # ("Shared Cython type ... has the wrong size"). Falling back to the JIT + # path costs a compiler, but beats taking the process down. + warnings.warn( + f"Could not import prebuilt {name} ({e}); compiling it instead. " + "This usually means another extension module in this process was " + "built against an incompatible Cython ABI.", + RuntimeWarning, + stacklevel=2, + ) + return None return module.RTree