Add requires-python to uv init (#5322)
## Summary Prefers, in order: - The major-minor version of an interpreter discovered via `--python`. - The `requires-python` from the workspace. - The major-minor version of the default interpreter. If the `--python` request is a version or a version range, we use that without fetching an interpreter. Closes https://github.com/astral-sh/uv/issues/5299.
This commit is contained in:
@@ -49,6 +49,21 @@ impl RequiresPython {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a [`RequiresPython`] from a version specifier.
|
||||
pub fn from_specifiers(specifiers: &VersionSpecifiers) -> Result<Self, RequiresPythonError> {
|
||||
let bound = RequiresPythonBound(
|
||||
crate::pubgrub::PubGrubSpecifier::from_release_specifiers(specifiers)?
|
||||
.iter()
|
||||
.next()
|
||||
.map(|(lower, _)| lower.clone())
|
||||
.unwrap_or(Bound::Unbounded),
|
||||
);
|
||||
Ok(Self {
|
||||
specifiers: specifiers.clone(),
|
||||
bound,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a [`RequiresPython`] to express the union of the given version specifiers.
|
||||
///
|
||||
/// For example, given `>=3.8` and `>=3.9`, this would return `>=3.8`.
|
||||
|
||||
Reference in New Issue
Block a user