diff --git a/Cargo.lock b/Cargo.lock index d41cb41fe..dd172cfe9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5966,7 +5966,6 @@ version = "0.0.1" dependencies = [ "fs-err", "pathdiff", - "self-replace", "serde", "thiserror 2.0.12", "toml", diff --git a/crates/uv-tool/Cargo.toml b/crates/uv-tool/Cargo.toml index 210c17c00..f46941f74 100644 --- a/crates/uv-tool/Cargo.toml +++ b/crates/uv-tool/Cargo.toml @@ -39,6 +39,3 @@ thiserror = { workspace = true } toml = { workspace = true } toml_edit = { workspace = true } tracing = { workspace = true } - -[target.'cfg(target_os = "windows")'.dependencies] -self-replace = { workspace = true } diff --git a/crates/uv-tool/src/lib.rs b/crates/uv-tool/src/lib.rs index 902dbf2d0..cf279302a 100644 --- a/crates/uv-tool/src/lib.rs +++ b/crates/uv-tool/src/lib.rs @@ -24,6 +24,7 @@ use uv_installer::SitePackages; use uv_python::{Interpreter, PythonEnvironment}; use uv_state::{StateBucket, StateStore}; use uv_static::EnvVars; +use uv_virtualenv::remove_virtualenv; mod receipt; mod tool; @@ -188,17 +189,7 @@ impl InstalledTools { environment_path.user_display() ); - // On Windows, if the current executable is in the directory, guard against self-deletion. - #[cfg(windows)] - if let Ok(itself) = std::env::current_exe() { - let target = std::path::absolute(&environment_path)?; - if itself.starts_with(&target) { - debug!("Detected self-delete of executable: {}", itself.display()); - self_replace::self_delete_outside_path(&environment_path)?; - } - } - - fs_err::remove_dir_all(environment_path)?; + remove_virtualenv(environment_path.as_path())?; Ok(()) } diff --git a/crates/uv/src/commands/project/mod.rs b/crates/uv/src/commands/project/mod.rs index 15da8c933..f67be45d6 100644 --- a/crates/uv/src/commands/project/mod.rs +++ b/crates/uv/src/commands/project/mod.rs @@ -1578,7 +1578,7 @@ impl ScriptEnvironment { } // Remove the existing virtual environment. - let replaced = match fs_err::remove_dir_all(&root) { + let replaced = match remove_virtualenv(&root) { Ok(()) => { debug!( "Removed virtual environment at: {}", @@ -1586,7 +1586,11 @@ impl ScriptEnvironment { ); true } - Err(err) if err.kind() == std::io::ErrorKind::NotFound => false, + Err(uv_virtualenv::Error::Io(err)) + if err.kind() == std::io::ErrorKind::NotFound => + { + false + } Err(err) => return Err(err.into()), }; diff --git a/crates/uv/src/commands/tool/uninstall.rs b/crates/uv/src/commands/tool/uninstall.rs index c1f8ea8d7..e29e66c86 100644 --- a/crates/uv/src/commands/tool/uninstall.rs +++ b/crates/uv/src/commands/tool/uninstall.rs @@ -110,7 +110,9 @@ async fn do_uninstall( )?; continue; } - Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => { + Err(uv_tool::Error::VirtualEnvError(uv_virtualenv::Error::Io(err))) + if err.kind() == std::io::ErrorKind::NotFound => + { bail!("`{name}` is not installed"); } Err(err) => { @@ -135,7 +137,9 @@ async fn do_uninstall( )?; return Ok(()); } - Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => { + Err(uv_tool::Error::VirtualEnvError(uv_virtualenv::Error::Io(err))) + if err.kind() == std::io::ErrorKind::NotFound => + { bail!("`{name}` is not installed"); } Err(err) => {