From 1bf5eb1d79304bce9c4d4a813f20470ae4411de4 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 6 Mar 2024 17:02:02 +0800 Subject: [PATCH] fix: pdm deletes ``pyproject.toml`` keys it's not authorized to. Fixes #2666 Signed-off-by: Frost Ming --- news/2666.bugfix.md | 1 + src/pdm/project/project_file.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 news/2666.bugfix.md diff --git a/news/2666.bugfix.md b/news/2666.bugfix.md new file mode 100644 index 0000000000..9110b27838 --- /dev/null +++ b/news/2666.bugfix.md @@ -0,0 +1 @@ +Don't modify TOML tables that are not related to PDM. diff --git a/src/pdm/project/project_file.py b/src/pdm/project/project_file.py index 222d97f4c8..a308675bf9 100644 --- a/src/pdm/project/project_file.py +++ b/src/pdm/project/project_file.py @@ -39,7 +39,8 @@ def read(self) -> TOMLDocument: def write(self, show_message: bool = True) -> None: """Write the TOMLDocument to the file.""" - _remove_empty_tables(self._data) + _remove_empty_tables(self._data.get("project", {})) + _remove_empty_tables(self._data.get("tool", {}).get("pdm", {})) super().write() if show_message: self.ui.echo("Changes are written to [success]pyproject.toml[/].", verbosity=termui.Verbosity.NORMAL)