From 1845506b7fb2d17dadf18d2b8b09225f2b4e3893 Mon Sep 17 00:00:00 2001 From: Zsombor Hollay-Horvath Date: Tue, 6 Jan 2026 18:28:49 +0100 Subject: [PATCH] Bump PyO3 to >=0.27 --- kdam/CHANGELOG.md | 2 ++ kdam/Cargo.toml | 6 ++--- kdam/examples/coloured/gradient.rs | 4 +-- kdam/examples/coloured/solid.rs | 4 +-- kdam/examples/messages/between.rs | 2 +- kdam/examples/messages/input.rs | 2 +- kdam/examples/messages/simple.rs | 2 +- kdam/examples/messages/write.rs | 2 +- kdam/examples/miscellaneous/custom.rs | 2 +- kdam/examples/miscellaneous/file_copy.rs | 2 +- .../miscellaneous/file_download/Cargo.toml | 2 +- kdam/examples/miscellaneous/inverse_unit.rs | 2 +- kdam/examples/miscellaneous/max_fps.rs | 2 +- kdam/examples/miscellaneous/monitor_mode.rs | 2 +- kdam/examples/miscellaneous/rayon.rs | 2 +- .../examples/miscellaneous/redirect_output.rs | 2 +- kdam/examples/multiple/row_manager_clean.rs | 2 +- kdam/examples/multiple/row_manager_keep.rs | 2 +- kdam/examples/multiple/thread.rs | 2 +- kdam/examples/notebook/Cargo.toml | 4 +-- kdam/examples/rich.rs | 4 +-- kdam/examples/showcase/animations.rs | 2 +- kdam/examples/showcase/fira_code.rs | 2 +- kdam/examples/showcase/spinner.rs | 2 +- kdam/examples/simple.rs | 2 +- kdam/examples/template.rs | 18 +++++++++++-- kdam/examples/unknown.rs | 2 +- kdam/src/lib.rs | 2 +- kdam/src/rich/bar.rs | 2 +- kdam/src/rich/styles.rs | 6 +++-- kdam/src/spinner.rs | 5 +--- kdam/src/std/bar.rs | 21 +++++++-------- kdam/src/std/extension.rs | 22 +++++++-------- kdam/src/std/iterator.rs | 2 +- kdam/src/std/manager.rs | 27 ++++++++++--------- kdam/src/std/monitor.rs | 16 ++++++----- kdam/src/std/notebook.rs | 7 ++--- kdam/src/std/styles.rs | 4 ++- kdam/src/term/colours.rs | 16 +++++------ kdam/src/term/mod.rs | 4 +-- kdam/src/term/writer.rs | 2 +- kdam_derive/src/lib.rs | 16 +++++------ 42 files changed, 125 insertions(+), 109 deletions(-) diff --git a/kdam/CHANGELOG.md b/kdam/CHANGELOG.md index 3290a4c..1e220b3 100644 --- a/kdam/CHANGELOG.md +++ b/kdam/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Bump up pyo3 >=0.27 + ## [0.6.3] - 2025-06-10 ### Changed diff --git a/kdam/Cargo.toml b/kdam/Cargo.toml index c91883d..f889409 100644 --- a/kdam/Cargo.toml +++ b/kdam/Cargo.toml @@ -12,17 +12,17 @@ repository = "https://github.com/clitic/kdam/tree/main/kdam" version = "0.6.3" [dependencies] -colorgrad = { version = "0.7", optional = true } +colorgrad = { version = "0.8", optional = true } formatx = { version = "0.2.4", optional = true } kdam_derive = { version = "0.1.1", path = "../kdam_derive", optional = true } -pyo3 = { version = ">=0.23,<0.26", optional = true } +pyo3 = { version = ">=0.27", optional = true } rayon = { version = "1.10", optional = true } terminal_size = "0.4" unicode-segmentation = { version = "1", optional = true } unicode-width = { version = "0.2", optional = true } [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_System_Console"] } +windows-sys = { version = "0.61.0", features = ["Win32_Foundation", "Win32_System_Console"] } [features] derive = ["dep:kdam_derive"] diff --git a/kdam/examples/coloured/gradient.rs b/kdam/examples/coloured/gradient.rs index 4f6641d..06a6ae5 100644 --- a/kdam/examples/coloured/gradient.rs +++ b/kdam/examples/coloured/gradient.rs @@ -1,5 +1,5 @@ -use kdam::{term::Colorizer, tqdm, Colour}; -use std::io::{stderr, IsTerminal}; +use kdam::{Colour, term::Colorizer, tqdm}; +use std::io::{IsTerminal, stderr}; fn main() { kdam::term::init(stderr().is_terminal()); diff --git a/kdam/examples/coloured/solid.rs b/kdam/examples/coloured/solid.rs index 31ff7da..981f2a4 100644 --- a/kdam/examples/coloured/solid.rs +++ b/kdam/examples/coloured/solid.rs @@ -1,5 +1,5 @@ -use kdam::{tqdm, BarExt}; -use std::io::{stderr, IsTerminal, Result}; +use kdam::{BarExt, tqdm}; +use std::io::{IsTerminal, Result, stderr}; fn main() -> Result<()> { kdam::term::init(stderr().is_terminal()); diff --git a/kdam/examples/messages/between.rs b/kdam/examples/messages/between.rs index 7604212..a1783c8 100644 --- a/kdam/examples/messages/between.rs +++ b/kdam/examples/messages/between.rs @@ -1,4 +1,4 @@ -use kdam::{term, term::Writer, tqdm, BarExt}; +use kdam::{BarExt, term, term::Writer, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/messages/input.rs b/kdam/examples/messages/input.rs index 70a3e31..2a73bc9 100644 --- a/kdam/examples/messages/input.rs +++ b/kdam/examples/messages/input.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/messages/simple.rs b/kdam/examples/messages/simple.rs index 0a618c9..2997f15 100644 --- a/kdam/examples/messages/simple.rs +++ b/kdam/examples/messages/simple.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/messages/write.rs b/kdam/examples/messages/write.rs index 8f32d82..ea64a55 100644 --- a/kdam/examples/messages/write.rs +++ b/kdam/examples/messages/write.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/miscellaneous/custom.rs b/kdam/examples/miscellaneous/custom.rs index 6625cba..66095c7 100644 --- a/kdam/examples/miscellaneous/custom.rs +++ b/kdam/examples/miscellaneous/custom.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, Bar, BarExt}; +use kdam::{Bar, BarExt, tqdm}; use std::{io::Result, num::NonZeroU16}; #[derive(BarExt)] diff --git a/kdam/examples/miscellaneous/file_copy.rs b/kdam/examples/miscellaneous/file_copy.rs index 5b35a6e..7ac21a2 100644 --- a/kdam/examples/miscellaneous/file_copy.rs +++ b/kdam/examples/miscellaneous/file_copy.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::{ fs::File, io::{BufReader, Read, Result, Write}, diff --git a/kdam/examples/miscellaneous/file_download/Cargo.toml b/kdam/examples/miscellaneous/file_download/Cargo.toml index 308e577..f20b555 100644 --- a/kdam/examples/miscellaneous/file_download/Cargo.toml +++ b/kdam/examples/miscellaneous/file_download/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -reqwest = { version = "0.12", features = ["stream"] } +reqwest = { version = "0.13", features = ["stream"] } futures-util = "0.3" tokio = { version = "1", features = ["full"] } kdam = { path = "../../.." } diff --git a/kdam/examples/miscellaneous/inverse_unit.rs b/kdam/examples/miscellaneous/inverse_unit.rs index 5e46421..a482146 100644 --- a/kdam/examples/miscellaneous/inverse_unit.rs +++ b/kdam/examples/miscellaneous/inverse_unit.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/miscellaneous/max_fps.rs b/kdam/examples/miscellaneous/max_fps.rs index 5f48c04..c08870f 100644 --- a/kdam/examples/miscellaneous/max_fps.rs +++ b/kdam/examples/miscellaneous/max_fps.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/miscellaneous/monitor_mode.rs b/kdam/examples/miscellaneous/monitor_mode.rs index 8bfef81..bd66bef 100644 --- a/kdam/examples/miscellaneous/monitor_mode.rs +++ b/kdam/examples/miscellaneous/monitor_mode.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/miscellaneous/rayon.rs b/kdam/examples/miscellaneous/rayon.rs index e709fb3..76070c8 100644 --- a/kdam/examples/miscellaneous/rayon.rs +++ b/kdam/examples/miscellaneous/rayon.rs @@ -1,4 +1,4 @@ -use kdam::{rayon::prelude::*, TqdmIterator, TqdmParallelIterator}; +use kdam::{TqdmIterator, TqdmParallelIterator, rayon::prelude::*}; use std::{ thread::sleep, time::{Duration, Instant}, diff --git a/kdam/examples/miscellaneous/redirect_output.rs b/kdam/examples/miscellaneous/redirect_output.rs index b7dde4f..5784f65 100644 --- a/kdam/examples/miscellaneous/redirect_output.rs +++ b/kdam/examples/miscellaneous/redirect_output.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::{ fs::File, io::{Result, Write}, diff --git a/kdam/examples/multiple/row_manager_clean.rs b/kdam/examples/multiple/row_manager_clean.rs index 9767847..d9f88d7 100644 --- a/kdam/examples/multiple/row_manager_clean.rs +++ b/kdam/examples/multiple/row_manager_clean.rs @@ -1,4 +1,4 @@ -use kdam::{term, tqdm, BarExt, RowManager}; +use kdam::{BarExt, RowManager, term, tqdm}; use std::{ io::Result, sync::{Arc, Mutex}, diff --git a/kdam/examples/multiple/row_manager_keep.rs b/kdam/examples/multiple/row_manager_keep.rs index d8cb3ec..44e34b0 100644 --- a/kdam/examples/multiple/row_manager_keep.rs +++ b/kdam/examples/multiple/row_manager_keep.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt, RowManager, term}; +use kdam::{BarExt, RowManager, term, tqdm}; use std::{ io::Result, sync::{Arc, Mutex}, diff --git a/kdam/examples/multiple/thread.rs b/kdam/examples/multiple/thread.rs index fb818bb..ba600ae 100644 --- a/kdam/examples/multiple/thread.rs +++ b/kdam/examples/multiple/thread.rs @@ -1,4 +1,4 @@ -use kdam::{term, tqdm, BarExt}; +use kdam::{BarExt, term, tqdm}; use std::{io::Result, thread, time::Duration}; fn main() -> Result<()> { diff --git a/kdam/examples/notebook/Cargo.toml b/kdam/examples/notebook/Cargo.toml index dfe36c3..a069ac7 100644 --- a/kdam/examples/notebook/Cargo.toml +++ b/kdam/examples/notebook/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] kdam = { path = "../..", features = ["notebook", "template"] } -pyo3 = { version = ">=0.23,<0.26", features = ["extension-module"] } +pyo3 = { version = ">=0.27", features = ["extension-module"] } [build-dependencies] -pyo3-build-config = ">=0.23,<0.26" +pyo3-build-config = ">=0.27" diff --git a/kdam/examples/rich.rs b/kdam/examples/rich.rs index 832534f..504b02e 100644 --- a/kdam/examples/rich.rs +++ b/kdam/examples/rich.rs @@ -1,5 +1,5 @@ -use kdam::{term, term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner}; -use std::io::{stderr, IsTerminal, Result}; +use kdam::{BarExt, Column, RichProgress, Spinner, term, term::Colorizer, tqdm}; +use std::io::{IsTerminal, Result, stderr}; fn main() -> Result<()> { term::init(stderr().is_terminal()); diff --git a/kdam/examples/showcase/animations.rs b/kdam/examples/showcase/animations.rs index 96291cc..6af30b8 100644 --- a/kdam/examples/showcase/animations.rs +++ b/kdam/examples/showcase/animations.rs @@ -1,4 +1,4 @@ -use kdam::{term, tqdm, Animation, BarExt}; +use kdam::{Animation, BarExt, term, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/showcase/fira_code.rs b/kdam/examples/showcase/fira_code.rs index 43fbf84..b562c8b 100644 --- a/kdam/examples/showcase/fira_code.rs +++ b/kdam/examples/showcase/fira_code.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/showcase/spinner.rs b/kdam/examples/showcase/spinner.rs index 84dca68..b9f43c6 100644 --- a/kdam/examples/showcase/spinner.rs +++ b/kdam/examples/showcase/spinner.rs @@ -1,4 +1,4 @@ -use kdam::{term, term::Writer, Spinner}; +use kdam::{Spinner, term, term::Writer}; use std::{ num::NonZeroI16, time::{Duration, Instant}, diff --git a/kdam/examples/simple.rs b/kdam/examples/simple.rs index c590785..0e45b1d 100644 --- a/kdam/examples/simple.rs +++ b/kdam/examples/simple.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/examples/template.rs b/kdam/examples/template.rs index 0c0fbcb..5fefcef 100644 --- a/kdam/examples/template.rs +++ b/kdam/examples/template.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt, Spinner}; +use kdam::{BarExt, Spinner, tqdm}; use std::io::Result; fn main() -> Result<()> { @@ -8,7 +8,21 @@ fn main() -> Result<()> { force_refresh = true, bar_format = "{desc suffix=' '}|{animation}| {spinner} {count}/{total} [{percentage:.0}%] in {elapsed human=true} ({rate:.1}/s, eta: {remaining human=true})", spinner = Spinner::new( - &["▁▂▃", "▂▃▄", "▃▄▅", "▄▅▆", "▅▆▇", "▆▇█", "▇█▇", "█▇▆", "▇▆▅", "▆▅▄", "▅▄▃", "▄▃▂", "▃▂▁"], + &[ + "▁▂▃", + "▂▃▄", + "▃▄▅", + "▄▅▆", + "▅▆▇", + "▆▇█", + "▇█▇", + "█▇▆", + "▇▆▅", + "▆▅▄", + "▅▄▃", + "▄▃▂", + "▃▂▁" + ], 30.0, 1.0, ) diff --git a/kdam/examples/unknown.rs b/kdam/examples/unknown.rs index 01282ba..9fe61d3 100644 --- a/kdam/examples/unknown.rs +++ b/kdam/examples/unknown.rs @@ -1,4 +1,4 @@ -use kdam::{tqdm, BarExt}; +use kdam::{BarExt, tqdm}; use std::io::Result; fn main() -> Result<()> { diff --git a/kdam/src/lib.rs b/kdam/src/lib.rs index bc2e8c5..b5771d3 100644 --- a/kdam/src/lib.rs +++ b/kdam/src/lib.rs @@ -9,7 +9,7 @@ pub mod format; pub mod term; pub use crate::std::{ - monitor, Animation, Bar, BarBuilder, BarExt, BarIter, Colour, RowManager, TqdmIterator, + Animation, Bar, BarBuilder, BarExt, BarIter, Colour, RowManager, TqdmIterator, monitor, }; #[cfg(feature = "derive")] diff --git a/kdam/src/rich/bar.rs b/kdam/src/rich/bar.rs index c7334a4..b69d553 100644 --- a/kdam/src/rich/bar.rs +++ b/kdam/src/rich/bar.rs @@ -1,5 +1,5 @@ use super::styles; -use crate::{std::Bar, term::Colorizer, BarExt}; +use crate::{BarExt, std::Bar, term::Colorizer}; use std::num::{NonZeroI16, NonZeroU16}; #[cfg(feature = "spinner")] diff --git a/kdam/src/rich/styles.rs b/kdam/src/rich/styles.rs index c2df6a0..c46968f 100644 --- a/kdam/src/rich/styles.rs +++ b/kdam/src/rich/styles.rs @@ -1,5 +1,5 @@ -use std::num::{NonZeroU16, NonZeroI16}; use crate::term::Colorizer; +use std::num::{NonZeroI16, NonZeroU16}; // Characters const BAR_CHR: &str = "━"; @@ -21,7 +21,9 @@ pub(super) fn bar(ncols: NonZeroU16, progress: f32) -> String { let ncols = ncols.get(); if progress >= 1.0 { - BAR_CHR.repeat(ncols as usize).colorize(BAR_COMPLETED_COLOUR) + BAR_CHR + .repeat(ncols as usize) + .colorize(BAR_COMPLETED_COLOUR) } else { let block = (ncols as f32 * progress) as u16; (BAR_CHR.repeat(block as usize) + BAR_END_CHR).colorize(BAR_COLOUR) diff --git a/kdam/src/spinner.rs b/kdam/src/spinner.rs index 6199084..ebde9de 100644 --- a/kdam/src/spinner.rs +++ b/kdam/src/spinner.rs @@ -32,10 +32,7 @@ impl Spinner { /// ``` pub fn new(frames: &[&str], interval: f32, speed: f32) -> Self { Self { - frames: frames - .iter() - .map(|x| String::from(*x)) - .collect(), + frames: frames.iter().map(|x| String::from(*x)).collect(), interval, speed, } diff --git a/kdam/src/std/bar.rs b/kdam/src/std/bar.rs index 1d1a760..313b9fd 100644 --- a/kdam/src/std/bar.rs +++ b/kdam/src/std/bar.rs @@ -1,13 +1,13 @@ use super::{ - styles::{Animation, Colour}, BarExt, + styles::{Animation, Colour}, }; use crate::{ format, term::{self, Colorizer, InitializedOutput, Writer}, }; use std::{ - io::{stdin, Result, Write}, + io::{Result, Write, stdin}, num::NonZeroU16, time::Instant, }; @@ -27,7 +27,6 @@ use crate::spinner::Spinner; #[cfg(feature = "template")] use formatx::Template; - /// Core implemention of console progress bar. /// /// # Example @@ -367,7 +366,7 @@ impl Bar { let miniters_constraint = if self.miniters <= 1 { true } else { - self.counter % self.miniters == 0 + self.counter.is_multiple_of(self.miniters) }; if (mininterval_constraint && miniters_constraint && delay_constraint) @@ -449,11 +448,11 @@ impl BarExt for Bar { fn render(&mut self) -> String { #[cfg(feature = "notebook")] if let Some(container) = &self.container { - Python::with_gil(|py| -> PyResult<()> { + Python::attach(|py| -> PyResult<()> { let pb = container .bind(py) .getattr("children")? - .downcast::()? + .cast::()? .get_item(1)?; pb.setattr("value", self.counter)?; @@ -563,9 +562,9 @@ impl BarExt for Bar { if let Some(container) = &self.container { let text = bar_format.unchecked_text(); - Python::with_gil(|py| -> PyResult<()> { + Python::attach(|py| -> PyResult<()> { let container = container.bind(py).getattr("children")?; - let container = container.downcast::()?; + let container = container.cast::()?; let (lbar, rbar) = (container.get_item(0)?, container.get_item(2)?); if let Some(index) = text.find("{animation}") { @@ -616,9 +615,9 @@ impl BarExt for Bar { #[cfg(feature = "notebook")] if let Some(container) = &self.container { - Python::with_gil(|py| -> PyResult<()> { + Python::attach(|py| -> PyResult<()> { let container = container.bind(py).getattr("children")?; - let container = container.downcast::()?; + let container = container.cast::()?; let (lbar, rbar) = (container.get_item(0)?, container.get_item(2)?); if self.indefinite() { @@ -1001,7 +1000,7 @@ impl BarBuilder { #[cfg(feature = "notebook")] if notebook::running() { - Python::with_gil(|py| -> PyResult<()> { + Python::attach(|py| -> PyResult<()> { let ipywidgets = PyModule::import(py, "ipywidgets")?; let ipython_display = PyModule::import(py, "IPython.display")?; diff --git a/kdam/src/std/extension.rs b/kdam/src/std/extension.rs index 1479afb..0a42132 100644 --- a/kdam/src/std/extension.rs +++ b/kdam/src/std/extension.rs @@ -3,17 +3,17 @@ use std::io::{Result, Write}; /// Comman progress bar functionalities shared between different types of progress bars. pub trait BarExt { /// Clear current progress bar display. - /// + /// /// Returns `Err`, if writing to handle fails. fn clear(&mut self) -> Result<()>; /// Take input via progress bar (without overlaping with bar(s)). - /// + /// /// Returns `Err`, if reading from stdin handle fails. fn input>(&mut self, text: T) -> Result; /// Force refresh current progress bar display. - /// + /// /// Returns `Err`, if writing to handle fails. fn refresh(&mut self) -> Result<()>; @@ -21,34 +21,34 @@ pub trait BarExt { fn render(&mut self) -> String; /// Resets counter to 0 for repeated use. - /// + /// /// Consider combining with `leave = true`. fn reset(&mut self, total: Option); /// Manually update the progress bar, useful for streams such as reading files. - /// + /// /// Returns whether an update was triggered or not depending on constraints. /// Returns `Err`, if writing to handle fails. fn update(&mut self, n: usize) -> Result; /// Set counter value instead of incrementing counter through [update](Self::update) method. - /// + /// /// Returns wheter a update was triggered or not depending on constraints. /// Returns `Err`, if writing to handle fails. fn update_to(&mut self, n: usize) -> Result; /// Print a message via progress bar (without overlaping with bar(s)). - /// + /// /// Returns `Err`, if writing to handle fails. fn write>(&mut self, text: T) -> Result<()>; /// Write progress bar rendered text to a writer (useful for writing files). - /// + /// /// If `n` is supplied then this method behaves like [update](Self::update) method. - /// + /// /// Returns whether a update was triggered or not depending on constraints. /// Returns `Err`, if writing to handle fails. - /// + /// /// # Example /// /// Using [write_to](Self::write_to) as [update_to](Self::update_to). @@ -59,7 +59,7 @@ pub trait BarExt { /// /// let mut pb = tqdm!(total = 100, animation = "ascii"); /// let mut f = File::create("kdam-logs.txt").unwrap(); - /// + /// /// for i in 1..101 { /// pb.counter = i; /// pb.write_to(&mut f, Some(0)); diff --git a/kdam/src/std/iterator.rs b/kdam/src/std/iterator.rs index 6d01480..f4aedb8 100644 --- a/kdam/src/std/iterator.rs +++ b/kdam/src/std/iterator.rs @@ -12,8 +12,8 @@ use std::iter::FusedIterator; #[cfg(feature = "rayon")] use rayon::iter::{ - plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, IndexedParallelIterator, ParallelIterator, + plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, }; #[cfg(feature = "rayon")] diff --git a/kdam/src/std/manager.rs b/kdam/src/std/manager.rs index c29fb2e..c2d93ac 100644 --- a/kdam/src/std/manager.rs +++ b/kdam/src/std/manager.rs @@ -159,21 +159,22 @@ impl RowManager { )?; for (bar, disable) in self.bars.iter_mut() { - if !*disable && !bar.completed() { - if let Some(pos) = self.avaliable_pos.iter().min() { - if bar.disable && bar.position != *pos { - bar.position = *pos; - - if self.nrows > bar.position { - bar.disable = false; - } + if !*disable + && !bar.completed() + && let Some(pos) = self.avaliable_pos.iter().min() + && bar.disable + && bar.position != *pos + { + bar.position = *pos; + + if self.nrows > bar.position { + bar.disable = false; + } - bar.refresh()?; + bar.refresh()?; - if self.avaliable_pos.remove(&bar.position) { - self.acquired_pos.insert(bar.position); - } - } + if self.avaliable_pos.remove(&bar.position) { + self.acquired_pos.insert(bar.position); } } } diff --git a/kdam/src/std/monitor.rs b/kdam/src/std/monitor.rs index 48f87c8..fe957c2 100644 --- a/kdam/src/std/monitor.rs +++ b/kdam/src/std/monitor.rs @@ -60,15 +60,17 @@ pub fn bar(pb: Bar, maxinterval: f32) -> (Arc>, thread::JoinHandle<() let pb_arc = Arc::new(Mutex::new(pb)); let pb_arc_clone = pb_arc.clone(); - let handle = thread::spawn(move || loop { - thread::sleep(std::time::Duration::from_secs_f32(maxinterval)); - let mut pb_monitor = pb_arc_clone.lock().unwrap(); + let handle = thread::spawn(move || { + loop { + thread::sleep(std::time::Duration::from_secs_f32(maxinterval)); + let mut pb_monitor = pb_arc_clone.lock().unwrap(); - if pb_monitor.completed() { - break; - } + if pb_monitor.completed() { + break; + } - let _ = pb_monitor.refresh(); + let _ = pb_monitor.refresh(); + } }); (pb_arc, handle) diff --git a/kdam/src/std/notebook.rs b/kdam/src/std/notebook.rs index 725e3a7..df4d433 100644 --- a/kdam/src/std/notebook.rs +++ b/kdam/src/std/notebook.rs @@ -1,5 +1,5 @@ -use std::sync::atomic::{AtomicBool, Ordering}; use pyo3::{Bound, Py, PyAny, Python}; +use std::sync::atomic::{AtomicBool, Ordering}; static RUNNING: AtomicBool = AtomicBool::new(false); @@ -8,9 +8,7 @@ pub(crate) struct PyContainer(Py); impl Clone for PyContainer { fn clone(&self) -> Self { - Python::with_gil(|py| { - PyContainer(self.0.clone_ref(py)) - }) + Python::attach(|py| PyContainer(self.0.clone_ref(py))) } } @@ -27,7 +25,6 @@ impl<'py> From> for PyContainer { } } - /// Set whether `kdam` is running inside a jupyter notebook or not. pub fn set_notebook(running: bool) { RUNNING.store(running, Ordering::SeqCst); diff --git a/kdam/src/std/styles.rs b/kdam/src/std/styles.rs index 5c51bba..3b94ba2 100644 --- a/kdam/src/std/styles.rs +++ b/kdam/src/std/styles.rs @@ -189,7 +189,9 @@ impl Colour { pub fn rainbow() -> Self { Self::Gradient(Arc::new( GradientBuilder::new() - .html_colors(&["violet", "indigo", "blue", "green", "yellow", "orange", "red"]) + .html_colors(&[ + "violet", "indigo", "blue", "green", "yellow", "orange", "red", + ]) .build() .expect("failed to compile rainbow gradient"), )) diff --git a/kdam/src/term/colours.rs b/kdam/src/term/colours.rs index fece4b2..2926923 100644 --- a/kdam/src/term/colours.rs +++ b/kdam/src/term/colours.rs @@ -12,8 +12,8 @@ use std::sync::atomic::{AtomicBool, Ordering}; #[cfg(windows)] use windows_sys::Win32::System::Console::{ - GetConsoleMode, GetStdHandle, SetConsoleMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING, - STD_OUTPUT_HANDLE, + ENABLE_VIRTUAL_TERMINAL_PROCESSING, GetConsoleMode, GetStdHandle, STD_OUTPUT_HANDLE, + SetConsoleMode, }; const COLOURS: [&str; 8] = [ @@ -34,18 +34,18 @@ const COLOUR_RESET: &str = "\x1b[0m"; static SHOULD_COLORIZE: AtomicBool = AtomicBool::new(false); /// Enable/Disable colorization property of [colorizer](crate::term::Colorizer) trait. -/// +/// /// Colorization is **disabled** by default. -/// +/// /// # Platform-specific notes -/// +/// /// This functions also enables support for ANSI escape codes on windows. -/// +/// /// # Example -/// +/// /// ``` /// use std::io::{stderr, IsTerminal}; -/// +/// /// kdam::term::init(stderr().is_terminal()); /// ``` pub fn init(always: bool) { diff --git a/kdam/src/term/mod.rs b/kdam/src/term/mod.rs index 0dd04b8..02609c1 100644 --- a/kdam/src/term/mod.rs +++ b/kdam/src/term/mod.rs @@ -1,11 +1,11 @@ //! Terminal related utilities. -use std::io::{stderr, Result, Write}; +use std::io::{Result, Write, stderr}; mod colours; mod writer; -pub use colours::{colour, init, Colorizer}; +pub use colours::{Colorizer, colour, init}; pub use writer::{InitializedOutput, Writer}; /// Hide cursor. diff --git a/kdam/src/term/writer.rs b/kdam/src/term/writer.rs index 8e570f1..81718a3 100644 --- a/kdam/src/term/writer.rs +++ b/kdam/src/term/writer.rs @@ -1,6 +1,6 @@ use std::{ fs::{File, OpenOptions}, - io::{stderr, stdout, Result, Write}, + io::{Result, Write, stderr, stdout}, }; #[cfg(target_os = "windows")] diff --git a/kdam_derive/src/lib.rs b/kdam_derive/src/lib.rs index a6fcc56..152c0d9 100644 --- a/kdam_derive/src/lib.rs +++ b/kdam_derive/src/lib.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; use quote::{format_ident, quote}; -use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields, FieldsNamed, Meta, Path}; +use syn::{Data, DataStruct, DeriveInput, Fields, FieldsNamed, Meta, Path, parse_macro_input}; /// Derive [BarExt](https://docs.rs/kdam/latest/kdam/trait.BarExt.html) trait for a struct. /// @@ -9,21 +9,21 @@ use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields, FieldsNamed, /// ```no_test /// use kdam::{tqdm, Bar, BarExt}; /// use std::{io::Result, num::NonZeroU16}; -/// +/// /// #[derive(BarExt)] /// struct CustomBar { /// #[bar] /// pb: Bar, /// } -/// +/// /// impl CustomBar { /// /// Render progress bar text. /// fn render(&mut self) -> String { /// let fmt_percentage = self.pb.fmt_percentage(0); /// let padding = 1 + fmt_percentage.chars().count() as u16 + self.pb.animation.spaces() as u16; -/// +/// /// let ncols = self.pb.ncols_for_animation(padding); -/// +/// /// if ncols == 0 { /// self.pb.bar_length = padding - 1; /// fmt_percentage @@ -111,18 +111,18 @@ pub fn bar_ext(input: TokenStream) -> TokenStream { if !self.#bar_field.leave && self.#bar_field.position > 0 { return self.clear(); } - + self.#bar_field.total = self.#bar_field.counter; } let text = self.render(); let bar_length = #crate_name::term::Colorizer::len_ansi(text.as_str()) as u16; - + if bar_length > self.#bar_field.bar_length { self.clear()?; self.#bar_field.bar_length = bar_length; } - + self.#bar_field.writer.print_at(self.#bar_field.position, text.as_bytes())?; Ok(()) }