Skip to content

Commit f1e214a

Browse files
committed
Skip Rust extension build for free-threaded Python
Free-threaded Python (3.13t) doesn't support Rust extensions yet. The build hook now detects free-threaded Python and skips the Rust extension build to avoid GIL-related import errors.
1 parent b0c229f commit f1e214a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

hatch_build.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,18 @@ def initialize(self, version, build_data):
145145

146146
# Build Rust extension (optional)
147147
# Only build if PYMONGO_BUILD_RUST is set or Rust is available
148+
# Skip for free-threaded Python (not yet supported)
149+
is_free_threaded = hasattr(sys, "_is_gil_enabled") and not sys._is_gil_enabled()
148150
build_rust = os.environ.get("PYMONGO_BUILD_RUST", "").lower() in ("1", "true", "yes")
149-
if build_rust:
151+
if build_rust and is_free_threaded:
152+
warnings.warn(
153+
"Rust extension is not yet supported on free-threaded Python. Skipping build.",
154+
stacklevel=2,
155+
)
156+
elif build_rust:
150157
# If PYMONGO_BUILD_RUST is explicitly set, the build must succeed
151158
self._build_rust_extension(here, required=True)
152-
elif shutil.which("cargo"):
159+
elif shutil.which("cargo") and not is_free_threaded:
153160
# If Rust is available but not explicitly requested, build is optional
154161
self._build_rust_extension(here, required=False)
155162

0 commit comments

Comments
 (0)