Fetch from data-dist-info-metadata when available (#37)

As specified in https://peps.python.org/pep-0658/#specification.
This commit is contained in:
Charlie Marsh 2023-10-07 09:05:29 -04:00 committed by GitHub
parent ae28552b3a
commit 6c31631913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,12 +66,17 @@ impl PypiClient {
/// Fetch the metadata from a wheel file.
pub async fn file(&self, file: File) -> Result<Metadata21, PypiClientError> {
// Send to the proxy.
let url = self.proxy.join(
// Per PEP 658, if `data-dist-info-metadata` is available, we can request it directly;
// otherwise, send to our dedicated caching proxy.
let url = if file.data_dist_info_metadata.is_available() {
Url::parse(&format!("{}.metadata", file.url))?
} else {
self.proxy.join(
file.url
.strip_prefix("https://files.pythonhosted.org/")
.unwrap(),
)?;
)?
};
trace!("fetching file {} from {}", file.filename, url);
@ -155,6 +160,15 @@ pub enum Metadata {
Hashes(Hashes),
}
impl Metadata {
pub fn is_available(&self) -> bool {
match self {
Self::Bool(is_available) => *is_available,
Self::Hashes(_) => true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Yanked {