mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Add support for --reinstall
and --reinstall-package
in uv tool install
(#4504)
Adds support for `--reinstall` and `--reinstall-package` to `uv tool install`. These are already available via the installer settings, we just respect them now. `--reinstall` implies a recreation of the environment and reinstallation of the entry points. `--reinstall-package` will only update a subset of the environment. If the target package is the one with the entry points, we'll reinstall the entry points. Otherwise, the entry points are not changed.
This commit is contained in:
parent
747ab0d9f7
commit
b44c47fdab
5 changed files with 221 additions and 42 deletions
|
@ -21,6 +21,7 @@ uv-virtualenv = { workspace = true }
|
|||
uv-toolchain = { workspace = true }
|
||||
install-wheel-rs = { workspace = true }
|
||||
pep440_rs = { workspace = true }
|
||||
uv-cache = { workspace = true }
|
||||
|
||||
thiserror = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::io::{self, Write};
|
|||
use std::path::{Path, PathBuf};
|
||||
use thiserror::Error;
|
||||
use tracing::debug;
|
||||
use uv_cache::Cache;
|
||||
use uv_fs::{LockedFile, Simplified};
|
||||
use uv_toolchain::{Interpreter, PythonEnvironment};
|
||||
|
||||
|
@ -21,9 +22,9 @@ pub enum Error {
|
|||
#[error(transparent)]
|
||||
IO(#[from] io::Error),
|
||||
// TODO(zanieb): Improve the error handling here
|
||||
#[error("Failed to update `tools.toml` at {0}")]
|
||||
#[error("Failed to update `tools.toml` metadata at {0}")]
|
||||
TomlEdit(PathBuf, #[source] tools_toml::Error),
|
||||
#[error("Failed to read `tools.toml` at {0}")]
|
||||
#[error("Failed to read `tools.toml` metadata at {0}")]
|
||||
TomlRead(PathBuf, #[source] Box<toml::de::Error>),
|
||||
#[error(transparent)]
|
||||
VirtualEnvError(#[from] uv_virtualenv::Error),
|
||||
|
@ -33,6 +34,8 @@ pub enum Error {
|
|||
DistInfoMissing(String, PathBuf),
|
||||
#[error("Failed to find a directory for executables")]
|
||||
NoExecutableDirectory,
|
||||
#[error(transparent)]
|
||||
EnvironmentError(#[from] uv_toolchain::Error),
|
||||
}
|
||||
|
||||
/// A collection of uv-managed tools installed on the current system.
|
||||
|
@ -121,16 +124,26 @@ impl InstalledTools {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create_environment(
|
||||
pub fn environment(
|
||||
&self,
|
||||
name: &str,
|
||||
remove_existing: bool,
|
||||
interpreter: Interpreter,
|
||||
cache: &Cache,
|
||||
) -> Result<PythonEnvironment, Error> {
|
||||
let _lock = self.acquire_lock();
|
||||
let environment_path = self.root.join(name);
|
||||
|
||||
if !remove_existing && environment_path.exists() {
|
||||
debug!(
|
||||
"Using existing environment for tool `{name}` at `{}`.",
|
||||
environment_path.user_display()
|
||||
);
|
||||
return Ok(PythonEnvironment::from_root(environment_path, cache)?);
|
||||
}
|
||||
|
||||
debug!(
|
||||
"Creating environment for tool `{name}` at {}.",
|
||||
"Creating environment for tool `{name}` at `{}`.",
|
||||
environment_path.user_display()
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue