Skip to content

Commit

Permalink
fix: some small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager committed Feb 6, 2024
1 parent d5a45fc commit e716df7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
35 changes: 35 additions & 0 deletions crates/rattler_installs_packages/src/index/direct_url/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
use crate::index::http::Http;
use crate::index::package_database::DirectUrlArtifactResponse;
use crate::types::NormalizedPackageName;
use crate::wheel_builder::WheelBuilder;
use url::Url;

pub(crate) mod file;
pub(crate) mod git;
pub(crate) mod http;

/// Get artifact directly from file, vcs, or url
pub(crate) async fn fetch_artifact_and_metadata_by_direct_url<P: Into<NormalizedPackageName>>(
http: &Http,
p: P,
url: Url,
wheel_builder: &WheelBuilder,
) -> miette::Result<DirectUrlArtifactResponse> {
let p = p.into();

let response = if url.scheme() == "file" {
// This can result in a Wheel, Sdist or STree
super::direct_url::file::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else if url.scheme() == "https" {
// This can be a Wheel or SDist artifact
super::direct_url::http::get_artifacts_and_metadata(http, p.clone(), url, wheel_builder)
.await
} else if url.scheme() == "git+https" || url.scheme() == "git+file" {
// This can be a STree artifact
super::direct_url::git::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else {
Err(miette::miette!(
"Usage of insecure protocol or unsupported scheme {:?}",
url.scheme()
))
}?;

Ok(response)
}
41 changes: 8 additions & 33 deletions crates/rattler_installs_packages/src/index/package_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,13 @@ impl PackageDb {
return Ok(cached);
}

let response =
fetch_artifact_and_metadata_by_direct_url(&self.http, p.clone(), url, wheel_builder)
.await?;
let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url(
&self.http,
p.clone(),
url,
wheel_builder,
)
.await?;

self.put_metadata_in_cache(&response.artifact_info, &response.metadata.0)
.await?;
Expand Down Expand Up @@ -474,7 +478,7 @@ impl PackageDb {
artifact_info.filename
)
});
let response = fetch_artifact_and_metadata_by_direct_url(
let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url(
&self.http,
stree_name.distribution.clone(),
artifact_info.url.clone(),
Expand Down Expand Up @@ -626,35 +630,6 @@ impl PackageDb {
}
}

/// Get artifact directly from file, vcs, or url
async fn fetch_artifact_and_metadata_by_direct_url<P: Into<NormalizedPackageName>>(
http: &Http,
p: P,
url: Url,
wheel_builder: &WheelBuilder,
) -> miette::Result<DirectUrlArtifactResponse> {
let p = p.into();

let response = if url.scheme() == "file" {
// This can result in a Wheel, Sdist or STree
super::direct_url::file::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else if url.scheme() == "https" {
// This can be a Wheel or SDist artifact
super::direct_url::http::get_artifacts_and_metadata(http, p.clone(), url, wheel_builder)
.await
} else if url.scheme() == "git+https" || url.scheme() == "git+file" {
// This can be a STree artifact
super::direct_url::git::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else {
Err(miette::miette!(
"Usage of insecure protocol or unsupported scheme {:?}",
url.scheme()
))
}?;

Ok(response)
}

async fn fetch_simple_api(http: &Http, url: Url) -> miette::Result<Option<ProjectInfo>> {
let mut headers = HeaderMap::new();
headers.insert(CACHE_CONTROL, HeaderValue::from_static("max-age=0"));
Expand Down

0 comments on commit e716df7

Please sign in to comment.