-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
update-pre-commit
executable file
·65 lines (51 loc) · 1.53 KB
/
update-pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0
"""Synchronizes pre-commit config for Weblate repositories."""
import subprocess
import sys
import ruamel.yaml
yaml = ruamel.yaml.YAML()
yaml.indent = 2
yaml.preserve_quotes = False
yaml.width = sys.maxsize
MDFORMAT_DEPS = [
"mdformat-gfm==0.3.7",
"mdformat-ruff==0.1.3",
"mdformat-shfmt==0.2.0",
"mdformat_tables==1.0.0",
]
with open(sys.argv[1]) as handle:
data = yaml.load(handle)
remove = []
changed = False
for offset, repo in enumerate(data["repos"]):
if repo["repo"] in (
"https://github.com/asottile/pyupgrade",
"https://github.com/psf/black",
"https://github.com/PyCQA/isort",
):
remove.insert(0, offset)
if remove:
for offset in remove:
del data["repos"][offset]
changed = True
for repo in data["repos"]:
if (
repo["repo"] == "https://github.com/astral-sh/ruff-pre-commit"
and len(repo["hooks"]) == 1
):
repo["hooks"].append({"id": "ruff-format"})
changed = True
if repo["repo"] == "https://github.com/executablebooks/mdformat" and len(
repo["hooks"][0]["additional_dependencies"]
) != len(MDFORMAT_DEPS):
repo["hooks"][0]["additional_dependencies"] = MDFORMAT_DEPS
changed = True
if changed:
with open(sys.argv[1], "w") as handle:
yaml.dump(data, handle)
subprocess.run(
["pre-commit", "run", "--files", sys.argv[1]], check=False, capture_output=True
)