uv_installer/
uninstall.rs

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