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
+1 -13
View File
@@ -11,7 +11,7 @@ use thiserror::Error;
use uv_pypi_types::Scheme;
use uv_static::EnvVars;
use crate::{Interpreter, PythonVersion};
use crate::PythonVersion;
/// The layout of a virtual environment.
#[derive(Debug)]
@@ -270,18 +270,6 @@ impl PyVenvConfiguration {
self.include_system_site_packages
}
/// Returns true if the virtual environment has the same `pyvenv.cfg` version
/// as the interpreter Python version. Also returns true if there is no version.
pub fn matches_interpreter(&self, interpreter: &Interpreter) -> bool {
self.version.as_ref().is_none_or(|version| {
interpreter.python_major() == version.major()
&& interpreter.python_minor() == version.minor()
&& version
.patch()
.is_none_or(|patch| patch == interpreter.python_patch())
})
}
/// Set the key-value pair in the `pyvenv.cfg` file.
pub fn set(content: &str, key: &str, value: &str) -> String {
let mut lines = content.lines().map(Cow::Borrowed).collect::<Vec<_>>();