Skip to content

Commit 705b35c

Browse files
harshithvhzanieb
andauthored
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 <[email protected]>
1 parent 60f2ca3 commit 705b35c

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

crates/uv-build-frontend/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ impl SourceBuild {
359359
interpreter.clone(),
360360
uv_virtualenv::Prompt::None,
361361
false,
362-
uv_virtualenv::OnExisting::Remove,
362+
uv_virtualenv::OnExisting::Remove(
363+
uv_virtualenv::RemovalReason::TemporaryEnvironment,
364+
),
363365
false,
364366
false,
365367
false,

crates/uv-tool/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl InstalledTools {
273273
interpreter,
274274
uv_virtualenv::Prompt::None,
275275
false,
276-
uv_virtualenv::OnExisting::Remove,
276+
uv_virtualenv::OnExisting::Remove(uv_virtualenv::RemovalReason::ManagedEnvironment),
277277
false,
278278
false,
279279
false,

crates/uv-virtualenv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use thiserror::Error;
66
use uv_preview::Preview;
77
use uv_python::{Interpreter, PythonEnvironment};
88

9-
pub use virtualenv::{OnExisting, remove_virtualenv};
9+
pub use virtualenv::{OnExisting, RemovalReason, remove_virtualenv};
1010

1111
mod virtualenv;
1212

crates/uv-virtualenv/src/virtualenv.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ pub(crate) fn create(
136136
OnExisting::Allow => {
137137
debug!("Allowing existing {name} due to `--allow-existing`");
138138
}
139-
OnExisting::Remove => {
140-
debug!("Removing existing {name} due to `--clear`");
139+
OnExisting::Remove(reason) => {
140+
debug!("Removing existing {name} ({reason})");
141141
// Before removing the virtual environment, we need to canonicalize the path
142142
// because `Path::metadata` will follow the symlink but we're still operating on
143143
// the unresolved path and will remove the symlink itself.
@@ -634,6 +634,28 @@ pub fn remove_virtualenv(location: &Path) -> Result<(), Error> {
634634
Ok(())
635635
}
636636

637+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
638+
pub enum RemovalReason {
639+
/// The removal was explicitly requested, i.e., with `--clear`.
640+
UserRequest,
641+
/// The environment can be removed because it is considered temporary, e.g., a build
642+
/// environment.
643+
TemporaryEnvironment,
644+
/// The environment can be removed because it is managed by uv, e.g., a project or tool
645+
/// environment.
646+
ManagedEnvironment,
647+
}
648+
649+
impl std::fmt::Display for RemovalReason {
650+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
651+
match self {
652+
Self::UserRequest => f.write_str("requested with `--clear`"),
653+
Self::ManagedEnvironment => f.write_str("environment is managed by uv"),
654+
Self::TemporaryEnvironment => f.write_str("environment is temporary"),
655+
}
656+
}
657+
}
658+
637659
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
638660
pub enum OnExisting {
639661
/// Prompt before removing an existing directory.
@@ -647,15 +669,15 @@ pub enum OnExisting {
647669
/// files in the directory.
648670
Allow,
649671
/// Remove an existing directory.
650-
Remove,
672+
Remove(RemovalReason),
651673
}
652674

653675
impl OnExisting {
654676
pub fn from_args(allow_existing: bool, clear: bool, no_clear: bool) -> Self {
655677
if allow_existing {
656678
Self::Allow
657679
} else if clear {
658-
Self::Remove
680+
Self::Remove(RemovalReason::UserRequest)
659681
} else if no_clear {
660682
Self::Fail
661683
} else {

crates/uv/src/commands/project/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl CachedEnvironment {
187187
interpreter,
188188
uv_virtualenv::Prompt::None,
189189
false,
190-
uv_virtualenv::OnExisting::Remove,
190+
uv_virtualenv::OnExisting::Remove(uv_virtualenv::RemovalReason::TemporaryEnvironment),
191191
true,
192192
false,
193193
false,

crates/uv/src/commands/project/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,9 @@ impl ProjectEnvironment {
13681368
interpreter,
13691369
prompt,
13701370
false,
1371-
uv_virtualenv::OnExisting::Remove,
1371+
uv_virtualenv::OnExisting::Remove(
1372+
uv_virtualenv::RemovalReason::ManagedEnvironment,
1373+
),
13721374
false,
13731375
false,
13741376
upgradeable,
@@ -1408,7 +1410,9 @@ impl ProjectEnvironment {
14081410
interpreter,
14091411
prompt,
14101412
false,
1411-
uv_virtualenv::OnExisting::Remove,
1413+
uv_virtualenv::OnExisting::Remove(
1414+
uv_virtualenv::RemovalReason::ManagedEnvironment,
1415+
),
14121416
false,
14131417
false,
14141418
upgradeable,
@@ -1560,7 +1564,9 @@ impl ScriptEnvironment {
15601564
interpreter,
15611565
prompt,
15621566
false,
1563-
uv_virtualenv::OnExisting::Remove,
1567+
uv_virtualenv::OnExisting::Remove(
1568+
uv_virtualenv::RemovalReason::ManagedEnvironment,
1569+
),
15641570
false,
15651571
false,
15661572
upgradeable,
@@ -1600,7 +1606,9 @@ impl ScriptEnvironment {
16001606
interpreter,
16011607
prompt,
16021608
false,
1603-
uv_virtualenv::OnExisting::Remove,
1609+
uv_virtualenv::OnExisting::Remove(
1610+
uv_virtualenv::RemovalReason::ManagedEnvironment,
1611+
),
16041612
false,
16051613
false,
16061614
upgradeable,

crates/uv/src/commands/project/run.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
481481
interpreter,
482482
uv_virtualenv::Prompt::None,
483483
false,
484-
uv_virtualenv::OnExisting::Remove,
484+
uv_virtualenv::OnExisting::Remove(
485+
uv_virtualenv::RemovalReason::TemporaryEnvironment,
486+
),
485487
false,
486488
false,
487489
false,
@@ -681,7 +683,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
681683
interpreter,
682684
uv_virtualenv::Prompt::None,
683685
false,
684-
uv_virtualenv::OnExisting::Remove,
686+
uv_virtualenv::OnExisting::Remove(
687+
uv_virtualenv::RemovalReason::TemporaryEnvironment,
688+
),
685689
false,
686690
false,
687691
false,
@@ -914,7 +918,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
914918
interpreter,
915919
uv_virtualenv::Prompt::None,
916920
false,
917-
uv_virtualenv::OnExisting::Remove,
921+
uv_virtualenv::OnExisting::Remove(
922+
uv_virtualenv::RemovalReason::TemporaryEnvironment,
923+
),
918924
false,
919925
false,
920926
false,
@@ -1040,7 +1046,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
10401046
base_interpreter.clone(),
10411047
uv_virtualenv::Prompt::None,
10421048
false,
1043-
uv_virtualenv::OnExisting::Remove,
1049+
uv_virtualenv::OnExisting::Remove(
1050+
uv_virtualenv::RemovalReason::TemporaryEnvironment,
1051+
),
10441052
false,
10451053
false,
10461054
false,

0 commit comments

Comments
 (0)