From 4b1f6cebb5c88b9bf7d4202a687021b8342a892f Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:14:37 +0800 Subject: [PATCH 1/2] Only remove `[tool.uv.sources]` if it is no long being referenced --- crates/uv-workspace/src/pyproject_mut.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/uv-workspace/src/pyproject_mut.rs b/crates/uv-workspace/src/pyproject_mut.rs index 44aaf7665247..3befdd5ac20e 100644 --- a/crates/uv-workspace/src/pyproject_mut.rs +++ b/crates/uv-workspace/src/pyproject_mut.rs @@ -525,6 +525,11 @@ impl PyProjectTomlMut { /// Remove a matching source from `tool.uv.sources`, if it exists. fn remove_source(&mut self, name: &PackageName) -> Result<(), Error> { + // If the dependency is still in use, don't remove the source. + if !self.find_dependency(name, None).is_empty() { + return Ok(()); + } + if let Some(sources) = self .doc .get_mut("tool") From 7a67f4421e9abe5370ed0412fe0a665ed924cb52 Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:57:53 +0800 Subject: [PATCH 2/2] Fix snapshot --- crates/uv/tests/it/edit.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/uv/tests/it/edit.rs b/crates/uv/tests/it/edit.rs index d82373def784..ffbdf0cc0be0 100644 --- a/crates/uv/tests/it/edit.rs +++ b/crates/uv/tests/it/edit.rs @@ -4584,12 +4584,10 @@ fn remove_repeated() -> Result<()> { ----- stdout ----- ----- stderr ----- - Resolved 4 packages in [TIME] - Prepared 3 packages in [TIME] - Installed 3 packages in [TIME] - + anyio==4.3.0 - + idna==3.6 - + sniffio==1.3.1 + Resolved 2 packages in [TIME] + Prepared 1 package in [TIME] + Installed 1 package in [TIME] + + anyio==4.3.0+foo (from file://[WORKSPACE]/scripts/packages/anyio_local) "###); let pyproject_toml = context.read("pyproject.toml"); @@ -4610,6 +4608,9 @@ fn remove_repeated() -> Result<()> { [tool.uv] dev-dependencies = ["anyio"] + + [tool.uv.sources] + anyio = { path = "[WORKSPACE]/scripts/packages/anyio_local" } "### ); }); @@ -4620,8 +4621,8 @@ fn remove_repeated() -> Result<()> { ----- stdout ----- ----- stderr ----- - Resolved 4 packages in [TIME] - Audited 3 packages in [TIME] + Resolved 2 packages in [TIME] + Audited 1 package in [TIME] "###); let pyproject_toml = context.read("pyproject.toml"); @@ -4642,6 +4643,9 @@ fn remove_repeated() -> Result<()> { [tool.uv] dev-dependencies = ["anyio"] + + [tool.uv.sources] + anyio = { path = "[WORKSPACE]/scripts/packages/anyio_local" } "### ); }); @@ -4653,10 +4657,8 @@ fn remove_repeated() -> Result<()> { ----- stderr ----- Resolved 1 package in [TIME] - Uninstalled 3 packages in [TIME] - - anyio==4.3.0 - - idna==3.6 - - sniffio==1.3.1 + Uninstalled 1 package in [TIME] + - anyio==4.3.0+foo (from file://[WORKSPACE]/scripts/packages/anyio_local) "###); let pyproject_toml = context.read("pyproject.toml");