mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 12:59:45 +00:00
## Summary This is an alternative to `--require-hashes` which will validate a hash if it's present, but ignore requirements that omit hashes or are absent from the lockfile entirely. So, e.g., transitive dependencies that are missing will _not_ error; nor will dependencies that are included but lack a hash. Closes https://github.com/astral-sh/uv/issues/3305.
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
#[derive(Debug, Copy, Clone)]
|
|
pub enum HashCheckingMode {
|
|
/// Hashes should be validated against a pre-defined list of hashes. Every requirement must
|
|
/// itself be hashable (e.g., Git dependencies are forbidden) _and_ have a hash in the lockfile.
|
|
Require,
|
|
/// Hashes should be validated, if present, but ignored if absent.
|
|
Verify,
|
|
}
|
|
|
|
impl HashCheckingMode {
|
|
/// Return the [`HashCheckingMode`] from the command-line arguments, if any.
|
|
pub fn from_args(require_hashes: bool, verify_hashes: bool) -> Option<Self> {
|
|
if require_hashes {
|
|
Some(Self::Require)
|
|
} else if verify_hashes {
|
|
Some(Self::Verify)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
/// Returns `true` if the hash checking mode is `Require`.
|
|
pub fn is_require(&self) -> bool {
|
|
matches!(self, Self::Require)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for HashCheckingMode {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Require => write!(f, "--require-hashes"),
|
|
Self::Verify => write!(f, "--verify-hashes"),
|
|
}
|
|
}
|
|
}
|