From 922bf5a0f0c45ca0d0b37e570926e8fb95fdcdcf Mon Sep 17 00:00:00 2001 From: Gabriel Dugny Date: Tue, 27 Jan 2026 21:51:28 +0100 Subject: [PATCH 1/2] chore: support prek --- README.md | 2 ++ tests/test_pre_commit_config_file.py | 43 ++++++++++++++++++++++++++++ tox.ini | 4 +-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7ff74e..5bb07ec 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ PDM and Poetry plugin to sync your pre-commit versions with your lockfile and au - ⏩ Run every time you run the lockfile is updated, not as a pre-commit hook - 🔄 Install pre-commit hooks automatically, no need to run `pre-commit install` manually - 💫 Preserve your pre-commit config file formatting +- ✨ Support [prek](https://prek.j178.dev/) configuration files (preserve `prek` specific keys) - 🍃 Lightweight, only depends on [strictyaml](https://pypi.org/project/strictyaml/) and [packaging](https://pypi.org/project/packaging/) ## Supported versions @@ -87,6 +88,7 @@ disable-sync-from-lock = false # Packages to ignore when syncing from lock ignore = [] # Name of the pre-commit config file to sync with +# Can be set to ".pre-commit-config.yml" to support prek alternate config file pre-commit-config-file = ".pre-commit-config.yaml" # Additional mapping of URLs to python packages # Default is empty, but will merge with the default mapping diff --git a/tests/test_pre_commit_config_file.py b/tests/test_pre_commit_config_file.py index a4d59bf..50fd877 100644 --- a/tests/test_pre_commit_config_file.py +++ b/tests/test_pre_commit_config_file.py @@ -190,3 +190,46 @@ def test_update_additional_dependencies_versions(base: str) -> None: def test_precommit_repo_equality(repo1: PreCommitRepo, repo2: PreCommitRepo, equal: bool): assert (repo1 == repo2) is equal assert (hash(repo1) == hash(repo2)) is equal + + +def test_prek_config_support() -> None: + # A config file with prek-specific keys + file_content = """\ +minimum_prek_version: "0.1.0" +orphan: true +repos: + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + priority: 10 + env: + FOO: bar +""" + mock_path = MagicMock(spec=Path) + mock_path.open = mock_open(read_data=file_content) + + config = PreCommitHookConfig.from_yaml_file(mock_path) + + updated_repo = PreCommitRepo( + "https://github.com/psf/black", + "23.4.0", + [PreCommitHook("black")], + ) + + mock_path.open = mock_open() + config.update_pre_commit_repo_versions({config.repos[0]: updated_repo}) + + expected_content = """\ +minimum_prek_version: "0.1.0" +orphan: true +repos: + - repo: https://github.com/psf/black + rev: 23.4.0 + hooks: + - id: black + priority: 10 + env: + FOO: bar +""" + mock_path.open().writelines.assert_called_once_with(expected_content.splitlines(keepends=True)) diff --git a/tox.ini b/tox.ini index e9b6a24..d7e0753 100644 --- a/tox.ini +++ b/tox.ini @@ -77,7 +77,7 @@ deps = pdm27: pdm<2.8,>=2.7 pdm28: pdm<2.9,>=2.8 pdm29: pdm<2.10,>=2.9 - pdmHEAD: pdm@ git+https://github.com/pdm-project/pdm.git + pdmHEAD: pdm @ git+https://github.com/pdm-project/pdm.git [testenv:py{314,313,312, 311, 310}-poetry{16, 17, 18, 20, 21, 22, 23,HEAD}] package = editable @@ -90,7 +90,7 @@ deps = poetry21: poetry<2.2,>=2.1 poetry22: poetry<2.3,>=2.2 poetry23: poetry<2.4,>=2.3 - poetryHEAD: poetry@ git+https://github.com/python-poetry/poetry.git + poetryHEAD: poetry @ git+https://github.com/python-poetry/poetry.git [gh] python = From 5ead1fc2c09bfb7a2cc526a284de2efaed57be81 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Feb 2026 12:12:09 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index d7e0753..e9b6a24 100644 --- a/tox.ini +++ b/tox.ini @@ -77,7 +77,7 @@ deps = pdm27: pdm<2.8,>=2.7 pdm28: pdm<2.9,>=2.8 pdm29: pdm<2.10,>=2.9 - pdmHEAD: pdm @ git+https://github.com/pdm-project/pdm.git + pdmHEAD: pdm@ git+https://github.com/pdm-project/pdm.git [testenv:py{314,313,312, 311, 310}-poetry{16, 17, 18, 20, 21, 22, 23,HEAD}] package = editable @@ -90,7 +90,7 @@ deps = poetry21: poetry<2.2,>=2.1 poetry22: poetry<2.3,>=2.2 poetry23: poetry<2.4,>=2.3 - poetryHEAD: poetry @ git+https://github.com/python-poetry/poetry.git + poetryHEAD: poetry@ git+https://github.com/python-poetry/poetry.git [gh] python =