forked from pre-commit/pre-commit.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_all_hooks.py
33 lines (25 loc) · 984 Bytes
/
make_all_hooks.py
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
import collections
import json
import multiprocessing
import os.path
import subprocess
import tempfile
import aspy.yaml
from pre_commit.clientlib import load_manifest
def get_manifest(repo_path):
print(f'*** {repo_path}')
with tempfile.TemporaryDirectory() as directory:
repo_dir = os.path.join(directory, 'repo')
subprocess.call(('git', 'clone', '-q', repo_path, repo_dir))
manifest_path = os.path.join(repo_dir, '.pre-commit-hooks.yaml')
# Validate the manifest just to make sure it's ok.
load_manifest(manifest_path)
return (repo_path, aspy.yaml.ordered_load(open(manifest_path)))
def main():
repos = aspy.yaml.ordered_load(open('all-repos.yaml'))
pool = multiprocessing.Pool(4)
hooks_json = collections.OrderedDict(pool.map(get_manifest, repos))
with open('all-hooks.json', 'w') as hooks_json_file:
json.dump(hooks_json, hooks_json_file, indent=4)
if __name__ == '__main__':
exit(main())