Remove `tool.uv.sources` table if it is empty (#8365)

## Summary

Resolves #8362
This commit is contained in:
Jo 2024-10-19 23:20:45 +08:00 committed by GitHub
parent 4355392c82
commit ca55793a90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View File

@ -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");
}
}
}

View File

@ -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]
"###
);
});