From a2dde94a3a4643ae1dac8bcf70af06dda6c588fe Mon Sep 17 00:00:00 2001 From: Collide <44722470+TD-Sky@users.noreply.github.com> Date: Tue, 20 May 2025 21:08:52 +0800 Subject: [PATCH] chore(deps): Bump dependencies (#95) * bump ureq to 3 * bump rand to 0.9 * cargo fmt --------- Co-authored-by: jamjamjon --- Cargo.toml | 21 ++++++++++---------- src/io/hub.rs | 38 +++++++++++++++++++++++++------------ src/models/sam/impl.rs | 6 +++--- src/utils/logits_sampler.rs | 4 ++-- src/utils/mod.rs | 4 ++-- src/viz/color.rs | 8 ++++---- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b4146ae..8c56a34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,9 @@ ndarray = { version = "0.16.1", features = ["rayon", "serde"] } indicatif = { version = "0.17.11" } log = "0.4.26" minifb = { version = "0.28.0" } -rand = { version = "0.8.5" } -ureq = { version = "2", default-features = true, features = [ "socks-proxy" ] } +rand = { version = "0.9" } +http = "1.3" +ureq = { version = "3", default-features = true, features = ["socks-proxy"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" rayon = { version = "1.10.0" } @@ -32,17 +33,17 @@ geo = "0.30.0" chrono = "0.4.40" regex = "1.11.1" sha2 = "0.10.8" -tempfile = "3.19.1" +tempfile = "3.19.1" video-rs = { version = "0.10.3", features = ["ndarray"], optional = true } -fast_image_resize = { version = "5.1.2", features = ["image"]} -ndarray-npy = "0.9.1" +fast_image_resize = { version = "5.1.2", features = ["image"] } +ndarray-npy = "0.9.1" half = { version = "2.3.1" } prost = "0.13.5" -ort = { version = "2.0.0-rc.9", default-features = false, optional = true , features = [ - "ndarray", - "copy-dylibs", - "half" -]} +ort = { version = "2.0.0-rc.9", default-features = false, optional = true, features = [ + "ndarray", + "copy-dylibs", + "half", +] } tokenizers = { version = "0.21.1" } paste = "1.0.15" diff --git a/src/io/hub.rs b/src/io/hub.rs index 5f32a0e..7d6c750 100644 --- a/src/io/hub.rs +++ b/src/io/hub.rs @@ -197,8 +197,9 @@ impl Hub { pack = pack.with_url(s).with_tag(&tag_).with_file_name(&file_name_); if let Some(n) = retry!(self.max_attempts, Self::fetch_get_response(s))? - .header("Content-Length") - .and_then(|s| s.parse::().ok()) + .headers() + .get(http::header::CONTENT_LENGTH) + .and_then(|v| v.to_str().ok()?.parse::().ok()) { pack = pack.with_file_size(n); } @@ -242,14 +243,20 @@ impl Hub { } else { for f_ in release.assets.iter() { if f_.name.as_str() == file_name_ { - pack = pack.with_url(&f_.browser_download_url).with_tag(tag_).with_file_name(file_name_).with_file_size(f_.size); + pack = pack + .with_url(&f_.browser_download_url) + .with_tag(tag_) + .with_file_name(file_name_) + .with_file_size(f_.size); break; } } } } - self.to.crate_dir_default_with_subs(&[tag_])?.join(file_name_) + self.to + .crate_dir_default_with_subs(&[tag_])? + .join(file_name_) } } _ => anyhow::bail!( @@ -265,7 +272,8 @@ impl Hub { if saveout.is_file() { match pack.file_size { None => { - log::warn!("Failed to retrieve the remote file size. \ + log::warn!( + "Failed to retrieve the remote file size. \ Download will be skipped, which may cause issues. \ Please verify your network connection or ensure the local file is valid and complete." ); @@ -315,7 +323,8 @@ impl Hub { fn fetch_and_cache_releases(url: &str, cache_path: &Path) -> Result { let response = retry!(3, Self::fetch_get_response(url))?; let body = response - .into_string() + .into_body() + .read_to_string() .context("Failed to read response body")?; // Ensure cache directory exists @@ -392,17 +401,18 @@ impl Hub { ) -> Result<()> { let resp = Self::fetch_get_response(src)?; let ntotal = resp - .header("Content-Length") - .and_then(|s| s.parse::().ok()) + .headers() + .get(http::header::CONTENT_LENGTH) + .and_then(|v| v.to_str().ok()?.parse::().ok()) .context("Content-Length header is missing or invalid")?; let pb = crate::build_progress_bar( ntotal, "Fetching", Some(message.unwrap_or_default()), - "{prefix:.cyan.bold} {msg} |{bar}| ({percent_precise}%, {binary_bytes}/{binary_total_bytes}, {binary_bytes_per_sec})" + "{prefix:.cyan.bold} {msg} |{bar}| ({percent_precise}%, {binary_bytes}/{binary_total_bytes}, {binary_bytes_per_sec})", )?; - let mut reader = resp.into_reader(); + let mut reader = resp.into_body().into_reader(); let mut buffer = [0; 2048]; let mut downloaded_bytes = 0usize; let mut file = std::fs::File::create(&dst) @@ -433,8 +443,12 @@ impl Hub { Ok(()) } - fn fetch_get_response(url: &str) -> anyhow::Result { - let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build(); + fn fetch_get_response(url: &str) -> anyhow::Result> { + let config = ureq::Agent::config_builder() + .proxy(ureq::Proxy::try_from_env()) + .build(); + let agent = ureq::Agent::new_with_config(config); + let response = agent .get(url) .call() diff --git a/src/models/sam/impl.rs b/src/models/sam/impl.rs index d022295..7a76e77 100644 --- a/src/models/sam/impl.rs +++ b/src/models/sam/impl.rs @@ -1,7 +1,7 @@ use aksr::Builder; use anyhow::Result; use ndarray::{s, Axis}; -use rand::prelude::*; +use rand::{prelude::*, rng}; use crate::{ elapsed, Config, DynConf, Engine, Image, Mask, Ops, Polygon, Processor, SamPrompt, Ts, Xs, X, Y, @@ -259,8 +259,8 @@ impl SAM { }; // contours - let mut rng = thread_rng(); - let id = rng.gen_range(0..20); + let mut rng = rng(); + let id = rng.random_range(0..20); let mask = Mask::new(&luma, image_width, image_height)?.with_id(id); if self.find_contours { for polygon in mask.polygons().into_iter() { diff --git a/src/utils/logits_sampler.rs b/src/utils/logits_sampler.rs index 5795834..a95435d 100644 --- a/src/utils/logits_sampler.rs +++ b/src/utils/logits_sampler.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use rand::distributions::{Distribution, WeightedIndex}; +use rand::distr::{weighted::WeightedIndex, Distribution}; #[derive(Debug, Clone)] pub struct LogitsSampler { @@ -76,7 +76,7 @@ impl LogitsSampler { let choices: Vec = candidates.iter().map(|&(idx, _)| idx).collect(); let probs: Vec = candidates.iter().map(|&(_, prob)| prob).collect(); let dist = WeightedIndex::new(probs)?; - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let token_id = choices[dist.sample(&mut rng)]; Ok(token_id as u32) } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e145054..7c33ac0 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -126,11 +126,11 @@ fn format_bytes_internal( } pub fn generate_random_string(length: usize) -> String { - use rand::{distributions::Alphanumeric, thread_rng, Rng}; + use rand::{distr::Alphanumeric, rng, Rng}; if length == 0 { return String::new(); } - let rng = thread_rng(); + let rng = rng(); let mut result = String::with_capacity(length); result.extend(rng.sample_iter(&Alphanumeric).take(length).map(char::from)); result diff --git a/src/viz/color.rs b/src/viz/color.rs index 2bfb70c..e981b43 100644 --- a/src/viz/color.rs +++ b/src/viz/color.rs @@ -165,13 +165,13 @@ impl Color { } pub fn palette_rand(n: usize) -> Vec { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let xs: Vec<(u8, u8, u8)> = (0..n) .map(|_| { ( - rng.gen_range(0..=255), - rng.gen_range(0..=255), - rng.gen_range(0..=255), + rng.random_range(0..=255), + rng.random_range(0..=255), + rng.random_range(0..=255), ) }) .collect();