Add free-threaded Python support - #2310
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
103c93d to
4c1e000
Compare
|
For testing it's possible to use https://github.com/Quansight-Labs/setup-python as a drop-in replacement for the GitHub one |
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (1)
src/python_interpreter/config.rs:131
- The handling of abiflags for free-threaded Python on Windows is incomplete. This could lead to unexpected behavior if free-threaded Python is used on Windows.
// FIXME: windows abiflags for free-threaded python?
ffbf35a to
ba5b918
Compare
|
Happy to help with this if needed. The windows free-threaded packaging situation is "fun". |
dd2379a to
ae896ff
Compare
Thanks, feel free to send PR to this branch! |
ae896ff to
22add66
Compare
|
It looks like a few of the tests hardcode using abi3: Since free-threading and abi3 are incompatible, would it be better to skip over the tests that use these crates? For the ones that are testing whether the limited api support is working correctly I think skipping them makes sense, but some of these seem to be more generic integration tests for maturin that happen to use the limited API. I don't see an easy way to optionally turn on and off the abi3 feature in the test crates. Am I missing something? If not, any guidance? |
|
We should probably try to support this case because My gut says that it'd be good enough for now if |
Hmm, that's sort of in the vein of PyO3/pyo3#4719, but maybe what I'm doing there making more things hard errors is bad and it would be better to warn and just turn off limited API and set the ABI to Py_3_13 if someone is trying to build for the free-threaded ABI but asks for an earlier ABI. |
We have a convoluted setup where |
|
👍 It seems to me that we probably don't want |
|
Yep, if I add |
|
It looks like three of the crates use old PyO3 APIs and need to be updated: Other errors from trying to build one of these crates: DetailsI'm confused why the update to PyO3 0.23 last week didn't break tests using these crates on CI. |
9c7dc83 to
417eb38
Compare
There was a problem hiding this comment.
Copilot reviewed 5 out of 8 changed files in this pull request and generated no suggestions.
Files not reviewed (3)
- src/auditwheel/audit.rs: Evaluated as low risk
- src/build_options.rs: Evaluated as low risk
- src/cross_compile.rs: Evaluated as low risk
Some of these tests are not built but only used to test generating source distribution, will fix them later in a separate PR. |
Installing `pyproject-fmt` or `tox-toml-fmt` under [free-threaded CPython](https://docs.python.org/3/howto/free-threading-python.html) failed because the published `cp39-abi3` wheel is rejected by free-threaded interpreters, and [PEP 803 (`abi3t`)](https://peps.python.org/pep-0803/) is still in progress in CPython 3.15 (tracked in [python/cpython#146636](python/cpython#146636), with the related loader bug at [python/cpython#120901](python/cpython#120901)). 🧵 Users on `python3.15t` saw `The built wheel pyproject_fmt-2.21.1-cp39-abi3-linux_x86_64.whl is not compatible with the current Python 3.15t`, and `3.13t`/`3.14t` had no compatible wheel either. The PyO3 modules are now marked with [`gil_used = false`](https://pyo3.rs/v0.28.3/free-threading) since the format pipeline is pure Rust with no shared Python state, so they run without re-enabling the GIL on free-threaded interpreters. `abi3` becomes a [Cargo feature](https://doc.rust-lang.org/cargo/reference/features.html) rather than a hardcoded dependency flag, which lets [maturin](https://www.maturin.rs/) produce version-specific wheels for `3.15t` (where its abi3 [auto-fallback heuristic](PyO3/maturin#2310) is currently too eager because PEP 803 isn't fully landed in `3.15.0a8`) by setting [`MATURIN_PEP517_ARGS`](https://www.maturin.rs/distribution#cross-compiling)`=--no-default-features --features extension-module` in the per-env tox config; for `3.13t`/`3.14t` maturin already auto-falls-back to per-version builds. The build matrices now ship `cp313t`/`cp314t` wheels alongside the existing abi3 wheel, and the test matrix covers `3.15`, `3.13t`, `3.14t`, and `3.15t`. `max_supported_python` moves to `3.15` and the [trove classifiers](https://pypi.org/classifiers/) gain `Free Threading :: 1 - Unstable`. A small `build.rs` per package emits the macOS [`-undefined dynamic_lookup`](https://pyo3.rs/v0.28.3/building-and-distribution#macos) linker flag only when `extension-module` is active, so local `cargo build` works on Apple Silicon. ✨ Closes #305
Implementation details:
Py_GIL_DISABLEDbuild flag for runnable Python interpreterspython3.13twhen cross compilingCloses #2298
Closes #2315