-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprecommit.py
More file actions
executable file
·75 lines (58 loc) · 2.23 KB
/
precommit.py
File metadata and controls
executable file
·75 lines (58 loc) · 2.23 KB
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
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""Run precommit checks on the repository."""
import argparse
import os
import pathlib
import subprocess
import sys
def main() -> int:
""""
Main routine
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--overwrite",
help="Overwrite the unformatted source files with the well-formatted code in place. "
"If not set, raise an exception if any of the files do not conform to the style guide.",
action='store_true')
args = parser.parse_args()
overwrite = bool(args.overwrite)
repo_root = pathlib.Path(__file__).parent
print("YAPF'ing...")
if overwrite:
subprocess.check_call(
[
"yapf", "--in-place", "--style=style.yapf", "--recursive", "tests", "sphinx_icontract", "setup.py",
"precommit.py"
],
cwd=str(repo_root))
else:
subprocess.check_call(
[
"yapf", "--diff", "--style=style.yapf", "--recursive", "tests", "sphinx_icontract", "setup.py",
"precommit.py"
],
cwd=str(repo_root))
print("Mypy'ing...")
subprocess.check_call(["mypy", "sphinx_icontract", "tests"], cwd=str(repo_root))
print("Pyicontract-lint'ing...")
subprocess.check_call(["pyicontract-lint", "tests", "sphinx_icontract"], cwd=str(repo_root))
print("Pylint'ing...")
subprocess.check_call(["pylint", "--rcfile=pylint.rc", "tests", "sphinx_icontract"], cwd=str(repo_root))
print("Pydocstyle'ing...")
subprocess.check_call(["pydocstyle", "sphinx_icontract"], cwd=str(repo_root))
print("Testing...")
env = os.environ.copy()
env['ICONTRACT_SLOW'] = 'true'
subprocess.check_call(
["coverage", "run", "--source", "sphinx_icontract", "-m", "unittest", "discover", "tests"],
cwd=str(repo_root),
env=env)
subprocess.check_call(["coverage", "report"])
print("Doctesting...")
subprocess.check_call([sys.executable, "-m", "doctest", str(repo_root / "README.rst")])
for pth in (repo_root / "sphinx_icontract").glob("**/*.py"):
subprocess.check_call([sys.executable, "-m", "doctest", str(pth)])
return 0
if __name__ == "__main__":
sys.exit(main())