Skip to content

Commit 909a515

Browse files
authored
Sync pre-commit deps with other pre-commit libraries (#7)
1 parent be0d4b7 commit 909a515

File tree

4 files changed

+139
-173
lines changed

4 files changed

+139
-173
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.4.0
44
hooks:
5-
- id: check-docstring-first
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
67
- id: check-yaml
78
- id: debug-statements
8-
- id: end-of-file-fixer
9+
- id: double-quote-string-fixer
910
- id: name-tests-test
1011
- id: requirements-txt-fixer
11-
- id: trailing-whitespace
12-
- repo: https://github.com/mxr/sync-pre-commit-deps
13-
rev: v0.0.1
14-
hooks:
15-
- id: sync-pre-commit-deps
1612
- repo: https://github.com/asottile/setup-cfg-fmt
1713
rev: v2.4.0
1814
hooks:
@@ -23,44 +19,23 @@ repos:
2319
hooks:
2420
- id: reorder-python-imports
2521
args: [--py38-plus, --add-import, 'from __future__ import annotations']
22+
- repo: https://github.com/asottile/add-trailing-comma
23+
rev: v3.0.1
24+
hooks:
25+
- id: add-trailing-comma
2626
- repo: https://github.com/asottile/pyupgrade
2727
rev: v3.10.1
2828
hooks:
2929
- id: pyupgrade
3030
args: [--py38-plus]
31-
- repo: https://github.com/hakancelikdev/unimport
32-
rev: 1.0.0
33-
hooks:
34-
- id: unimport
35-
- repo: https://github.com/mxr/unkey
36-
rev: v0.0.1
31+
- repo: https://github.com/pre-commit/mirrors-autopep8
32+
rev: v2.0.2
3733
hooks:
38-
- id: unkey
39-
- repo: https://github.com/psf/black
40-
rev: 23.7.0
41-
hooks:
42-
- id: black
34+
- id: autopep8
4335
- repo: https://github.com/PyCQA/flake8
4436
rev: 6.1.0
4537
hooks:
4638
- id: flake8
47-
additional_dependencies:
48-
- flake8-bugbear==23.7.10
49-
- flake8-builtins==2.1.0
50-
- flake8-comprehensions==3.14.0
51-
- flake8-typing-imports==1.14.0
52-
- flake8_simplify==0.20.0
53-
- repo: https://github.com/asottile/yesqa
54-
rev: v1.5.0
55-
hooks:
56-
- id: yesqa
57-
additional_dependencies:
58-
- flake8==6.1.0
59-
- flake8-bugbear==23.7.10
60-
- flake8-builtins==2.1.0
61-
- flake8-comprehensions==3.14.0
62-
- flake8-typing-imports==1.14.0
63-
- flake8_simplify==0.20.0
6439
- repo: https://github.com/pre-commit/mirrors-mypy
6540
rev: v1.5.1
6641
hooks:

setup.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ universal = True
3232
[coverage:run]
3333
plugins = covdefaults
3434

35-
[flake8]
36-
max-line-length = 88
37-
extend-ignore = E203
38-
min_python_version = 3.8
39-
4035
[mypy]
4136
check_untyped_defs = true
4237
disallow_any_generics = true

sync_pre_commit_deps.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55

66
import ruamel.yaml
77

8-
SUPPORTED = frozenset(
9-
(
10-
"black",
11-
"flake8",
12-
)
13-
)
8+
SUPPORTED = frozenset(('black', 'flake8'))
149

1510

1611
def main(argv: Sequence[str] | None = None) -> int:
1712
parser = argparse.ArgumentParser()
18-
parser.add_argument("filename", default=".pre-commit-config.yaml")
13+
parser.add_argument('filename', default='.pre-commit-config.yaml')
1914

2015
args = parser.parse_args(argv)
2116
filename: str = args.filename
@@ -31,32 +26,33 @@ def main(argv: Sequence[str] | None = None) -> int:
3126

3227
# TODO - validate schema?
3328
versions = {}
34-
for repo in loaded["repos"]:
35-
for hook in repo["hooks"]:
36-
if (hid := hook["id"]) in SUPPORTED:
37-
versions[hid] = repo["rev"]
29+
for repo in loaded['repos']:
30+
for hook in repo['hooks']:
31+
if (hid := hook['id']) in SUPPORTED:
32+
versions[hid] = repo['rev']
3833

3934
updated = []
40-
for repo in loaded["repos"]:
41-
for hook in repo["hooks"]:
42-
for i, dep in enumerate(hook.get("additional_dependencies", ())):
43-
name, _, cur_version = dep.partition("==")
35+
for repo in loaded['repos']:
36+
for hook in repo['hooks']:
37+
for i, dep in enumerate(hook.get('additional_dependencies', ())):
38+
name, _, cur_version = dep.partition('==')
4439
target_version = versions.get(name, cur_version)
4540
if target_version != cur_version:
46-
hook["additional_dependencies"][i] = f"{name}=={target_version}"
47-
updated.append((hook["id"], name))
41+
name_and_version = f'{name}=={target_version}'
42+
hook['additional_dependencies'][i] = name_and_version
43+
updated.append((hook['id'], name))
4844

4945
if updated:
50-
print(f"Writing updates to {filename}:")
46+
print(f'Writing updates to {filename}:')
5147
for hid, name in updated:
52-
print(f"\tSetting {hid!r} dependency {name!r} to {versions[name]}")
48+
print(f'\tSetting {hid!r} dependency {name!r} to {versions[name]}')
5349

54-
with open(filename, "w+") as f:
50+
with open(filename, 'w+') as f:
5551
yaml.dump(loaded, f)
5652
return 1
5753

5854
return 0
5955

6056

61-
if __name__ == "__main__":
57+
if __name__ == '__main__':
6258
raise SystemExit(main())

0 commit comments

Comments
 (0)