[Mod] 修正ci脚本
This commit is contained in:
parent
45ae431d83
commit
c2637b9fea
@ -33,8 +33,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ggdb")
|
||||
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP /bigobj")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ob2 /Ot /Oi /MT /GL /MP")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc /MP /bigobj")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /EHsc /Ox /Ob2 /Ot /Oi /MT /GL /MP")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
|
||||
|
||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||
|
@ -1,2 +1,3 @@
|
||||
pylint
|
||||
https://github.com/google/yapf/archive/master.zip
|
||||
black
|
||||
flake8
|
||||
|
@ -1,51 +0,0 @@
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from tools.check.utils import check_and_warning
|
||||
|
||||
logger = logging.Logger(__file__)
|
||||
|
||||
|
||||
def check_by_yapf():
|
||||
from yapf.yapflib.yapf_api import FormatFile
|
||||
|
||||
passed = True
|
||||
for root, dir, filenames in os.walk("vnpy"):
|
||||
for filename in filenames:
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if ext == ".py":
|
||||
path = os.path.join(root, filename)
|
||||
reformatted_code, encoding, changed = FormatFile(
|
||||
filename=path,
|
||||
style_config=".style.yapf",
|
||||
print_diff=True,
|
||||
verify=False,
|
||||
in_place=False,
|
||||
logger=None,
|
||||
)
|
||||
if changed:
|
||||
passed = False
|
||||
logger.warning("File {} not formatted!".format(path))
|
||||
else:
|
||||
logger.info("File {} is formatted!".format(path))
|
||||
return passed
|
||||
|
||||
|
||||
def check_black():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(["black", "--check", "./"])
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_format():
|
||||
return check_and_warning(check_black)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not check_format():
|
||||
exit(1)
|
||||
exit(0)
|
@ -1,36 +0,0 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from tools.check.utils import check_and_warning
|
||||
|
||||
logger = logging.Logger(__file__)
|
||||
|
||||
|
||||
def check_flake8():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(["flake8", "./"])
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_pylint():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(
|
||||
["pylint", "-j", "0", "vnpy", "binding", "tests"]
|
||||
)
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_linter():
|
||||
return check_and_warning(check_pylint, check_flake8)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not check_linter():
|
||||
exit(1)
|
||||
exit(0)
|
@ -1,21 +0,0 @@
|
||||
import logging
|
||||
import os
|
||||
from typing import Callable
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
||||
|
||||
def check_and_warning(*args, fast_fail: bool = False):
|
||||
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
|
@ -1,12 +1,74 @@
|
||||
from tools.check.check_format import check_format
|
||||
from tools.check.check_linter import check_linter
|
||||
from tools.check.utils import check_and_warning
|
||||
"""
|
||||
check code quality for project
|
||||
run this file under project root
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from typing import Callable
|
||||
|
||||
logger = logging.Logger(__file__)
|
||||
|
||||
|
||||
def check_and_warning(*args, fast_fail: bool = False):
|
||||
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_black():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(["python", "-m", "black", "--check", "./"])
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_format():
|
||||
return check_and_warning(check_black)
|
||||
|
||||
|
||||
def check_all():
|
||||
return check_and_warning(check_format, check_linter)
|
||||
|
||||
|
||||
def check_flake8():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(["python", "-m", "flake8", "./"])
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_pylint():
|
||||
passed = True
|
||||
try:
|
||||
subprocess.check_call(
|
||||
["python", "-m", "pylint", "-j", "0", "vnpy", "binding", "tests"]
|
||||
)
|
||||
except subprocess.SubprocessError:
|
||||
passed = False
|
||||
return passed
|
||||
|
||||
|
||||
def check_linter():
|
||||
return check_and_warning(check_pylint, check_flake8)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not check_all():
|
||||
exit(1)
|
||||
|
@ -5,11 +5,11 @@ import subprocess
|
||||
logger = logging.Logger(__file__)
|
||||
|
||||
|
||||
def format_by_black():
|
||||
subprocess.check_call(["black", "vnpy"])
|
||||
def format_black():
|
||||
subprocess.check_call(["python", "-m", "black", "."])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not format_by_black():
|
||||
if not format_black():
|
||||
exit(1)
|
||||
exit(0)
|
||||
|
Loading…
Reference in New Issue
Block a user