Skip to content

Commit

Permalink
Remove print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Dec 25, 2024
1 parent e8c45b3 commit 875d4aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
16 changes: 3 additions & 13 deletions src/api/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub enum ApiError {
pub struct ApiBuilder {
endpoint: String,
cache: Cache,
url_template: String,
token: Option<String>,
progress: bool,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})
Expand All @@ -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,
Expand Down Expand Up @@ -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`]
Expand Down
15 changes: 2 additions & 13 deletions src/api/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub enum ApiError {
pub struct ApiBuilder {
endpoint: String,
cache: Cache,
url_template: String,
token: Option<String>,
max_files: usize,
chunk_size: usize,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -237,7 +235,6 @@ impl ApiBuilder {
.build()?;
Ok(Api {
endpoint: self.endpoint,
url_template: self.url_template,
cache: self.cache,
client,
relative_redirect_client,
Expand All @@ -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,
Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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?;

Expand Down

0 comments on commit 875d4aa

Please sign in to comment.