Skip to content

Commit c01bbf8

Browse files
artizclaude
andcommitted
fix(py): migrate the bindings to pyo3 0.29
Dependabot bumped crates/docling-py to pyo3 0.29 (#122) without touching the code, so every wheel build now dies on the 0.23-era APIs. Move to the current ones: FromPyObject gained a second lifetime, an Error associated type and takes Borrowed (extract_bound is gone), and Python::allow_threads is now Python::detach. cargo check + clippy clean; maturin develop + the full pytest suite (30 tests) pass against 0.29. Signed-off-by: artiz <artem.kustikov@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EY5KAiquN4YpVf2PXEQkVT
1 parent a65796a commit c01bbf8

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

crates/docling-py/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/docling-py/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ where
3838
use std::time::Duration;
3939

4040
let (tx, rx) = channel();
41-
// Mutex only to make the receiver Sync for `allow_threads`; never contended.
41+
// Mutex only to make the receiver Sync for `detach`; never contended.
4242
let rx = Mutex::new(rx);
4343
std::thread::spawn(move || {
4444
let _ = tx.send(work());
4545
});
4646
loop {
4747
let received =
48-
py.allow_threads(|| rx.lock().unwrap().recv_timeout(Duration::from_millis(100)));
48+
py.detach(|| rx.lock().unwrap().recv_timeout(Duration::from_millis(100)));
4949
match received {
5050
Ok(result) => return result,
5151
Err(RecvTimeoutError::Timeout) => py.check_signals()?,
@@ -348,7 +348,7 @@ impl PyChunkStream {
348348
Done,
349349
}
350350
loop {
351-
let received = py.allow_threads(|| match self.rx.lock().unwrap().as_ref() {
351+
let received = py.detach(|| match self.rx.lock().unwrap().as_ref() {
352352
None => Recv::Done,
353353
Some(rx) => match rx.recv_timeout(Duration::from_millis(100)) {
354354
Ok(item) => Recv::Item(item),
@@ -489,13 +489,15 @@ fn chunk_document(
489489
/// str / pathlib.Path / anything os.PathLike → PathBuf.
490490
struct PathLike(std::path::PathBuf);
491491

492-
impl<'py> FromPyObject<'py> for PathLike {
493-
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
492+
impl<'a, 'py> FromPyObject<'a, 'py> for PathLike {
493+
type Error = PyErr;
494+
495+
fn extract(ob: pyo3::Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
494496
if let Ok(p) = ob.extract::<std::path::PathBuf>() {
495497
return Ok(PathLike(p));
496498
}
497499
let fspath = ob.py().import("os")?.getattr("fspath")?;
498-
Ok(PathLike(fspath.call1((ob,))?.extract()?))
500+
Ok(PathLike(fspath.call1((&*ob,))?.extract()?))
499501
}
500502
}
501503

0 commit comments

Comments
 (0)