Skip to content

build: upgrade PyO3 to 0.30.1 so citry-core builds for Python 3.15 - #340

Merged
JuroOravec merged 1 commit into
mainfrom
fix/pyo3-0-30
Oct 24, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/pyo3-0-30

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What this changes

citry-core did not build for Python 3.15: the workspace pinned PyO3 0.27.1,
whose pyo3-ffi refuses any CPython newer than 3.14. This PR moves the
workspace to PyO3 0.30.1, which supports Python 3.15.0 and free-threaded
3.15. abi3 stays at py310 here, because the Python 3.10 drop is a separate
change that moves the release files together.

Adding 3.15 to the test matrix, the classifiers and the wheel set is the
docs/CI follow-up.

What had to change

I read PyO3's changelog for 0.28, 0.29 and 0.30. The 0.30 migration guide
has no "0.29 to 0.30" section. These changes reach this repository:

  • FromPyObject for Clone classes. PyO3 0.30 no longer gives a
    Clone #[pyclass] a FromPyObject implementation by default; 0.28
    deprecated it. The AST classes in citry_template_parser are passed back
    into Rust by value, for example through a constructor that takes a
    Token. So the 30 Clone classes there now ask for it with
    #[pyclass(from_py_object)], which gives them exactly what 0.27 gave
    them.
  • Garbage-collector tracking. PyO3 0.30 makes every #[pyclass] a
    garbage-collected type (PyO3#6269),
    so every new object is tracked. The native-render _NativeRow,
    _NativeRun, _NativeOccurrence and _LeafJson objects hold only
    strings, Rust data and objects that cannot refer back to them. A page
    creates thousands of them. They were untracked before, and the
    native-render tests check that they still are: they are now created
    through new_untracked in native_render/mod.rs, which untracks each
    new object when its type is collector-managed. Every other class, such as
    Template, Token and the Browser* records, is now tracked. They hold
    only Rust data, so I measured whether that costs enough to untrack them
    too (the threshold was 2%; see "Collector cost" below). It does not.
  • Free-threading default. PyO3 0.28 made modules declare free-threading
    support by default. Our module already says #[pymodule(gil_used = true)],
    so a free-threaded interpreter still enables the GIL when it imports
    citry_core._rust, as on 3.14t today.
  • Argument errors. A wrong argument type raises a TypeError with
    PyO3's new wording, and the argument's name moves into a note:
    parse_template(123) raised argument 'input': 'int' object cannot be cast as 'str', and now raises 'int' object is not an instance of 'str'
    with __notes__ == ["while processing 'input'"]. Nothing in the
    repository reads that text. The citry-core changelog notes it.
  • Smaller changes. HtmlAttrKind values are shared objects now, so
    a.kind is b.kind holds where only == did. After
    del sys.modules["citry_core._rust"], importing again builds a new
    module object, because PyO3 uses multi-phase initialization; the classes
    stay the same objects.

The other removals (Py::from_owned_ptr, the PyErr conversions from UTF-8
errors, tuple super-class initialization and get_refcnt) are not used
here.

What Python can see

I dumped every module, class, method, signature and docstring of
citry_core._rust before and after: 644 entries. The dump records names,
signatures and docstrings, so it does not see the error wording, tracking
and identity changes above. Within what it records, everything matches
except for one change that PyO3 0.28 made. The variant classes of
template_parser.Node and template_parser.TemplateElement are now named
after their variant, rather than after the enum and the variant joined
with _:

type(node).__name__      # was "Node_WithBody", now "WithBody"
type(node).__qualname__  # now "Node.WithBody"

They also carry their Rust docstrings. isinstance(node, Node.WithBody) is
unaffected.

Why I kept the new names. PyO3 0.30 has no option to keep the old
flat names: its #[pyclass] macro passes each variant's own name to the
class builder (pyo3-macros-backend 0.30.1,
pyclass.rs, PyClassImplsBuilder::new(&variant_cls, &variant_name, ...)).
It does not pass variant options through (its own comment there reads
"TODO: propagate variant.options"), so #[pyo3(name = ...)] on a variant
cannot rename the class. This is not a break in citry-core's public API:
the old flat names were never attributes of any module at runtime, public
or private, and existed only as type-only names in the private _rust.pyi
stub. citry_core.template_parser exports Node and TemplateElement,
and Node.WithBody and the other variants are reached through them exactly
as before. So packages/py/citry_core/CHANGELOG.md notes the new
__name__, __qualname__ and docstrings, without a breaking-change label.

Nothing in the repository reads these names. I grepped packages/py,
docs_site and docs for the old names, and for __name__,
__qualname__ and repr() of template AST nodes. The type(...).__name__
uses I found are on Citry's Python node classes and on Python's own ast.
The _rust.pyi stub now declares the variants as nested classes, as at
runtime: Node.SelfClosing, Node.WithBody, TemplateElement.Text and
so on. The ruff exemption comment in pyproject.toml no longer names
Node_WithBody. mypy is clean on every package.

Collector cost

Both builds were optimized (--release with lto = false,
codegen-units = 16 and line-tables-only debug info, to fit the disk), on
Python 3.14 on an Apple M-series Mac. Each figure is the median of five
fresh processes, and each process takes the median of its timed loop.

Measurement PyO3 0.27.1 PyO3 0.30.1
Warm render of the 1,400-row project board, per render 54.7 ms 54.0 ms
Collections during 10 board renders (generation 0/1/2) 101 (92/8/1) 122 (111/10/1)
Time in the collector during those 10 renders 31.4 ms 31.8 ms
Parse and compile of 143 docs and benchmark templates 13.9 ms 13.9 ms
Collections during 20 parse-and-compile passes 0 0

The render time and the parse-and-compile time are within noise. The newly
tracked objects add about 20% more generation-0 collections during a
render, but the time spent in them grows by about 1%. The AST classes
therefore stay tracked, and only the four native-render classes are
created untracked. The two throwaway scripts render the board through
benchmarks/web/apps/citry/app.py and time parse_template plus
compile_template, with a gc.callbacks hook that counts and times each
collection.

Tests

  • cargo test, cargo clippy --all-targets -D warnings and cargo fmt for
    citry_core_py and citry_template_parser, plus the fast gate.
  • Python 3.14: the citry, citry_ui, citry_core, citry_lsp and pygments_citry
    suites pass (10,955 tests), including the GC-tracking tests that failed
    until the objects were created untracked.
  • Python 3.15.1: I built citry-core in a throwaway venv and ran the same
    suites, and all 10,955 tests pass. The venv used newer versions of the
    packages that have no 3.15 wheel at their locked version. With the newest
    tzdata and Pygments, three tests that pin locked data failed; with the
    locked tzdata 2026.3 and Pygments 2.20.0 they pass.
  • Free-threaded Python 3.15.1: citry-core builds, imports with the GIL
    enabled, renders a component, and passes the citry_core suite (499
    tests).

PyPy 3.11, 3.14t, Windows (x64 and x86, which now link with raw-dylib)
and Pyodide are not built locally; the release workflow builds them.

Changelog: packages/py/citry_core/CHANGELOG.md (3.15 builds, the
variant-class names and the argument-error wording).

🤖 Generated with Claude Code

pyo3-ffi 0.27 caps CPython at 3.14. PyO3 0.30.1 supports Python 3.15.0,
including the free-threaded build. Little that Python can see changes:

- PyO3 0.30 no longer gives a `Clone` `#[pyclass]` a `FromPyObject`
  implementation by default. The 30 `Clone` classes in
  citry_template_parser now ask for it with `from_py_object`, as 0.27 gave
  it to them, so the AST classes still convert from Python as before.
- PyO3 0.30 makes every `#[pyclass]` a garbage-collected type. The
  native-render row, run, occurrence and leaf objects hold nothing that can
  refer back to them, and a page makes thousands of them, so they are
  created untracked (`new_untracked`), as they were before.
- The module keeps `gil_used = true`. Since PyO3 0.28, a module that does
  not say so declares that it runs without the GIL.
- Argument type errors use PyO3's new wording and name the argument in a
  note, every other class is tracked by the cyclic collector, and
  `HtmlAttrKind` values are shared objects.

A dump of every module, class, signature and docstring in
citry_core._rust before and after matches, except that the variant
classes of `Node` and `TemplateElement` are named after their variant
(`Node.WithBody` rather than `Node_WithBody`) and carry their
docstrings, which PyO3 0.28 changed and offers no option to undo. The
`_rust.pyi` stub now declares the variants as nested classes, as at
runtime, and the citry-core changelog notes the new names and the new
error wording. abi3 stays at py310.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 72c42f1 into main Oct 24, 2026
25 of 31 checks passed
@JuroOravec
JuroOravec deleted the fix/pyo3-0-30 branch October 24, 2026 21:20
JuroOravec added a commit that referenced this pull request Oct 27, 2026
The rest of #177, now that citry-core builds on 3.15 (#340).

- All five packages list Python 3.15 in their classifiers.
- The Python test matrix gains Ubuntu and Windows 3.15 jobs, and the
  macOS pair becomes 3.11 and 3.15. The Citry UI wheel install check now
  runs on 3.11 and 3.15, the citry, citry-lsp, citry-ui and
  pygments-citry release install tests run on 3.15 too, and the
  diagnostic workflow offers it.
- The citry-core release now installs and tests its ABI3 wheel on 3.15
  (on Linux and Windows next to 3.11-3.14, and as the newest on macOS),
  and builds a free-threaded cp315t wheel for every Linux and musllinux
  architecture next to cp314t. The release set grows from 36 to 46
  files; the verifier, its test, the toolchain validator and
  docs/codebase.md move with it.
- uv.lock moves only what a 3.15 test job installs and has no cp315
  wheel for: markupsafe 3.0.4, and pydantic 2.14.1 with pydantic-core
  2.50.1 (pydantic 2.14.1 needs typing-extensions 4.16.0 and
  typing-inspection 0.4.4). tzdata, pygments and everything else stay.
- PyYAML, which the citry-ui tests and the repository workflow tests
  read manifests with, has no wheel for 3.15 (or PyPy) and builds from
  its sdist with Cython. require-build-hashes refused that build, so
  scripts/build_constraints.py now also pins the backends in
  THIRD_PARTY_BUILD_REQUIREMENTS (Cython 3.3.0), and docs/codebase.md
  says how to add another one. A source build of PyYAML on CPython 3.15.1
  and PyPy 3.11.17 with an empty cache passes with the pin.
- django-components (and its djc-core) is in citry's `benchmark` group,
  and minify-html in the root `docs` extra; no test job installs either,
  so neither needs a 3.15 wheel.
- The README, the package READMEs, the installation and compatibility
  pages, the development page, and docs/codebase.md say 3.11 through
  3.15, and each package's changelog says it supports 3.15.

The example projects keep testing on 3.11 and 3.14: their lockfiles pin
the released Citry and markupsafe 3.0.3, which has no cp315 wheel, so
moving them needs their own relock and is left for a follow-up.

Closes #177

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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