Skip to content

Commit

Permalink
Remove tool.uv.sources table if it is empty (astral-sh#8365)
Browse files Browse the repository at this point in the history
## Summary

Resolves astral-sh#8362
  • Loading branch information
j178 authored and MtkN1 committed Oct 21, 2024
1 parent e756e07 commit 7287561
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 14 additions & 0 deletions crates/uv-workspace/src/pyproject_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down
10 changes: 0 additions & 10 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,6 @@ fn add_remove_workspace() -> Result<()> {
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.uv.sources]
"###
);
});
Expand Down Expand Up @@ -2881,8 +2879,6 @@ fn remove_non_normalized_source() -> Result<()> {
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.uv.sources]
"###
);
});
Expand Down Expand Up @@ -4614,8 +4610,6 @@ fn remove_repeated() -> Result<()> {
[tool.uv]
dev-dependencies = ["anyio"]
[tool.uv.sources]
"###
);
});
Expand Down Expand Up @@ -4648,8 +4642,6 @@ fn remove_repeated() -> Result<()> {
[tool.uv]
dev-dependencies = ["anyio"]
[tool.uv.sources]
"###
);
});
Expand Down Expand Up @@ -4685,8 +4677,6 @@ fn remove_repeated() -> Result<()> {
[tool.uv]
dev-dependencies = []
[tool.uv.sources]
"###
);
});
Expand Down

0 comments on commit 7287561

Please sign in to comment.