mirror of https://github.com/astral-sh/uv
fix misleading debug message in uv sync (#15881)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary - Added `RemovableReason` enum to track removal context - Updated `OnExisting::Remove` to include source information - Modified debug message to show appropriate context - Updated all call sites to specify correct removal source fixes: #14734 --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
60f2ca3388
commit
705b35c552
|
|
@ -359,7 +359,9 @@ impl SourceBuild {
|
||||||
interpreter.clone(),
|
interpreter.clone(),
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::TemporaryEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ impl InstalledTools {
|
||||||
interpreter,
|
interpreter,
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(uv_virtualenv::RemovalReason::ManagedEnvironment),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use thiserror::Error;
|
||||||
use uv_preview::Preview;
|
use uv_preview::Preview;
|
||||||
use uv_python::{Interpreter, PythonEnvironment};
|
use uv_python::{Interpreter, PythonEnvironment};
|
||||||
|
|
||||||
pub use virtualenv::{OnExisting, remove_virtualenv};
|
pub use virtualenv::{OnExisting, RemovalReason, remove_virtualenv};
|
||||||
|
|
||||||
mod virtualenv;
|
mod virtualenv;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,8 @@ pub(crate) fn create(
|
||||||
OnExisting::Allow => {
|
OnExisting::Allow => {
|
||||||
debug!("Allowing existing {name} due to `--allow-existing`");
|
debug!("Allowing existing {name} due to `--allow-existing`");
|
||||||
}
|
}
|
||||||
OnExisting::Remove => {
|
OnExisting::Remove(reason) => {
|
||||||
debug!("Removing existing {name} due to `--clear`");
|
debug!("Removing existing {name} ({reason})");
|
||||||
// Before removing the virtual environment, we need to canonicalize the path
|
// Before removing the virtual environment, we need to canonicalize the path
|
||||||
// because `Path::metadata` will follow the symlink but we're still operating on
|
// because `Path::metadata` will follow the symlink but we're still operating on
|
||||||
// the unresolved path and will remove the symlink itself.
|
// the unresolved path and will remove the symlink itself.
|
||||||
|
|
@ -634,6 +634,28 @@ pub fn remove_virtualenv(location: &Path) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
|
pub enum RemovalReason {
|
||||||
|
/// The removal was explicitly requested, i.e., with `--clear`.
|
||||||
|
UserRequest,
|
||||||
|
/// The environment can be removed because it is considered temporary, e.g., a build
|
||||||
|
/// environment.
|
||||||
|
TemporaryEnvironment,
|
||||||
|
/// The environment can be removed because it is managed by uv, e.g., a project or tool
|
||||||
|
/// environment.
|
||||||
|
ManagedEnvironment,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for RemovalReason {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::UserRequest => f.write_str("requested with `--clear`"),
|
||||||
|
Self::ManagedEnvironment => f.write_str("environment is managed by uv"),
|
||||||
|
Self::TemporaryEnvironment => f.write_str("environment is temporary"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||||
pub enum OnExisting {
|
pub enum OnExisting {
|
||||||
/// Prompt before removing an existing directory.
|
/// Prompt before removing an existing directory.
|
||||||
|
|
@ -647,7 +669,7 @@ pub enum OnExisting {
|
||||||
/// files in the directory.
|
/// files in the directory.
|
||||||
Allow,
|
Allow,
|
||||||
/// Remove an existing directory.
|
/// Remove an existing directory.
|
||||||
Remove,
|
Remove(RemovalReason),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OnExisting {
|
impl OnExisting {
|
||||||
|
|
@ -655,7 +677,7 @@ impl OnExisting {
|
||||||
if allow_existing {
|
if allow_existing {
|
||||||
Self::Allow
|
Self::Allow
|
||||||
} else if clear {
|
} else if clear {
|
||||||
Self::Remove
|
Self::Remove(RemovalReason::UserRequest)
|
||||||
} else if no_clear {
|
} else if no_clear {
|
||||||
Self::Fail
|
Self::Fail
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ impl CachedEnvironment {
|
||||||
interpreter,
|
interpreter,
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(uv_virtualenv::RemovalReason::TemporaryEnvironment),
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
|
|
@ -1368,7 +1368,9 @@ impl ProjectEnvironment {
|
||||||
interpreter,
|
interpreter,
|
||||||
prompt,
|
prompt,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::ManagedEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
upgradeable,
|
upgradeable,
|
||||||
|
|
@ -1408,7 +1410,9 @@ impl ProjectEnvironment {
|
||||||
interpreter,
|
interpreter,
|
||||||
prompt,
|
prompt,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::ManagedEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
upgradeable,
|
upgradeable,
|
||||||
|
|
@ -1560,7 +1564,9 @@ impl ScriptEnvironment {
|
||||||
interpreter,
|
interpreter,
|
||||||
prompt,
|
prompt,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::ManagedEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
upgradeable,
|
upgradeable,
|
||||||
|
|
@ -1600,7 +1606,9 @@ impl ScriptEnvironment {
|
||||||
interpreter,
|
interpreter,
|
||||||
prompt,
|
prompt,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::ManagedEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
upgradeable,
|
upgradeable,
|
||||||
|
|
|
||||||
|
|
@ -481,7 +481,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
|
||||||
interpreter,
|
interpreter,
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::TemporaryEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
@ -681,7 +683,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
|
||||||
interpreter,
|
interpreter,
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::TemporaryEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
@ -914,7 +918,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
|
||||||
interpreter,
|
interpreter,
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::TemporaryEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
@ -1040,7 +1046,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
|
||||||
base_interpreter.clone(),
|
base_interpreter.clone(),
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
uv_virtualenv::OnExisting::Remove,
|
uv_virtualenv::OnExisting::Remove(
|
||||||
|
uv_virtualenv::RemovalReason::TemporaryEnvironment,
|
||||||
|
),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue