Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions tests/test_pre_commit_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading