Skip to content

Commit 909fe7c

Browse files
Split out HTTP(S) (ureq) and image default-formats into features
1 parent c86d18b commit 909fe7c

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ anyhow = { version = "1" }
1616
slsl = { version = "0.0.7", features = ["rayon"], optional = true }
1717
aksr = { version = "0.0.7" }
1818
ab_glyph = { version = "0.2.32" }
19-
image = { version = "0.25" }
20-
imageproc = { version = "0.25" }
19+
image = { version = "0.25", default-features = false, features = ["rayon"] }
20+
imageproc = { version = "0.25", default-features = false, features = ["rayon"] }
2121
ndarray = { version = "0.16.1", features = ["rayon"] }
2222
half = { version = "2.7.1", features = ["bytemuck", "num-traits"] }
2323
indicatif = { version = "0.18" }
@@ -26,7 +26,7 @@ prost = { version = "0.14.1" }
2626
paste = { version = "1.0.15" }
2727
rand = { version = "0.9" }
2828
http = { version = "1.3" }
29-
ureq = { version = "3" }
29+
ureq = { version = "3", optional = true }
3030
serde = { version = "1.0", features = ["derive"] }
3131
serde_json = { version = "1.0" }
3232
rayon = { version = "1.10.0" }
@@ -66,11 +66,12 @@ debug = false
6666

6767

6868
[features]
69-
default = ["ort-download-binaries", "yolo"]
69+
default = ["ort-download-binaries", "yolo", "http", "image-default-formats"]
7070

7171
# Utility features
7272
video = ["dep:video-rs"]
7373
viewer = ["dep:minifb"]
74+
image-default-formats = ["image/default-formats"]
7475

7576
# ONNX Runtime features
7677
ort-download-binaries = ["ort", "ort/download-binaries"]
@@ -102,6 +103,8 @@ tokenizers = ["dep:tokenizers"]
102103

103104
# Hugging Face hub support (for downloading models from Hugging Face)
104105
hf-hub = ["dep:hf-hub"]
106+
# HTTP(S) request support (for downloading models from other sources)
107+
http = ["dep:ureq"]
105108

106109
# SLSL tensor library (used by yolo and clip)
107110
slsl = ["dep:slsl"]

src/core/hub.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct Hub {
6767
/// GitHub repository owner
6868
owner: String,
6969

70-
/// GitHub repository name
70+
/// GitHub repository name
7171
repo: String,
7272

7373
/// Directory to store the downloaded file
@@ -151,6 +151,10 @@ impl Hub {
151151
anyhow::bail!("HF hub support is not enabled. Please enable the 'hf-hub' feature.")
152152
}
153153

154+
pub fn try_fetch(&mut self, s: &str) -> Result<String> {
155+
unimplemented!("'http' feature not enabled, ureq compiled out")
156+
}
157+
154158
/// Attempts to fetch a file from a local path, GitHub release, or Hugging Face repository.
155159
///
156160
/// The `try_fetch` method supports multiple scenarios:
@@ -199,6 +203,7 @@ impl Hub {
199203
/// let temp_hf_path = Hub::default().try_fetch("BAAI/bge-m3/sentencepiece.bpe.model")
200204
/// .expect("Failed to fetch HF file");
201205
/// ```
206+
#[cfg(feature = "http")]
202207
pub fn try_fetch(&mut self, s: &str) -> Result<String> {
203208
#[derive(Default, Debug, aksr::Builder)]
204209
struct Pack {
@@ -405,7 +410,13 @@ impl Hub {
405410
.with_context(|| format!("Failed to convert PathBuf: {:?} to String", saveout))
406411
}
407412

413+
#[cfg(not(feature = "http"))]
414+
fn fetch_and_cache_releases(&self, url: &str, cache_path: &Path) -> Result<String> {
415+
unimplemented!("'http' feature not enabled, ureq compiled out")
416+
}
417+
408418
/// Fetch releases from GitHub and cache them
419+
#[cfg(feature = "http")]
409420
fn fetch_and_cache_releases(&self, url: &str, cache_path: &Path) -> Result<String> {
410421
let response = retry!(self.max_attempts, self.fetch_get_response(url))?;
411422
let body = response
@@ -479,7 +490,18 @@ impl Hub {
479490
Ok(y)
480491
}
481492

493+
#[cfg(not(feature = "http"))]
494+
pub fn download<P: AsRef<Path> + std::fmt::Debug>(
495+
&self,
496+
src: &str,
497+
dst: P,
498+
message: Option<&str>,
499+
) -> Result<()> {
500+
unimplemented!("'http' feature disabled, ureq compiled out")
501+
}
502+
482503
/// Download a file from a github release to a specified path with a progress bar
504+
#[cfg(feature = "http")]
483505
pub fn download<P: AsRef<Path> + std::fmt::Debug>(
484506
&self,
485507
src: &str,
@@ -558,6 +580,7 @@ impl Hub {
558580
Ok(())
559581
}
560582

583+
#[cfg(feature = "http")]
561584
fn fetch_get_response(&self, url: &str) -> anyhow::Result<http::Response<ureq::Body>> {
562585
let config = ureq::Agent::config_builder()
563586
.proxy(ureq::Proxy::try_from_env())

0 commit comments

Comments
 (0)