Skip to content

Commit 31ac868

Browse files
committed
Do not process rev for local or meta hooks
1 parent cd98c81 commit 31ac868

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

sync_pre_commit_deps.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import ruamel.yaml
77

8+
REPOS_WITHOUT_REV = frozenset(('local', 'meta'))
89
SUPPORTED = frozenset(('black', 'flake8', 'mypy'))
910

1011

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

6365
updated = []
6466
for repo in loaded['repos']:

tests/sync_pre_commit_deps_test.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
from __future__ import annotations
22

3+
import pytest
4+
35
from sync_pre_commit_deps import main
46

57

6-
def test_main_noop(tmpdir):
7-
s = (
8-
'repos:\n'
9-
'- repo: https://github.com/psf/black\n'
10-
' rev: 23.3.0\n'
11-
' hooks:\n'
12-
' - id: black\n'
13-
'- repo: https://github.com/adamchainz/blacken-docs\n'
14-
' rev: 1.15.0\n'
15-
' hooks:\n'
16-
' - id: blacken-docs\n'
17-
' additional_dependencies:\n'
18-
' - black==23.3.0\n'
19-
)
8+
@pytest.mark.parametrize(
9+
('s',),
10+
(
11+
pytest.param(
12+
'repos:\n'
13+
'- repo: https://github.com/psf/black\n'
14+
' rev: 23.3.0\n'
15+
' hooks:\n'
16+
' - id: black\n'
17+
'- repo: https://github.com/adamchainz/blacken-docs\n'
18+
' rev: 1.15.0\n'
19+
' hooks:\n'
20+
' - id: blacken-docs\n'
21+
' additional_dependencies:\n'
22+
' - black==23.3.0\n',
23+
id='already correct version',
24+
),
25+
pytest.param(
26+
'repos:\n'
27+
'- repo: local\n'
28+
' hooks:\n'
29+
' - id: mypy\n'
30+
'- repo: https://github.com/nbQA-dev/nbQA\n'
31+
' rev: 1.9.1\n'
32+
' hooks:\n'
33+
' - id: nbqa-mypy\n'
34+
' additional_dependencies:\n'
35+
' - mypy==0.123\n',
36+
id='local hook shadows supported lib',
37+
),
38+
),
39+
)
40+
def test_main_noop(tmpdir, s):
2041
cfg = tmpdir.join('.pre-commit-config.yaml')
2142
cfg.write(s)
2243

0 commit comments

Comments
 (0)