From 4199cb47c5d7e23434c27ec6e60fe3f91bc57f00 Mon Sep 17 00:00:00 2001 From: "Axel H." Date: Tue, 23 Jul 2024 15:32:57 +0200 Subject: [PATCH 1/3] feat(db): add `pdm` and `poetry` --- README.md | 2 ++ src/sync_pre_commit_lock/db.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index af74ee0..8e14f7b 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ Here is the list of default packages supported by this plugin, from [`db.py`](ht - [flakeheaven](https://github.com/flakeheaven/flakeheaven) - [isort](https://github.com/pycqa/isort) - [mypy](https://github.com/pre-commit/mirrors-mypy) +- [pdm](https://github.com/pdm-project/pdm) +- [poetry](https://github.com/python-poetry/poetry) - [pycln](https://github.com/hadialqattan/pycln) - [pyroma](https://github.com/regebro/pyroma) - [pyupgrade](https://github.com/asottile/pyupgrade) diff --git a/src/sync_pre_commit_lock/db.py b/src/sync_pre_commit_lock/db.py index d74bb4f..df8aa03 100644 --- a/src/sync_pre_commit_lock/db.py +++ b/src/sync_pre_commit_lock/db.py @@ -63,6 +63,14 @@ class RepoInfo(TypedDict): "repo": "https://github.com/pre-commit/mirrors-mypy", "rev": "v${rev}", }, + "pdm": { + "repo": "https://github.com/pdm-project/pdm", + "rev": "${rev}", + }, + "poetry": { + "repo": "https://github.com/python-poetry/poetry", + "rev": "${rev}", + }, "pycln": { "repo": "https://github.com/hadialqattan/pycln", "rev": "v${rev}", From f9ad6992975224cfe749b271edcf31234ebc4be5 Mon Sep 17 00:00:00 2001 From: "Axel H." Date: Tue, 23 Jul 2024 15:50:45 +0200 Subject: [PATCH 2/3] feat: resolve `pdm` and `poetry` from the current running instance --- src/sync_pre_commit_lock/pdm_plugin.py | 3 +++ src/sync_pre_commit_lock/poetry_plugin.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/sync_pre_commit_lock/pdm_plugin.py b/src/sync_pre_commit_lock/pdm_plugin.py index a338109..d256acb 100644 --- a/src/sync_pre_commit_lock/pdm_plugin.py +++ b/src/sync_pre_commit_lock/pdm_plugin.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, Union from pdm import termui +from pdm.__version__ import __version__ as pdm_version from pdm.cli.commands.base import BaseCommand from pdm.cli.options import dry_run_option from pdm.signals import post_install, post_lock @@ -142,6 +143,8 @@ def on_pdm_lock_check_pre_commit( for k, v in resolution.items() if (c := select_candidate(v)) and c.name and c.version } + # Adds pdm itself has it won't be part of the resolved dependencies + resolved_packages["pdm"] = GenericLockedPackage("pdm", pdm_version) action = SyncPreCommitHooksVersion( printer=printer, pre_commit_config_file_path=file_path, diff --git a/src/sync_pre_commit_lock/poetry_plugin.py b/src/sync_pre_commit_lock/poetry_plugin.py index 125cd6b..762c000 100644 --- a/src/sync_pre_commit_lock/poetry_plugin.py +++ b/src/sync_pre_commit_lock/poetry_plugin.py @@ -9,6 +9,7 @@ from cleo.exceptions import CleoValueError from cleo.helpers import option from cleo.io.outputs.output import Verbosity +from poetry.__version__ import __version__ as poetry_version from poetry.console.application import Application from poetry.console.commands.add import AddCommand from poetry.console.commands.install import InstallCommand @@ -89,6 +90,8 @@ def run_sync_pre_commit_version(printer: PoetryPrinter, dry_run: bool, applicati locked_packages = {str(p.name): GenericLockedPackage(p.name, str(p.version)) for p in poetry_locked_packages} plugin_config = load_config(application.poetry.pyproject_path) file_path = Path().cwd() / plugin_config.pre_commit_config_file + # Add poetry itself as it won't be part of the resolved dependencies + locked_packages["poetry"] = GenericLockedPackage("poetry", poetry_version) SyncPreCommitHooksVersion( printer, From c7bcb8f4aa51679d183ec10ac31f8ca2e7c6774c Mon Sep 17 00:00:00 2001 From: Gabriel Dugny Date: Thu, 25 Jul 2024 13:07:15 +0200 Subject: [PATCH 3/3] docs: add note in README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8e14f7b..e0d8af2 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,8 @@ Here is the list of default packages supported by this plugin, from [`db.py`](ht - [yamllint](https://github.com/adrienverge/yamllint) +> Note: `pdm` or `poetry` version will be added, from the current instance version, and not from the lockfile. + ## Improvement ideas Feel free to open an issue or a PR if you have any idea, or if you want to help!