Skip to content

Commit fe3faac

Browse files
noirbizarreGabDug
andauthored
feat: support pdm and poetry as dependency or running instance (#33)
* feat(db): add `pdm` and `poetry` * feat: resolve `pdm` and `poetry` from the current running instance * docs: add note in README --------- Co-authored-by: Gabriel Dugny <[email protected]>
1 parent c1a528b commit fe3faac

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ Here is the list of default packages supported by this plugin, from [`db.py`](ht
133133
- [flakeheaven](https://github.com/flakeheaven/flakeheaven)
134134
- [isort](https://github.com/pycqa/isort)
135135
- [mypy](https://github.com/pre-commit/mirrors-mypy)
136+
- [pdm](https://github.com/pdm-project/pdm)
137+
- [poetry](https://github.com/python-poetry/poetry)
136138
- [pycln](https://github.com/hadialqattan/pycln)
137139
- [pyroma](https://github.com/regebro/pyroma)
138140
- [pyupgrade](https://github.com/asottile/pyupgrade)
@@ -141,6 +143,8 @@ Here is the list of default packages supported by this plugin, from [`db.py`](ht
141143
- [yamllint](https://github.com/adrienverge/yamllint)
142144
<!-- END-GENERATED-PACKAGES-LIST -->
143145

146+
> Note: `pdm` or `poetry` version will be added, from the current instance version, and not from the lockfile.
147+
144148
## Improvement ideas
145149

146150
Feel free to open an issue or a PR if you have any idea, or if you want to help!

src/sync_pre_commit_lock/db.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class RepoInfo(TypedDict):
6363
"repo": "https://github.com/pre-commit/mirrors-mypy",
6464
"rev": "v${rev}",
6565
},
66+
"pdm": {
67+
"repo": "https://github.com/pdm-project/pdm",
68+
"rev": "${rev}",
69+
},
70+
"poetry": {
71+
"repo": "https://github.com/python-poetry/poetry",
72+
"rev": "${rev}",
73+
},
6674
"pycln": {
6775
"repo": "https://github.com/hadialqattan/pycln",
6876
"rev": "v${rev}",

src/sync_pre_commit_lock/pdm_plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING, Any, ClassVar, Union
55

66
from pdm import termui
7+
from pdm.__version__ import __version__ as pdm_version
78
from pdm.cli.commands.base import BaseCommand
89
from pdm.cli.options import dry_run_option
910
from pdm.signals import post_install, post_lock
@@ -142,6 +143,8 @@ def on_pdm_lock_check_pre_commit(
142143
for k, v in resolution.items()
143144
if (c := select_candidate(v)) and c.name and c.version
144145
}
146+
# Adds pdm itself has it won't be part of the resolved dependencies
147+
resolved_packages["pdm"] = GenericLockedPackage("pdm", pdm_version)
145148
action = SyncPreCommitHooksVersion(
146149
printer=printer,
147150
pre_commit_config_file_path=file_path,

src/sync_pre_commit_lock/poetry_plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from cleo.exceptions import CleoValueError
1010
from cleo.helpers import option
1111
from cleo.io.outputs.output import Verbosity
12+
from poetry.__version__ import __version__ as poetry_version
1213
from poetry.console.application import Application
1314
from poetry.console.commands.add import AddCommand
1415
from poetry.console.commands.install import InstallCommand
@@ -89,6 +90,8 @@ def run_sync_pre_commit_version(printer: PoetryPrinter, dry_run: bool, applicati
8990
locked_packages = {str(p.name): GenericLockedPackage(p.name, str(p.version)) for p in poetry_locked_packages}
9091
plugin_config = load_config(application.poetry.pyproject_path)
9192
file_path = Path().cwd() / plugin_config.pre_commit_config_file
93+
# Add poetry itself as it won't be part of the resolved dependencies
94+
locked_packages["poetry"] = GenericLockedPackage("poetry", poetry_version)
9295

9396
SyncPreCommitHooksVersion(
9497
printer,

0 commit comments

Comments
 (0)