mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Track supported Python range in lockfile (#4065)
## Summary This PR adds the `Requires-Python` range to the user's lockfile. This will enable us to validate it when installing. For now, we repeat the `Requires-Python` back to the user; alternatively, though, we could detect the supported Python range automatically. See: https://github.com/astral-sh/uv/issues/4052
This commit is contained in:
parent
8596525d97
commit
642cef0dad
6 changed files with 58 additions and 9 deletions
|
@ -60,13 +60,14 @@ impl PythonRequirement {
|
|||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum RequiresPython {
|
||||
/// The `RequiresPython` specifier is a single version specifier, as provided via
|
||||
/// The [`RequiresPython`] specifier is a single version specifier, as provided via
|
||||
/// `--python-version` on the command line.
|
||||
///
|
||||
/// The use of a separate enum variant allows us to use a verbatim representation when reporting
|
||||
/// back to the user.
|
||||
Specifier(StringVersion),
|
||||
/// The `RequiresPython` specifier is a set of version specifiers.
|
||||
/// The [`RequiresPython`] specifier is a set of version specifiers, as extracted from the
|
||||
/// `Requires-Python` field in a `pyproject.toml` or `METADATA` file.
|
||||
Specifiers(VersionSpecifiers),
|
||||
}
|
||||
|
||||
|
@ -93,6 +94,14 @@ impl RequiresPython {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [`VersionSpecifiers`] for the [`RequiresPython`] specifier.
|
||||
pub fn as_specifiers(&self) -> Option<&VersionSpecifiers> {
|
||||
match self {
|
||||
RequiresPython::Specifier(_) => None,
|
||||
RequiresPython::Specifiers(specifiers) => Some(specifiers),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RequiresPython {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue