Return computed hashes from metadata requests (#2951)

## Summary

This PR modifies the distribution database to return both the
`Metadata23` and the computed hashes when clients request metadata.

No behavior changes, but this will be necessary to power
`--generate-hashes`.
This commit is contained in:
Charlie Marsh 2024-04-10 15:31:41 -04:00 committed by GitHub
parent c18551fd3c
commit 8513d603b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 100 additions and 60 deletions

View file

@ -100,30 +100,30 @@ impl<'a, Context: BuildContext + Send + Sync> SourceTreeResolver<'a, Context> {
// Fetch the metadata for the distribution.
let metadata = {
let id = PackageId::from_url(source.url());
if let Some(metadata) = self
if let Some(archive) = self
.index
.get_metadata(&id)
.as_deref()
.and_then(|response| {
if let MetadataResponse::Found(metadata) = response {
Some(metadata)
if let MetadataResponse::Found(archive) = response {
Some(archive)
} else {
None
}
})
{
// If the metadata is already in the index, return it.
metadata.clone()
archive.metadata.clone()
} else {
// Run the PEP 517 build process to extract metadata from the source distribution.
let source = BuildableSource::Url(source);
let metadata = self.database.build_wheel_metadata(&source, &[]).await?;
let archive = self.database.build_wheel_metadata(&source, &[]).await?;
// Insert the metadata into the index.
self.index
.insert_metadata(id, MetadataResponse::Found(metadata.clone()));
.insert_metadata(id, MetadataResponse::Found(archive.clone()));
metadata
archive.metadata
}
};