Skip to content

Commit

Permalink
Use max rather than min to sort managed Pythons (#5205)
Browse files Browse the repository at this point in the history
## Summary

See: #5139 and
#5201 (comment).

## 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`
  • Loading branch information
charliermarsh committed Jul 19, 2024
1 parent 93ba676 commit bb84cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/uv-python/src/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ pub enum Error {

#[derive(Debug, Eq, PartialEq, Clone, Copy, Default, PartialOrd, Ord, Hash)]
pub enum ImplementationName {
GraalPy,
PyPy,
#[default]
CPython,
PyPy,
GraalPy,
}

#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
pub enum LenientImplementationName {
Known(ImplementationName),
Unknown(String),
Known(ImplementationName),
}

impl ImplementationName {
Expand Down
7 changes: 4 additions & 3 deletions crates/uv-python/src/managed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::fmt;
use fs_err as fs;
use itertools::Itertools;
use std::cmp::Reverse;
use std::ffi::OsStr;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -150,14 +151,14 @@ impl ManagedPythonInstallations {
},
Err(err) => Some(Err(err)),
})
.collect::<Result<_, std::io::Error>>()
.collect::<Result<_, io::Error>>()
.map_err(|err| Error::ReadError {
dir: self.root.clone(),
err,
})?;
directories
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => vec![],
Err(err) if err.kind() == io::ErrorKind::NotFound => vec![],
Err(err) => {
return Err(Error::ReadError {
dir: self.root.clone(),
Expand All @@ -174,7 +175,7 @@ impl ManagedPythonInstallations {
})
.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.
Expand Down

0 comments on commit bb84cbb

Please sign in to comment.