Skip to content

Commit

Permalink
Merge pull request #21 from ljeub-pometry/pyo3_0_22
Browse files Browse the repository at this point in the history
Support pyo3 version 0.22
  • Loading branch information
clitic authored Nov 6, 2024
2 parents 6ec1826 + b3fc30a commit d82957a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kdam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = "0.5.2"
colorgrad = { version = "0.6", optional = true }
formatx = { version = "0.2.2", optional = true }
kdam_derive = { version = "0.1.0", path = "../kdam_derive", optional = true }
pyo3 = { version = "0.21", optional = true }
pyo3 = { version = "0.22.5", optional = true }
rayon = { version = "1.10", optional = true }
terminal_size = "0.3"
unicode-segmentation = { version = "1", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions kdam/examples/notebook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
kdam = { path = "../..", features = ["notebook", "template"] }
pyo3 = { version = "0.21", features = ["extension-module"] }
pyo3 = { version = "0.22.5", features = ["extension-module"] }

[build-dependencies]
pyo3-build-config = "0.21"
pyo3-build-config = "0.22.5"
3 changes: 2 additions & 1 deletion kdam/src/std/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::spinner::Spinner;
#[cfg(feature = "template")]
use formatx::Template;


/// Core implemention of console progress bar.
///
/// # Example
Expand Down Expand Up @@ -72,7 +73,7 @@ pub struct Bar {
// Non Builder Fields
pub bar_length: u16,
#[cfg(feature = "notebook")]
container: Option<Py<PyAny>>,
container: Option<notebook::PyContainer>,
pub counter: usize,
current_ncols: u16,
elapsed_time: f32,
Expand Down
26 changes: 26 additions & 0 deletions kdam/src/std/notebook.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
use std::sync::atomic::{AtomicBool, Ordering};
use pyo3::{Bound, Py, PyAny, Python};

static RUNNING: AtomicBool = AtomicBool::new(false);

#[derive(Debug)]
pub(crate) struct PyContainer(Py<PyAny>);

impl Clone for PyContainer {
fn clone(&self) -> Self {
Python::with_gil(|py| {
PyContainer(self.0.clone_ref(py))
})
}
}

impl PyContainer {
#[inline]
pub fn bind<'py>(&self, py: Python<'py>) -> &Bound<'py, PyAny> {
self.0.bind(py)
}
}

impl<'py> From<Bound<'py, PyAny>> for PyContainer {
fn from(value: Bound<'py, PyAny>) -> Self {
Self(value.into())
}
}


/// Set whether `kdam` is running inside a jupyter notebook or not.
pub fn set_notebook(running: bool) {
RUNNING.store(running, Ordering::SeqCst);
Expand Down

0 comments on commit d82957a

Please sign in to comment.