forked from praw-dev/praw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_push.py
executable file
·50 lines (39 loc) · 1.23 KB
/
pre_push.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""Run static analysis on the project."""
from shutil import rmtree
from subprocess import CalledProcessError, check_call
from tempfile import mkdtemp
import sys
def do_process(*args):
"""Run program provided by args.
Return True on success.
Output failed message on non-zero exit and return False.
Exit if command is not found.
"""
print('Running: {}'.format(' '.join(args)))
try:
check_call(args)
except CalledProcessError:
print('\nFailed: {}'.format(' '.join(args)))
return False
except Exception as exc:
sys.stderr.write(str(exc) + '\n')
sys.exit(1)
return True
def main():
"""Entry point to pre_push.py."""
success = True
success &= do_process('flake8', '--exclude=.eggs,docs,.tox')
success &= do_process('pydocstyle', 'praw')
success &= do_process('pylint', '--rcfile=.pylintrc', 'praw')
tmp_dir = mkdtemp()
try:
success &= do_process('sphinx-build', '-W', 'docs', tmp_dir)
finally:
rmtree(tmp_dir)
return 0 if success else 1
if __name__ == '__main__':
exit_code = main()
print()
print('pre_push.py: Success!' if exit_code == 0 else 'pre_push.py: Fail')
sys.exit(exit_code)