mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Use requires-python
semantics for --universal
(#4701)
## Summary This doesn't actually change any behaviors, but it does make it a bit easier to solve #4669, because we don't have to support "version narrowing" for the non-`RequiresPython` variants in here. Right now, the semantics are kind of muddied, because the `target` variant is _sometimes_ interpreted as an exact version and sometimes as a lower bound.
This commit is contained in:
parent
348efa26ba
commit
f3d1e52e65
5 changed files with 27 additions and 38 deletions
|
@ -1,5 +1,5 @@
|
|||
use pep440_rs::{Operator, Version, VersionSpecifier, VersionSpecifiers};
|
||||
use pep508_rs::{MarkerExpression, MarkerTree, MarkerValueVersion, StringVersion};
|
||||
use pep440_rs::VersionSpecifiers;
|
||||
use pep508_rs::{MarkerTree, StringVersion};
|
||||
use uv_toolchain::{Interpreter, PythonVersion};
|
||||
|
||||
use crate::RequiresPython;
|
||||
|
@ -62,32 +62,12 @@ impl PythonRequirement {
|
|||
/// Return a [`MarkerTree`] representing the Python requirement.
|
||||
///
|
||||
/// See: [`RequiresPython::to_marker_tree`]
|
||||
pub fn to_marker_tree(&self) -> MarkerTree {
|
||||
let version = match &self.target {
|
||||
None => self.installed.version.clone(),
|
||||
Some(PythonTarget::Version(version)) => version.version.clone(),
|
||||
Some(PythonTarget::RequiresPython(requires_python)) => {
|
||||
return requires_python.to_marker_tree()
|
||||
}
|
||||
};
|
||||
|
||||
let version_major_minor_only = Version::new(version.release().iter().take(2));
|
||||
let expr_python_version = MarkerExpression::Version {
|
||||
key: MarkerValueVersion::PythonVersion,
|
||||
specifier: VersionSpecifier::from_version(
|
||||
Operator::GreaterThanEqual,
|
||||
version_major_minor_only,
|
||||
)
|
||||
.unwrap(),
|
||||
};
|
||||
let expr_python_full_version = MarkerExpression::Version {
|
||||
key: MarkerValueVersion::PythonFullVersion,
|
||||
specifier: VersionSpecifier::from_version(Operator::GreaterThanEqual, version).unwrap(),
|
||||
};
|
||||
MarkerTree::And(vec![
|
||||
MarkerTree::Expression(expr_python_version),
|
||||
MarkerTree::Expression(expr_python_full_version),
|
||||
])
|
||||
pub fn to_marker_tree(&self) -> Option<MarkerTree> {
|
||||
if let Some(PythonTarget::RequiresPython(requires_python)) = self.target.as_ref() {
|
||||
Some(requires_python.to_marker_tree())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue