diff --git a/.pylintrc b/.pylintrc index 0863a73c..ee6f90d4 100644 --- a/.pylintrc +++ b/.pylintrc @@ -3,7 +3,7 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code. -extension-pkg-whitelist=PyQt5, vnctp +extension-pkg-whitelist=PyQt5,vnctp # Add files or directories to the blacklist. They should be base names, not # paths. diff --git a/binding/cmake/flags.cmake b/binding/cmake/flags.cmake index 94f4f3e8..b4b11f77 100644 --- a/binding/cmake/flags.cmake +++ b/binding/cmake/flags.cmake @@ -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) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6325b67f..f0eea09d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ pylint -https://github.com/google/yapf/archive/master.zip +black +flake8 diff --git a/tools/check/__init__.py b/tools/check/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tools/check/check_format.py b/tools/check/check_format.py deleted file mode 100644 index 58f333ef..00000000 --- a/tools/check/check_format.py +++ /dev/null @@ -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) diff --git a/tools/check/check_linter.py b/tools/check/check_linter.py deleted file mode 100644 index f9642f14..00000000 --- a/tools/check/check_linter.py +++ /dev/null @@ -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) diff --git a/tools/check/utils.py b/tools/check/utils.py deleted file mode 100644 index 52152c6c..00000000 --- a/tools/check/utils.py +++ /dev/null @@ -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 diff --git a/tools/ci/check_all.py b/tools/ci/check_all.py index 835f0132..3c986f04 100644 --- a/tools/ci/check_all.py +++ b/tools/ci/check_all.py @@ -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) diff --git a/tools/format_all.py b/tools/format_all.py index 3df06d2c..918b9c5b 100644 --- a/tools/format_all.py +++ b/tools/format_all.py @@ -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)