From 9a34e8127a186f078aede18b2ce8de278fb4c584 Mon Sep 17 00:00:00 2001 From: Wey Gu Date: Sun, 21 Jan 2024 03:22:25 +0000 Subject: [PATCH] fix: packagetype fixer avoid dupl. empty section close: #2577 --- src/pdm/cli/commands/fix/fixers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pdm/cli/commands/fix/fixers.py b/src/pdm/cli/commands/fix/fixers.py index 1f9f03e0b6..18316adaf1 100644 --- a/src/pdm/cli/commands/fix/fixers.py +++ b/src/pdm/cli/commands/fix/fixers.py @@ -83,7 +83,17 @@ def check(self) -> bool: return "package-type" in self.project.pyproject.settings def fix(self) -> None: - package_type = self.project.pyproject.settings.pop("package-type") + # Copy the project settings + settings = self.project.pyproject.settings.copy() + + # Pop the package type and convert it to a distribution type + package_type = settings.pop("package-type") dist = bool(package_type == "library") - self.project.pyproject.settings["distribution"] = dist + settings["distribution"] = dist + + # Update the project settings with the new distribution type + self.project.pyproject._data["tool"].pop("pdm") + self.project.pyproject.settings.update(settings) + + # Write the updated settings back to the project self.project.pyproject.write(False)