mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 02:40:11 +00:00
Search for all python3.x in PATH (#5148)
Search for all `python3.x` minor versions in PATH, skipping those we already know we can use. For example, let's say `python` and `python3` are Python 3.10. When a user requests `>= 3.11`, we still need to find a `python3.12` in PATH. We do so with a regex matcher. Fixes #4709
This commit is contained in:
parent
36a0ee9822
commit
7beae77283
6 changed files with 167 additions and 15 deletions
|
|
@ -33,6 +33,7 @@ mod python_version;
|
|||
mod target;
|
||||
mod version_files;
|
||||
mod virtualenv;
|
||||
mod which;
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub(crate) fn current_dir() -> Result<std::path::PathBuf, std::io::Error> {
|
||||
|
|
@ -1752,6 +1753,32 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_python_all_minors() -> Result<()> {
|
||||
let mut context = TestContext::new()?;
|
||||
context.add_python_interpreters(&[
|
||||
(true, ImplementationName::CPython, "python", "3.10.0"),
|
||||
(true, ImplementationName::CPython, "python3", "3.10.0"),
|
||||
(true, ImplementationName::CPython, "python3.12", "3.12.0"),
|
||||
])?;
|
||||
|
||||
let python = context.run(|| {
|
||||
find_python_installation(
|
||||
&PythonRequest::parse(">= 3.11"),
|
||||
EnvironmentPreference::Any,
|
||||
PythonPreference::OnlySystem,
|
||||
&context.cache,
|
||||
)
|
||||
})??;
|
||||
assert_eq!(
|
||||
python.interpreter().python_full_version().to_string(),
|
||||
"3.12.0",
|
||||
"We should find matching minor version even if they aren't called `python` or `python3`"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_python_pypy_prefers_executable_with_implementation_name() -> Result<()> {
|
||||
let mut context = TestContext::new()?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue