diff --git a/crates/uv-workspace/src/pyproject_mut.rs b/crates/uv-workspace/src/pyproject_mut.rs index d87a0343d..44aaf7665 100644 --- a/crates/uv-workspace/src/pyproject_mut.rs +++ b/crates/uv-workspace/src/pyproject_mut.rs @@ -539,6 +539,20 @@ impl PyProjectTomlMut { { if let Some(key) = find_source(name, sources) { sources.remove(&key); + + // Remove the `tool.uv.sources` table if it is empty. + if sources.is_empty() { + self.doc + .entry("tool") + .or_insert(implicit()) + .as_table_mut() + .ok_or(Error::MalformedSources)? + .entry("uv") + .or_insert(implicit()) + .as_table_mut() + .ok_or(Error::MalformedSources)? + .remove("sources"); + } } } diff --git a/crates/uv/tests/it/edit.rs b/crates/uv/tests/it/edit.rs index 27a5083c9..d82373def 100644 --- a/crates/uv/tests/it/edit.rs +++ b/crates/uv/tests/it/edit.rs @@ -1688,8 +1688,6 @@ fn add_remove_workspace() -> Result<()> { [build-system] requires = ["setuptools>=42"] build-backend = "setuptools.build_meta" - - [tool.uv.sources] "### ); }); @@ -2881,8 +2879,6 @@ fn remove_non_normalized_source() -> Result<()> { [build-system] requires = ["setuptools>=42"] build-backend = "setuptools.build_meta" - - [tool.uv.sources] "### ); }); @@ -4614,8 +4610,6 @@ fn remove_repeated() -> Result<()> { [tool.uv] dev-dependencies = ["anyio"] - - [tool.uv.sources] "### ); }); @@ -4648,8 +4642,6 @@ fn remove_repeated() -> Result<()> { [tool.uv] dev-dependencies = ["anyio"] - - [tool.uv.sources] "### ); }); @@ -4685,8 +4677,6 @@ fn remove_repeated() -> Result<()> { [tool.uv] dev-dependencies = [] - - [tool.uv.sources] "### ); });