Skip to content

Commit b05f48f

Browse files
authored
Merge pull request #124 from artiz/claude/pyo3-0.29
fix(py): migrate the bindings to pyo3 0.29
2 parents a65796a + c01bbf8 commit b05f48f

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)