Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: package-type fixer to avoid duplicated empty section #2578

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2578.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix the package-type fixer won't update toml properly for "Nested Section Ordering Issue in TOML".
16 changes: 13 additions & 3 deletions src/pdm/cli/commands/fix/fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
dist = bool(package_type == "library")
self.project.pyproject.settings["distribution"] = dist
# 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 = package_type == "library"
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)
7 changes: 7 additions & 0 deletions tests/cli/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,10 @@ def test_install_requirement_with_extras(project, pdm, working_set):
pdm(["lock", "-Gsocks"], obj=project, strict=True)
pdm(["sync", "-Gsocks"], obj=project, strict=True)
assert "pysocks" in working_set


def test_fix_package_type_and_update(fixture_project, pdm, working_set):
project = fixture_project("test-package-type-fixer")
pdm(["fix", "project-type"], obj=project, strict=True)
frostming marked this conversation as resolved.
Show resolved Hide resolved
pdm(["update"], obj=project, strict=True)
assert "test-package-type-fixer" in working_set
frostming marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions tests/fixtures/projects/test-package-type-fixer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]

version = "0.0.1"
dependencies = []
name = "test-package-type-fixer"


[tool.pdm.version]
source = "file"
path = "src/test_package_type_fixer/__init__.py"

[tool.pdm]
package-type = "application"

[tool.pdm.dev-dependencies]

dev = [
"black>=23.12.1"
wey-gu marked this conversation as resolved.
Show resolved Hide resolved
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__verson__ = '0.1.0'
Loading