uv_installer/
uninstall.rs1use uv_distribution_types::{InstalledDist, InstalledDistKind, InstalledEggInfoFile};
2use uv_install_wheel::Layout;
3
4pub async fn uninstall(
6 dist: &InstalledDist,
7 layout: &Layout,
8) -> Result<uv_install_wheel::Uninstall, UninstallError> {
9 let uninstall = tokio::task::spawn_blocking({
10 let dist = dist.clone();
11 let layout = layout.clone();
12 move || match dist.kind {
13 InstalledDistKind::Registry(_) | InstalledDistKind::Url(_) => Ok(
14 uv_install_wheel::uninstall_wheel(dist.install_path(), &dist, &layout)?,
15 ),
16 InstalledDistKind::EggInfoDirectory(_) => {
17 Ok(uv_install_wheel::uninstall_egg(dist.install_path(), &dist)?)
18 }
19 InstalledDistKind::LegacyEditable(dist) => {
20 Ok(uv_install_wheel::uninstall_legacy_editable(&dist.egg_link)?)
21 }
22 InstalledDistKind::EggInfoFile(dist) => Err(UninstallError::Distutils(dist)),
23 }
24 })
25 .await??;
26
27 Ok(uninstall)
28}
29
30#[derive(thiserror::Error, Debug)]
31pub enum UninstallError {
32 #[error(
33 "Unable to uninstall `{0}`. distutils-installed distributions do not include the metadata required to uninstall safely."
34 )]
35 Distutils(InstalledEggInfoFile),
36 #[error(transparent)]
37 Uninstall(#[from] uv_install_wheel::Error),
38 #[error(transparent)]
39 Join(#[from] tokio::task::JoinError),
40}