Skip to content

rust: upgrade PyO3 from 0.25 to 0.29 - #356

Open
zydo wants to merge 5 commits into
indygreg:mainfrom
zydo:pyo3-0.29
Open

zydo wants to merge 5 commits into
indygreg:mainfrom
zydo:pyo3-0.29

Conversation

@zydo

@zydo zydo commented Oct 12, 2026 •

Copy link
Copy Markdown

Upgrades PyO3 from 0.25 to 0.29, the first release that supports Python 3.15, and ports the Rust backend to the APIs renamed or removed since 0.25 (PyObject -> Py<PyAny>, downcast*() -> cast*(), allow_threads() -> detach(), assume_gil_acquired() -> assume_attached()). The deprecated Py::from_borrowed_ptr() in ZstdBufferWithSegments.segments() is replaced with a safe conversion.

Supersedes #310: Dependabot's bump only changes Cargo.toml/Cargo.lock, and the Rust backend doesn't compile against 0.29 without these code changes. (Its CI looks mostly fine only because Rust test failures are continue-on-error.)

Depends on #358 (CI fixes); only the last commit belongs to this PR.

All workflows pass on the fork: https://github.com/zydo/python-zstandard/actions?query=branch%3Apyo3-0.29. The Rust backend results match main: the one failing Rust test, test_train_dictionary.py::TestTrainDictionary::test_optimize, already fails on main.

zydo added 5 commits October 12, 2026 03:06
load_setup_py_data() executes setup.py in the conda-build process.
setup.py prepends "." to sys.path, so the source tree's unbuilt
zstandard package later shadows the zstandard bindings that
conda-package-handling imports for .conda support. conda-build then
fails with "Didn't recognize extension for file '...conda'".

Read the version from c-ext/python-zstandard.h with load_file_regex()
instead.
cibuildwheel installs the test-groups packages unlocked, so it picked up
the latest mypy, which now depends on ast-serialize. ast-serialize has no
wheels for musllinux_1_1 or musllinux s390x, and building it from source
needs a Rust toolchain the containers don't have, failing those wheel
jobs before any test ran.

Move the test suite's dependencies into a new "test" dependency group,
have "dev" include it plus mypy, and point cibuildwheel at "test".
On Apple Silicon runners Homebrew installs into /opt/homebrew, which
isn't on the compiler's default search paths, so the --system-zstd build
failed with "'zdict.h' file not found". Pass Homebrew's include and lib
directories explicitly, and build for arm64 only since Homebrew's libzstd
is not universal2.
test_stream_source_readinto intermittently fails on macos-26-intel
runners with DeadlineExceeded: a single example took 31s against the 20s
deadline, then 18s on hypothesis's rerun, which hypothesis reports as a
FlakyFailure. The timing depends on runner load, not on the code under
test, so don't enforce a deadline in the ci profile, as the expensive
profile already does.
PyO3 0.29 is the first release that supports Python 3.15.

Port the Rust backend to the APIs renamed or removed since 0.25:
PyObject becomes Py<PyAny>, downcast*() becomes cast*(), allow_threads()
becomes detach() and assume_gil_acquired() becomes assume_attached().

Py::from_borrowed_ptr() is deprecated, so build the parent reference in
ZstdBufferWithSegments.segments() with a safe conversion instead of a
raw pointer cast.
@zydo zydo mentioned this pull request Oct 12, 2026
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