mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 12:09:12 +00:00
Make hashes optional (#910)
There is no guarantee that indexes provide hashes at all or the sha256 we support specifically. [PEP 503](https://peps.python.org/pep-0503/#specification): > The URL SHOULD include a hash in the form of a URL fragment with the following syntax: #<hashname>=<hashvalue>, where <hashname> is the lowercase name of the hash function (such as sha256) and <hashvalue> is the hex encoded digest. We instead use the url as input to generate a hash when caching.
This commit is contained in:
parent
9ad19b7e54
commit
5ffbfadf66
8 changed files with 104 additions and 41 deletions
|
@ -85,14 +85,18 @@ impl Yanked {
|
|||
///
|
||||
/// PEP 691 says multiple hashes can be included and the interpretation is left to the client, we
|
||||
/// only support SHA 256 atm.
|
||||
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
|
||||
pub struct Hashes {
|
||||
// TODO(charlie): Hashes should be optional.
|
||||
pub sha256: String,
|
||||
pub sha256: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Hashes {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "sha256:{}", self.sha256)
|
||||
impl Hashes {
|
||||
/// Format as `<algorithm>:<hash>`.
|
||||
///
|
||||
/// Currently limited to SHA256.
|
||||
pub fn to_string(&self) -> Option<String> {
|
||||
self.sha256
|
||||
.as_ref()
|
||||
.map(|sha256| format!("sha256:{sha256}"))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue