From 875d4aa807c54ca03f40fcbda14e3ac8e49f9545 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Wed, 25 Dec 2024 17:12:58 +0100 Subject: [PATCH] Remove print statements --- src/api/sync.rs | 16 +++------------- src/api/tokio.rs | 15 ++------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/api/sync.rs b/src/api/sync.rs index f7b16fa..43f3c7a 100644 --- a/src/api/sync.rs +++ b/src/api/sync.rs @@ -91,7 +91,6 @@ pub enum ApiError { pub struct ApiBuilder { endpoint: String, cache: Cache, - url_template: String, token: Option, progress: bool, } @@ -125,12 +124,10 @@ impl ApiBuilder { let progress = true; - let endpoint = - std::env::var("HF_ENDPOINT").unwrap_or_else(|_| "https://huggingface.co".to_owned()); + let endpoint = "https://huggingface.co".to_string(); Self { endpoint, - url_template: "{endpoint}/{repo_id}/resolve/{revision}/{filename}".to_string(), cache, token, progress, @@ -187,10 +184,8 @@ impl ApiBuilder { Ok(Api { endpoint: self.endpoint, - url_template: self.url_template, cache: self.cache, client, - no_redirect_client, progress: self.progress, }) @@ -209,7 +204,6 @@ struct Metadata { #[derive(Clone, Debug)] pub struct Api { endpoint: String, - url_template: String, cache: Cache, client: HeaderAgent, no_redirect_client: HeaderAgent, @@ -484,12 +478,8 @@ impl ApiRepo { pub fn url(&self, filename: &str) -> String { let endpoint = &self.api.endpoint; let revision = &self.repo.url_revision(); - self.api - .url_template - .replace("{endpoint}", endpoint) - .replace("{repo_id}", &self.repo.url()) - .replace("{revision}", revision) - .replace("{filename}", filename) + let repo_id = self.repo.url(); + format!("{endpoint}/{repo_id}/resolve/{revision}/{filename}") } /// This will attempt the fetch the file locally first, then [`Api.download`] diff --git a/src/api/tokio.rs b/src/api/tokio.rs index b158448..01c9bdd 100644 --- a/src/api/tokio.rs +++ b/src/api/tokio.rs @@ -107,7 +107,6 @@ pub enum ApiError { pub struct ApiBuilder { endpoint: String, cache: Cache, - url_template: String, token: Option, max_files: usize, chunk_size: usize, @@ -147,7 +146,6 @@ impl ApiBuilder { Self { endpoint: "https://huggingface.co".to_string(), - url_template: "{endpoint}/{repo_id}/resolve/{revision}/{filename}".to_string(), cache, token, max_files: num_cpus::get(), @@ -237,7 +235,6 @@ impl ApiBuilder { .build()?; Ok(Api { endpoint: self.endpoint, - url_template: self.url_template, cache: self.cache, client, relative_redirect_client, @@ -262,7 +259,6 @@ struct Metadata { #[derive(Clone, Debug)] pub struct Api { endpoint: String, - url_template: String, cache: Cache, client: Client, relative_redirect_client: Client, @@ -469,12 +465,8 @@ impl ApiRepo { pub fn url(&self, filename: &str) -> String { let endpoint = &self.api.endpoint; let revision = &self.repo.url_revision(); - self.api - .url_template - .replace("{endpoint}", endpoint) - .replace("{repo_id}", &self.repo.url()) - .replace("{revision}", revision) - .replace("{filename}", filename) + let repo_id = self.repo.url(); + format!("{endpoint}/{repo_id}/resolve/{revision}/{filename}") } async fn download_tempfile<'a, P: Progress + Clone + Send + Sync + 'static>( @@ -551,7 +543,6 @@ impl ApiRepo { stop: usize, ) -> Result<(), ApiError> { // Process each socket concurrently. - println!("Downloading chunk {start}-{stop}"); let range = format!("bytes={start}-{stop}"); let mut file = tokio::fs::OpenOptions::new() .write(true) @@ -651,11 +642,9 @@ impl ApiRepo { std::fs::create_dir_all(blob_path.parent().unwrap())?; progress.init(metadata.size, filename).await; - println!("Init progress"); let tmp_filename = self .download_tempfile(&url, metadata.size, progress) .await?; - println!("Download finished"); tokio::fs::rename(&tmp_filename, &blob_path).await?;