Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not process rev for local or meta hooks #54

Merged
merged 2 commits into from
Jan 20, 2025
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
13 changes: 7 additions & 6 deletions sync_pre_commit_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,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 ('local', 'meta'):
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
Loading