Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for URL requirements in --generate-hashes #2952

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

charliermarsh
Copy link
Member

Summary

This PR enables hash generation for URL requirements when the user provides --generate-hashes to pip compile. While we include the hashes from the registry already, today, we omit hashes for URLs.

To power hash generation, we introduce a HashPolicy abstraction:

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HashPolicy<'a> {
    /// No hash policy is specified.
    None,
    /// Hashes should be generated (specifically, a SHA-256 hash), but not validated.
    Generate,
    /// Hashes should be validated against a pre-defined list of hashes. If necessary, hashes should
    /// be generated so as to ensure that the archive is valid.
    Validate(&'a [HashDigest]),
}

All of the methods on the distribution database now accept this policy, instead of accepting &'a [HashDigest].

Closes #2378.

@charliermarsh charliermarsh added the enhancement New feature or request label Apr 10, 2024
let metadata = wheel.metadata()?;
let hashes = wheel.hashes;
return Ok(ArchiveMetadata { metadata, hashes });
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worst part of this PR but not 100% sure how to solve. It's fine in practice, just somewhat brittle.

@charliermarsh charliermarsh changed the title Introduce a hash policy abstraction Add support for URL requirements in --generate-hashes Apr 10, 2024
@charliermarsh charliermarsh marked this pull request as ready for review April 10, 2024 01:45
@charliermarsh charliermarsh force-pushed the charlie/generate-hashes-ii branch 2 times, most recently from 446ffd2 to 7c27227 Compare April 10, 2024 02:36
Base automatically changed from charlie/generate-hashes to main April 10, 2024 19:31
@charliermarsh charliermarsh force-pushed the charlie/generate-hashes-ii branch 4 times, most recently from 790480b to dba9cd1 Compare April 10, 2024 19:45
@charliermarsh charliermarsh enabled auto-merge (squash) April 10, 2024 19:53
@charliermarsh charliermarsh merged commit 006379c into main Apr 10, 2024
37 checks passed
@charliermarsh charliermarsh deleted the charlie/generate-hashes-ii branch April 10, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants