Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reinstall report formatting for uv python install --reinstall #8487

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub enum EnvironmentPreference {
Any,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PythonVariant {
#[default]
Default,
Expand Down
1 change: 1 addition & 0 deletions crates/uv-python/src/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,6 @@ impl Ord for PythonInstallationKey {
.then_with(|| self.os.to_string().cmp(&other.os.to_string()))
.then_with(|| self.arch.to_string().cmp(&other.arch.to_string()))
.then_with(|| self.libc.to_string().cmp(&other.libc.to_string()))
.then_with(|| self.variant.cmp(&other.variant))
}
}
37 changes: 25 additions & 12 deletions crates/uv/src/commands/python/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures::stream::FuturesUnordered;
use futures::StreamExt;
use itertools::Itertools;
use owo_colors::OwoColorize;
use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashSet};
use std::fmt::Write;
use std::path::Path;
use tracing::debug;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub(crate) async fn install(
.inspect(|installation| debug!("Found existing installation {}", installation.key()))
.collect();
let mut unfilled_requests = Vec::new();
let mut uninstalled = Vec::new();
let mut uninstalled = HashSet::new();
for (request, download_request) in requests.iter().zip(download_requests) {
if matches!(requests.as_slice(), [PythonRequest::Default]) {
writeln!(printer.stderr(), "Searching for Python installations")?;
Expand All @@ -91,7 +91,7 @@ pub(crate) async fn install(
}
if reinstall {
fs::remove_dir_all(installation.path())?;
uninstalled.push(installation.key().clone());
uninstalled.insert(installation.key());
unfilled_requests.push(download_request);
}
} else {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub(crate) async fn install(
});
}

let mut installed = vec![];
let mut installed = HashSet::new();
let mut errors = vec![];
while let Some((key, result)) = tasks.next().await {
match result {
Expand All @@ -162,7 +162,7 @@ pub(crate) async fn install(
DownloadResult::Fetched(path) => path,
};

installed.push(key.clone());
installed.insert(key);

// Ensure the installations have externally managed markers
let managed = ManagedPythonInstallation::new(path.clone())?;
Expand All @@ -176,7 +176,8 @@ pub(crate) async fn install(
}

if !installed.is_empty() {
if let [installed] = installed.as_slice() {
if installed.len() == 1 {
let installed = installed.iter().next().unwrap();
// Ex) "Installed Python 3.9.7 in 1.68s"
writeln!(
printer.stderr(),
Expand All @@ -190,29 +191,38 @@ pub(crate) async fn install(
)?;
} else {
// Ex) "Installed 2 versions in 1.68s"
let s = if installed.len() == 1 { "" } else { "s" };
writeln!(
printer.stderr(),
"{}",
format!(
"Installed {} {}",
format!("{} version{s}", installed.len()).bold(),
format!("{} versions", installed.len()).bold(),
format!("in {}", elapsed(start.elapsed())).dimmed()
)
.dimmed()
)?;
}

let reinstalled = uninstalled
.intersection(&installed)
.copied()
.collect::<HashSet<_>>();
let uninstalled = uninstalled.difference(&reinstalled).copied();
let installed = installed.difference(&reinstalled).copied();

for event in uninstalled
.into_iter()
.map(|key| ChangeEvent {
key,
key: key.clone(),
kind: ChangeEventKind::Removed,
})
.chain(installed.into_iter().map(|key| ChangeEvent {
key,
.chain(installed.map(|key| ChangeEvent {
key: key.clone(),
kind: ChangeEventKind::Added,
}))
.chain(reinstalled.iter().map(|&key| ChangeEvent {
key: key.clone(),
kind: ChangeEventKind::Reinstalled,
}))
.sorted_unstable_by(|a, b| a.key.cmp(&b.key).then_with(|| a.kind.cmp(&b.kind)))
{
match event.kind {
Expand All @@ -222,6 +232,9 @@ pub(crate) async fn install(
ChangeEventKind::Removed => {
writeln!(printer.stderr(), " {} {}", "-".red(), event.key.bold())?;
}
ChangeEventKind::Reinstalled => {
writeln!(printer.stderr(), " {} {}", "~".yellow(), event.key.bold(),)?;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub(super) enum ChangeEventKind {
Removed,
/// The Python version was installed.
Added,
/// The Python version was reinstalled.
Reinstalled,
}

#[derive(Debug)]
Expand Down
4 changes: 1 addition & 3 deletions crates/uv/src/commands/python/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ async fn do_uninstall(
.sorted_unstable_by(|a, b| a.key.cmp(&b.key).then_with(|| a.kind.cmp(&b.kind)))
{
match event.kind {
ChangeEventKind::Added => {
writeln!(printer.stderr(), " {} {}", "+".green(), event.key.bold())?;
}
ChangeEventKind::Removed => {
writeln!(printer.stderr(), " {} {}", "-".red(), event.key.bold())?;
}
_ => unreachable!(),
}
}
}
Expand Down
Loading