Skip to content

Commit

Permalink
Do not process rev for local or meta hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr committed Jan 20, 2025
1 parent cd98c81 commit 4d54d08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
14 changes: 8 additions & 6 deletions sync_pre_commit_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import ruamel.yaml

REPOS_WITHOUT_REV = frozenset(('local', 'meta'))
SUPPORTED = frozenset(('black', 'flake8', 'mypy'))


Expand Down Expand Up @@ -53,12 +54,13 @@ def main(argv: Sequence[str] | None = None) -> int:
# TODO - validate schema?
versions = {}
for repo in loaded['repos']:
for hook in repo['hooks']:
if (hid := hook['id']) in SUPPORTED:
# `mirrors-mypy` uses versions with a 'v' prefix, so we have to
# strip it out to get the mypy version.
cleaned_rev = repo['rev'].removeprefix('v')
versions[hid] = cleaned_rev
if repo['repo'] not in REPOS_WITHOUT_REV:
for hook in repo['hooks']:
if (hid := hook['id']) in SUPPORTED:
# `mirrors-mypy` uses versions with a 'v' prefix, so we have to
# strip it out to get the mypy version.
cleaned_rev = repo['rev'].removeprefix('v')
versions[hid] = cleaned_rev

updated = []
for repo in loaded['repos']:
Expand Down
49 changes: 35 additions & 14 deletions tests/sync_pre_commit_deps_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
from __future__ import annotations

import pytest

from sync_pre_commit_deps import main


def test_main_noop(tmpdir):
s = (
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n'
)
@pytest.mark.parametrize(
('s',),
(
pytest.param(
'repos:\n'
'- repo: https://github.com/psf/black\n'
' rev: 23.3.0\n'
' hooks:\n'
' - id: black\n'
'- repo: https://github.com/adamchainz/blacken-docs\n'
' rev: 1.15.0\n'
' hooks:\n'
' - id: blacken-docs\n'
' additional_dependencies:\n'
' - black==23.3.0\n',
id='already correct version',
),
pytest.param(
'repos:\n'
'- repo: local\n'
' hooks:\n'
' - id: mypy\n'
'- repo: https://github.com/nbQA-dev/nbQA\n'
' rev: 1.9.1\n'
' hooks:\n'
' - id: nbqa-mypy\n'
' additional_dependencies:\n'
' - mypy==0.123\n',
id='local hook shadows supported lib',
),
),
)
def test_main_noop(tmpdir, s):
cfg = tmpdir.join('.pre-commit-config.yaml')
cfg.write(s)

Expand Down

0 comments on commit 4d54d08

Please sign in to comment.