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

feat: add a fixer for deprecating cross platform strategy #3259

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/pdm/cli/commands/fix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse

from pdm.cli.commands.base import BaseCommand
from pdm.cli.commands.fix.fixers import BaseFixer, PackageTypeFixer, ProjectConfigFixer
from pdm.cli.commands.fix.fixers import BaseFixer, LockStrategyFixer, PackageTypeFixer, ProjectConfigFixer
from pdm.exceptions import PdmUsageError
from pdm.project import Project
from pdm.termui import Emoji
Expand Down Expand Up @@ -49,7 +49,7 @@ def check_problems(project: Project, strict: bool = True) -> None:
@staticmethod
def get_fixers(project: Project) -> list[BaseFixer]:
"""Return a list of fixers to check, the order matters"""
return [ProjectConfigFixer(project), PackageTypeFixer(project)]
return [ProjectConfigFixer(project), PackageTypeFixer(project), LockStrategyFixer(project)]

def handle(self, project: Project, options: argparse.Namespace) -> None:
if options.dry_run:
Expand Down
21 changes: 21 additions & 0 deletions src/pdm/cli/commands/fix/fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import re

from pdm.project import Config, Project
from pdm.project.lockfile import FLAG_CROSS_PLATFORM
from pdm.termui import Verbosity
from pdm.utils import parse_version


class BaseFixer(abc.ABC):
Expand Down Expand Up @@ -97,3 +99,22 @@

# Write the updated settings back to the project
self.project.pyproject.write(False)


class LockStrategyFixer(BaseFixer):
identifier = "deprecated-cross-platform"

def get_message(self) -> str:
return "Lock strategy [success]`cross_platform`[/] has been deprecated in favor of lock targets."

Check warning on line 108 in src/pdm/cli/commands/fix/fixers.py

View check run for this annotation

Codecov / codecov/patch

src/pdm/cli/commands/fix/fixers.py#L108

Added line #L108 was not covered by tests

def check(self) -> bool:
lockfile_version = self.project.lockfile.file_version
if not lockfile_version or parse_version(lockfile_version) < parse_version("4.5.0"):
return False
return FLAG_CROSS_PLATFORM in self.project.lockfile.strategy

def fix(self) -> None:
strategies = self.project.lockfile.strategy - {FLAG_CROSS_PLATFORM}
self.project.lockfile._data["metadata"]["strategy"] = sorted(strategies)
self.project.lockfile.write(False)
self.log("Lock strategy [success]`cross_platform` has been removed.", verbosity=Verbosity.DETAIL)

Check warning on line 120 in src/pdm/cli/commands/fix/fixers.py

View check run for this annotation

Codecov / codecov/patch

src/pdm/cli/commands/fix/fixers.py#L117-L120

Added lines #L117 - L120 were not covered by tests
Loading