Trim injected python_version marker to (major, minor) (#2395)
## Summary Per [PEP 508](https://peps.python.org/pep-0508/), `python_version` is just major and minor:  Right now, we're using the provided version directly, so if it's, e.g., `-p 3.11.8`, we'll inject the wrong marker. This was causing `pandas` to omit `numpy` when `-p 3.11.8` was provided, since its markers look like: ``` Requires-Dist: numpy<2,>=1.22.4; python_version < "3.11" Requires-Dist: numpy<2,>=1.23.2; python_version == "3.11" Requires-Dist: numpy<2,>=1.26.0; python_version >= "3.12" ``` Closes https://github.com/astral-sh/uv/issues/2392.
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
use pep440_rs::Version;
|
||||
use pep508_rs::MarkerEnvironment;
|
||||
use pep508_rs::{MarkerEnvironment, StringVersion};
|
||||
use uv_interpreter::Interpreter;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct PythonRequirement {
|
||||
/// The installed version of Python.
|
||||
installed: Version,
|
||||
installed: StringVersion,
|
||||
/// The target version of Python; that is, the version of Python for which we are resolving
|
||||
/// dependencies. This is typically the same as the installed version, but may be different
|
||||
/// when specifying an alternate Python version for the resolution.
|
||||
target: Version,
|
||||
target: StringVersion,
|
||||
}
|
||||
|
||||
impl PythonRequirement {
|
||||
pub fn new(interpreter: &Interpreter, markers: &MarkerEnvironment) -> Self {
|
||||
Self {
|
||||
installed: interpreter.python_version().clone(),
|
||||
target: markers.python_full_version.version.clone(),
|
||||
installed: interpreter.python_full_version().clone(),
|
||||
target: markers.python_full_version.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the installed version of Python.
|
||||
pub fn installed(&self) -> &Version {
|
||||
pub fn installed(&self) -> &StringVersion {
|
||||
&self.installed
|
||||
}
|
||||
|
||||
/// Return the target version of Python.
|
||||
pub fn target(&self) -> &Version {
|
||||
pub fn target(&self) -> &StringVersion {
|
||||
&self.target
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user