Skip to content

Commit 895cced

Browse files
authored
fix(pdm): avoid deprecation warning for PDM 2.17+ (#35)
PDM commit changing lock behaviour: pdm-project/pdm@c190e14 MR: pdm-project/pdm#2995
1 parent fe3faac commit 895cced

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sync_pre_commit_lock/pdm_plugin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pdm.cli.hooks import HookManager
2626
from pdm.core import Core
2727
from pdm.models.candidates import Candidate
28+
from pdm.models.repositories.lock import LockedRepository
2829
from pdm.project import Project
2930
from pdm.termui import UI
3031

@@ -164,6 +165,12 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
164165
dry_run_option.add_to_parser(parser)
165166

166167
def handle(self, project: Project, options: argparse.Namespace) -> None:
167-
candidates = project.locked_repository.all_candidates
168+
candidates = self._get_locked_repository(project).all_candidates
168169

169170
on_pdm_lock_check_pre_commit(project, resolution=candidates, dry_run=options.dry_run, with_prefix=False)
171+
172+
def _get_locked_repository(self, project: Project) -> LockedRepository:
173+
# `locked_repository` was deprecated in PDM 2.17 favour of `get_locked_repository`, try to use it first to avoid warning
174+
if hasattr(project, "get_locked_repository"):
175+
return project.get_locked_repository()
176+
return project.locked_repository

0 commit comments

Comments
 (0)