mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 13:43:45 +00:00
Improve major-minor bounds on requires-python (#8145)
This commit is contained in:
parent
b12d5b619b
commit
346050bf99
2 changed files with 22 additions and 18 deletions
|
@ -553,13 +553,11 @@ impl LowerBound {
|
|||
/// Return the [`LowerBound`] truncated to the major and minor version.
|
||||
fn major_minor(&self) -> Self {
|
||||
match &self.0 {
|
||||
// Ex) `>=3.10.1` -> `>=3.10` (and `>=3.10.0` is `>=3.10`)
|
||||
// Ex) `>=3.10.1` -> `>=3.10`
|
||||
Bound::Included(version) => Self(Bound::Included(Version::new(
|
||||
version.release().iter().take(2),
|
||||
))),
|
||||
// Ex) `>3.10.1` -> `>=3.10`.
|
||||
// This is unintuitive, but `>3.10.1` does indicate that _some_ version of Python 3.10
|
||||
// is supported.
|
||||
Bound::Excluded(version) => Self(Bound::Included(Version::new(
|
||||
version.release().iter().take(2),
|
||||
))),
|
||||
|
@ -668,24 +666,20 @@ impl UpperBound {
|
|||
/// Return the [`UpperBound`] truncated to the major and minor version.
|
||||
fn major_minor(&self) -> Self {
|
||||
match &self.0 {
|
||||
// Ex) `<=3.10.1` -> `<3.11` (but `<=3.10.0` is `<=3.10`)
|
||||
Bound::Included(version) => {
|
||||
let major = version.release().first().copied().unwrap_or(3);
|
||||
let minor = version.release().get(1).copied().unwrap_or(0);
|
||||
if version.release().get(2).is_some_and(|patch| *patch > 0) {
|
||||
Self(Bound::Excluded(Version::new([major, minor + 1])))
|
||||
} else {
|
||||
Self(Bound::Included(Version::new([major, minor])))
|
||||
}
|
||||
}
|
||||
// Ex) `<3.10.1` -> `<3.11` (but `<3.10.0` is `<3.10`)
|
||||
// Ex) `<=3.10.1` -> `<=3.10`
|
||||
Bound::Included(version) => Self(Bound::Included(Version::new(
|
||||
version.release().iter().take(2),
|
||||
))),
|
||||
// Ex) `<3.10.1` -> `<=3.10` (but `<3.10.0` is `<3.10`)
|
||||
Bound::Excluded(version) => {
|
||||
let major = version.release().first().copied().unwrap_or(3);
|
||||
let minor = version.release().get(1).copied().unwrap_or(0);
|
||||
if version.release().get(2).is_some_and(|patch| *patch > 0) {
|
||||
Self(Bound::Excluded(Version::new([major, minor + 1])))
|
||||
Self(Bound::Included(Version::new(
|
||||
version.release().iter().take(2),
|
||||
)))
|
||||
} else {
|
||||
Self(Bound::Excluded(Version::new([major, minor])))
|
||||
Self(Bound::Excluded(Version::new(
|
||||
version.release().iter().take(2),
|
||||
)))
|
||||
}
|
||||
}
|
||||
Bound::Unbounded => Self(Bound::Unbounded),
|
||||
|
|
|
@ -39,6 +39,16 @@ fn requires_python_included() {
|
|||
);
|
||||
}
|
||||
|
||||
let version_specifiers = VersionSpecifiers::from_str("==3.12.6").unwrap();
|
||||
let requires_python = RequiresPython::from_specifiers(&version_specifiers).unwrap();
|
||||
let wheel_names = &["lxml-5.3.0-cp312-cp312-musllinux_1_2_aarch64.whl"];
|
||||
for wheel_name in wheel_names {
|
||||
assert!(
|
||||
requires_python.matches_wheel_tag(&WheelFilename::from_str(wheel_name).unwrap()),
|
||||
"{wheel_name}"
|
||||
);
|
||||
}
|
||||
|
||||
let version_specifiers = VersionSpecifiers::from_str("==3.12").unwrap();
|
||||
let requires_python = RequiresPython::from_specifiers(&version_specifiers).unwrap();
|
||||
let wheel_names = &["lxml-5.3.0-cp312-cp312-musllinux_1_2_x86_64.whl"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue