Refactor distribution types to return Result (#470)

## Summary

A variety of small refactors to the distribution types crate to (1)
return `Result` if we find an invalid wheel, rather than treating it as
a source distribution with a `.whl` suffix, and (2) DRY up some repeated
code around URLs.
This commit is contained in:
Charlie Marsh 2023-11-20 23:08:54 +00:00 committed by GitHub
parent f0841cdb6e
commit f1aa70d9d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 119 additions and 97 deletions

View file

@ -13,6 +13,7 @@ use distribution_filename::WheelFilename;
use distribution_types::direct_url::{DirectArchiveUrl, DirectGitUrl};
use distribution_types::{BuiltDist, Dist, Identifier, Metadata, RemoteSource, SourceDist};
use platform_tags::Tags;
use puffin_cache::metadata::WheelMetadataCache;
use puffin_client::RegistryClient;
use puffin_git::{GitSource, GitUrl};
use puffin_traits::BuildContext;
@ -77,6 +78,13 @@ impl<'a> Fetcher<'a> {
.await?;
Ok(metadata)
}
// Fetch the metadata directly from the wheel URL.
Dist::Built(BuiltDist::DirectUrl(wheel)) => {
let metadata = client
.wheel_metadata_no_pep658(&wheel.filename, &wheel.url, WheelMetadataCache::Url)
.await?;
Ok(metadata)
}
// Fetch the distribution, then read the metadata (for built distributions), or build
// the distribution and _then_ read the metadata (for source distributions).
dist => match self.fetch_dist(dist, client).await? {