Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions crates/uv-python/src/windows_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ pub fn remove_orphan_registry_entries(installations: &[ManagedPythonInstallation
// Separate assignment since `keys()` creates a borrow.
let subkeys = match key.keys() {
Ok(subkeys) => subkeys,
Err(err) if err.code() == ERROR_NOT_FOUND => {
return;
}
Err(err) => {
// TODO(konsti): We don't have an installation key here.
warn_user_once!("Failed to list subkeys of HKCU:\\{astral_key}: {err}");
Expand All @@ -281,6 +284,9 @@ pub fn remove_orphan_registry_entries(installations: &[ManagedPythonInstallation
let python_entry = format!("{astral_key}\\{subkey}");
debug!("Removing orphan registry key HKCU:\\{}", python_entry);
if let Err(err) = CURRENT_USER.remove_tree(&python_entry) {
if err.code() == ERROR_NOT_FOUND {
continue;
}
// TODO(konsti): We don't have an installation key here.
warn_user_once!("Failed to remove orphan registry key HKCU:\\{python_entry}: {err}");
}
Expand Down
24 changes: 13 additions & 11 deletions crates/uv/src/commands/python/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ async fn do_uninstall(
return Ok(ExitStatus::Failure);
}

// Remove registry entries first, so we don't have dangling entries between the file removal
// and the registry removal.
let mut errors = vec![];
#[cfg(windows)]
{
uv_python::windows_registry::remove_registry_entry(
&matching_installations,
all,
&mut errors,
);
uv_python::windows_registry::remove_orphan_registry_entries(&installed_installations);
}

// Find and remove all relevant Python executables
let mut uninstalled_executables: FxHashMap<PythonInstallationKey, FxHashSet<PathBuf>> =
FxHashMap::default();
Expand Down Expand Up @@ -201,7 +214,6 @@ async fn do_uninstall(
}

let mut uninstalled = IndexSet::<PythonInstallationKey>::default();
let mut errors = vec![];
while let Some((key, result)) = tasks.next().await {
if let Err(err) = result {
errors.push((key.clone(), anyhow::Error::new(err)));
Expand All @@ -210,16 +222,6 @@ async fn do_uninstall(
}
}

#[cfg(windows)]
{
uv_python::windows_registry::remove_registry_entry(
&matching_installations,
all,
&mut errors,
);
uv_python::windows_registry::remove_orphan_registry_entries(&installed_installations);
}

// Read all existing managed installations and find the highest installed patch
// for each installed minor version. Ensure the minor version link directory
// is still valid.
Expand Down
Loading