2019-02-23 08:20:51 +00:00
|
|
|
"""
|
2019-02-23 14:05:01 +00:00
|
|
|
Check code quality for vn.py project.
|
2019-02-23 08:20:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
logger = logging.Logger(__file__)
|
|
|
|
|
|
|
|
|
2019-02-23 14:05:01 +00:00
|
|
|
def check_and_warning(*args: list, fast_fail: bool = False):
|
|
|
|
"""
|
|
|
|
Run check and show related warning
|
|
|
|
"""
|
2019-02-23 08:20:51 +00:00
|
|
|
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():
|
2019-02-23 14:05:01 +00:00
|
|
|
"""
|
|
|
|
Check code with flake8.
|
|
|
|
"""
|
2019-02-23 08:20:51 +00:00
|
|
|
passed = True
|
|
|
|
try:
|
|
|
|
subprocess.check_call(["python", "-m", "flake8", "./"])
|
|
|
|
except subprocess.SubprocessError:
|
|
|
|
passed = False
|
|
|
|
return passed
|
|
|
|
|
|
|
|
|
2019-02-23 14:05:01 +00:00
|
|
|
def check_all():
|
|
|
|
"""
|
|
|
|
Run check with all tools (only flake8 for now).
|
|
|
|
"""
|
|
|
|
return check_and_warning(check_flake8)
|
2019-02-23 08:20:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if not check_all():
|
|
|
|
exit(1)
|
2019-02-23 08:33:11 +00:00
|
|
|
exit(0)
|