forked from vnpy/vnpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.py
54 lines (44 loc) · 1.08 KB
/
check.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
51
52
53
54
"""
Check code quality for vn.py project.
"""
import logging
import os
import subprocess
from typing import Callable
logger = logging.Logger(__file__)
def check_and_warning(*args: list, fast_fail: bool = False):
"""
Run check and show related warning
"""
passed = True
for i in args:
if isinstance(i, Callable):
print(f"check using {i}")
cwd = os.getcwd()
res = i()
os.chdir(cwd)
if not res:
passed = False
logger.warning("check of %s failed!", i)
if not passed and fast_fail:
return False
return passed
def check_flake8():
"""
Check code with flake8.
"""
passed = True
try:
subprocess.check_call(["python", "-m", "flake8", "./"])
except subprocess.SubprocessError:
passed = False
return passed
def check_all():
"""
Run check with all tools (only flake8 for now).
"""
return check_and_warning(check_flake8)
if __name__ == "__main__":
if not check_all():
exit(1)
exit(0)