Use max rather than min to sort managed Pythons (#5205)

## Summary

See: https://github.com/astral-sh/uv/issues/5139 and
https://github.com/astral-sh/uv/pull/5201#discussion_r1683636935.

## Test Plan

Verified that 3.12 was chosen above 3.8 in:

- `cargo run -- python uninstall --all`
- `cargo run -- python install 3.8 3.12`
- `cargo run -- tool run -v httpx`
This commit is contained in:
Charlie Marsh 2024-07-19 08:35:17 -04:00 committed by GitHub
parent 93ba676f2e
commit bb84cbb39d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View file

@ -12,16 +12,16 @@ pub enum Error {
#[derive(Debug, Eq, PartialEq, Clone, Copy, Default, PartialOrd, Ord, Hash)] #[derive(Debug, Eq, PartialEq, Clone, Copy, Default, PartialOrd, Ord, Hash)]
pub enum ImplementationName { pub enum ImplementationName {
GraalPy,
PyPy,
#[default] #[default]
CPython, CPython,
PyPy,
GraalPy,
} }
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)] #[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
pub enum LenientImplementationName { pub enum LenientImplementationName {
Known(ImplementationName),
Unknown(String), Unknown(String),
Known(ImplementationName),
} }
impl ImplementationName { impl ImplementationName {

View file

@ -1,6 +1,7 @@
use core::fmt; use core::fmt;
use fs_err as fs; use fs_err as fs;
use itertools::Itertools; use itertools::Itertools;
use std::cmp::Reverse;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -150,14 +151,14 @@ impl ManagedPythonInstallations {
}, },
Err(err) => Some(Err(err)), Err(err) => Some(Err(err)),
}) })
.collect::<Result<_, std::io::Error>>() .collect::<Result<_, io::Error>>()
.map_err(|err| Error::ReadError { .map_err(|err| Error::ReadError {
dir: self.root.clone(), dir: self.root.clone(),
err, err,
})?; })?;
directories directories
} }
Err(err) if err.kind() == std::io::ErrorKind::NotFound => vec![], Err(err) if err.kind() == io::ErrorKind::NotFound => vec![],
Err(err) => { Err(err) => {
return Err(Error::ReadError { return Err(Error::ReadError {
dir: self.root.clone(), dir: self.root.clone(),
@ -174,7 +175,7 @@ impl ManagedPythonInstallations {
}) })
.ok() .ok()
}) })
.sorted_unstable_by_key(|installation| installation.key().clone())) .sorted_unstable_by_key(|installation| Reverse(installation.key().clone())))
} }
/// Iterate over Python installations that support the current platform. /// Iterate over Python installations that support the current platform.