mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Narrow requires-python
requirement in resolver forks (#4707)
## Summary Given: ```text numpy >=1.26 ; python_version >= '3.9' numpy <1.26 ; python_version < '3.9' ``` When resolving for Python 3.8, we need to narrow the `requires-python` requirement in the top branch of the fork, because `numpy >=1.26` all require Python 3.9 or later -- but we know (in that branch) that we only need to _solve_ for Python 3.9 or later. Closes https://github.com/astral-sh/uv/issues/4669.
This commit is contained in:
parent
89b3324ae1
commit
d9f389a58d
9 changed files with 251 additions and 58 deletions
|
@ -2,7 +2,7 @@ use pep440_rs::VersionSpecifiers;
|
|||
use pep508_rs::{MarkerTree, StringVersion};
|
||||
use uv_toolchain::{Interpreter, PythonVersion};
|
||||
|
||||
use crate::RequiresPython;
|
||||
use crate::{RequiresPython, RequiresPythonBound};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct PythonRequirement {
|
||||
|
@ -49,6 +49,19 @@ impl PythonRequirement {
|
|||
}
|
||||
}
|
||||
|
||||
/// Narrow the [`PythonRequirement`] to the given version, if it's stricter (i.e., greater)
|
||||
/// than the current `Requires-Python` minimum.
|
||||
pub fn narrow(&self, target: &RequiresPythonBound) -> Option<Self> {
|
||||
let Some(PythonTarget::RequiresPython(requires_python)) = self.target.as_ref() else {
|
||||
return None;
|
||||
};
|
||||
let requires_python = requires_python.narrow(target)?;
|
||||
Some(Self {
|
||||
installed: self.installed.clone(),
|
||||
target: Some(PythonTarget::RequiresPython(requires_python)),
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the installed version of Python.
|
||||
pub fn installed(&self) -> &StringVersion {
|
||||
&self.installed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue