Report Python versions in pyvenv.cfg version mismatch (#13027)

When working on #13025 I noticed this message was lacking versions,
which seems frustrating if you're debugging things.

I refactored the general `matches_interpreter` utilities that were added
in https://github.com/astral-sh/uv/pull/12884 into a more purpose-fit
function that returns an `Option` with the versions if there's a
mismatch.
This commit is contained in:
Zanie Blue
2025-04-25 13:06:46 -05:00
committed by GitHub
parent 8414e9f3dd
commit fb08116800
5 changed files with 43 additions and 27 deletions
+11
View File
@@ -8,6 +8,12 @@ use uv_pep508::{MarkerEnvironment, StringVersion};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PythonVersion(StringVersion);
impl From<StringVersion> for PythonVersion {
fn from(version: StringVersion) -> Self {
Self(version)
}
}
impl Deref for PythonVersion {
type Target = StringVersion;
@@ -176,6 +182,11 @@ impl PythonVersion {
&self.0.version
}
/// Return the full parsed Python version.
pub fn into_version(self) -> Version {
self.0.version
}
/// Return the major version of this Python version.
pub fn major(&self) -> u8 {
u8::try_from(self.0.release().first().copied().unwrap_or(0)).expect("invalid major version")