Skip to content

Add support for free-threaded Python (PEP 703)#1517

Open
Gaganraj2002 wants to merge 1 commit intoosprey-oss:mainfrom
Gaganraj2002:free-threaded-support
Open

Add support for free-threaded Python (PEP 703)#1517
Gaganraj2002 wants to merge 1 commit intoosprey-oss:mainfrom
Gaganraj2002:free-threaded-support

Conversation

@Gaganraj2002
Copy link
Copy Markdown

Summary

Build and ship free-threaded Python (cp313t/cp314t) wheels, enabling deptry to work on Python built without the GIL.

Changes:

Release workflow (.github/workflows/release.yml):

  • Add free-threaded wheel build steps to linux, windows, and macos jobs
  • On Linux, manylinux containers already bundle python3.13t/python3.14t
  • On Windows/macOS, install free-threaded Python after the abi3 build to avoid interpreter detection conflicts (maturin-action#313)
  • Free-threaded steps are skipped for PyPy matrix entries

Test workflow (.github/workflows/main.yml):

  • Add 3.13t and 3.14t to the test matrix
  • Skip mypy typing group for free-threaded builds (not yet compatible)

Tests:

  • Add tests/unit/test_thread_safety.py with concurrent stress test exercising the Rust import extraction from 8 threads simultaneously

Why no Rust code changes are needed:

The extension already uses PyO3 0.28.2, which defaults to gil_used = false. The Rust codebase has zero global mutable state, zero unsafe blocks, and zero static variables — all functions are pure computations. PyO3 automatically ignores the abi3-py310 feature flag when it detects Py_GIL_DISABLED, producing version-specific cp313t/cp314t wheels instead of abi3 wheels.

Test plan

  • Thread-safety test passes locally (8 threads x 50 iterations)
  • Existing tests unaffected
  • CI: Tests pass on 3.13t and 3.14t with free-threaded Python
  • CI: Free-threaded wheels build on Linux, macOS, and Windows

Build and test free-threaded (cp313t/cp314t) wheels across all platforms.

CI changes:
- Add 3.13t and 3.14t to test matrix in main.yml
- Skip typing group install for free-threaded builds (mypy not yet compatible)
- Add free-threaded wheel build steps to linux, windows, and macos release jobs
- On Linux, manylinux containers bundle free-threaded interpreters natively
- On Windows/macOS, install free-threaded Python after abi3 build to avoid
  interpreter detection conflicts (maturin-action#313)

Tests:
- Add concurrent thread-safety test exercising the Rust import extraction
  from multiple threads simultaneously

The Rust extension (PyO3 0.28.2) already defaults to gil_used=false and has
zero global mutable state, making it inherently thread-safe. PyO3 automatically
ignores the abi3 feature flag when building for free-threaded Python, producing
version-specific cp313t/cp314t wheels instead of abi3 wheels.
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 this pull request may close these issues.

1 participant