Skip to content

Commit 61c03b8

Browse files
committed
Use reinstall report formatting for uv python install --reinstall
1 parent fa14ea4 commit 61c03b8

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

crates/uv/src/commands/python/install.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) async fn install(
6464
.inspect(|installation| debug!("Found existing installation {}", installation.key()))
6565
.collect();
6666
let mut unfilled_requests = Vec::new();
67-
let mut uninstalled = Vec::new();
67+
let mut uninstalled = BTreeSet::new();
6868
for (request, download_request) in requests.iter().zip(download_requests) {
6969
if matches!(requests.as_slice(), [PythonRequest::Default]) {
7070
writeln!(printer.stderr(), "Searching for Python installations")?;
@@ -91,7 +91,7 @@ pub(crate) async fn install(
9191
}
9292
if reinstall {
9393
fs::remove_dir_all(installation.path())?;
94-
uninstalled.push(installation.key().clone());
94+
uninstalled.insert(installation.key());
9595
unfilled_requests.push(download_request);
9696
}
9797
} else {
@@ -151,7 +151,7 @@ pub(crate) async fn install(
151151
});
152152
}
153153

154-
let mut installed = vec![];
154+
let mut installed = BTreeSet::new();
155155
let mut errors = vec![];
156156
while let Some((key, result)) = tasks.next().await {
157157
match result {
@@ -162,7 +162,7 @@ pub(crate) async fn install(
162162
DownloadResult::Fetched(path) => path,
163163
};
164164

165-
installed.push(key.clone());
165+
installed.insert(key);
166166

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

178178
if !installed.is_empty() {
179-
if let [installed] = installed.as_slice() {
179+
if installed.len() == 1 {
180+
let installed = installed.iter().next().unwrap();
180181
// Ex) "Installed Python 3.9.7 in 1.68s"
181182
writeln!(
182183
printer.stderr(),
@@ -190,29 +191,38 @@ pub(crate) async fn install(
190191
)?;
191192
} else {
192193
// Ex) "Installed 2 versions in 1.68s"
193-
let s = if installed.len() == 1 { "" } else { "s" };
194194
writeln!(
195195
printer.stderr(),
196196
"{}",
197197
format!(
198198
"Installed {} {}",
199-
format!("{} version{s}", installed.len()).bold(),
199+
format!("{} versions", installed.len()).bold(),
200200
format!("in {}", elapsed(start.elapsed())).dimmed()
201201
)
202202
.dimmed()
203203
)?;
204204
}
205205

206+
let reinstalled = uninstalled
207+
.intersection(&installed)
208+
.copied()
209+
.collect::<BTreeSet<_>>();
210+
let uninstalled = uninstalled.difference(&reinstalled).copied();
211+
let installed = installed.difference(&reinstalled).copied();
212+
206213
for event in uninstalled
207-
.into_iter()
208214
.map(|key| ChangeEvent {
209-
key,
215+
key: key.clone(),
210216
kind: ChangeEventKind::Removed,
211217
})
212-
.chain(installed.into_iter().map(|key| ChangeEvent {
213-
key,
218+
.chain(installed.map(|key| ChangeEvent {
219+
key: key.clone(),
214220
kind: ChangeEventKind::Added,
215221
}))
222+
.chain(reinstalled.iter().map(|&key| ChangeEvent {
223+
key: key.clone(),
224+
kind: ChangeEventKind::Reinstalled,
225+
}))
216226
.sorted_unstable_by(|a, b| a.key.cmp(&b.key).then_with(|| a.kind.cmp(&b.kind)))
217227
{
218228
match event.kind {
@@ -222,6 +232,9 @@ pub(crate) async fn install(
222232
ChangeEventKind::Removed => {
223233
writeln!(printer.stderr(), " {} {}", "-".red(), event.key.bold())?;
224234
}
235+
ChangeEventKind::Reinstalled => {
236+
writeln!(printer.stderr(), " {} {}", "~".yellow(), event.key.bold(),)?;
237+
}
225238
}
226239
}
227240
}

crates/uv/src/commands/python/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub(super) enum ChangeEventKind {
1111
Removed,
1212
/// The Python version was installed.
1313
Added,
14+
/// The Python version was reinstalled.
15+
Reinstalled,
1416
}
1517

1618
#[derive(Debug)]

crates/uv/src/commands/python/uninstall.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,10 @@ async fn do_uninstall(
179179
.sorted_unstable_by(|a, b| a.key.cmp(&b.key).then_with(|| a.kind.cmp(&b.kind)))
180180
{
181181
match event.kind {
182-
ChangeEventKind::Added => {
183-
writeln!(printer.stderr(), " {} {}", "+".green(), event.key.bold())?;
184-
}
185182
ChangeEventKind::Removed => {
186183
writeln!(printer.stderr(), " {} {}", "-".red(), event.key.bold())?;
187184
}
185+
_ => unreachable!(),
188186
}
189187
}
190188
}

0 commit comments

Comments
 (0)