diff --git a/.pylintrc b/.pylintrc index c900bb48..7f97f88a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -66,6 +66,7 @@ disable= missing-docstring, unused-argument, no-self-use, + no-member, # dataclass is not well supported by pylint # Enable the message, report, category or checker with the given id(s). You can @@ -159,7 +160,7 @@ class-naming-style=PascalCase # Regular expression matching correct constant names. Overrides const-naming- # style. -const-rgx=^([A-Z][A-Z0-9_]+|[a-z][a-z0-9_]+|__\w+__)$ +const-rgx=^_?([A-Z][A-Z0-9_]+|[a-z][a-z0-9_]+|__\w+__)$ # Minimum line length for functions/classes that require docstrings, shorter diff --git a/.travis.yml b/.travis.yml index 091f336d..5fd6f616 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,5 @@ install: - pip install -r requirements-dev.txt # command to run tests script: - - python tools/ci/check_format.py - - pylint --rcfile=.pylintrc vnpy + - python tools/ci/check_all.py - python tests/test_all.py diff --git a/README.md b/README.md index 73b6e205..98a15033 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,9 @@ vnpy 2.0 在提交代码的时候,请遵守以下规则,以提高代码质量: - * 使用[yapf](目前必须使用github上的最新代码:```pip install https://github.com/google/yapf/archive/master.zip```)格式化你的代码。对你的每一个文件运行```yapf -i --style .style.yapf ```即可。 - * 使用[pylint]检查你的代码,确保没有error和warning。我们使用的pylint规则在项目根目录下。运行```pylint --rcfile=.pylintrc vnpy```即可。 + * 使用[black]格式化你的代码。运行```black .```即可。 + * 使用[pylint]检查你的代码(主要检查命名规则),确保没有error和warning。在项目根目录下运行```pylint vnpy```即可。 + * 使用[flake8]检查你的代码,确保没有error和warning。在项目根目录下运行```flake8```即可。 [yapf]:https://github.com/google/yapf [pylint]:https://github.com/PyCQA/pylint diff --git a/binding/__init__.py b/binding/__init__.py new file mode 100644 index 00000000..838c2d2c --- /dev/null +++ b/binding/__init__.py @@ -0,0 +1 @@ +# this file is created only for making pylint work diff --git a/binding/generator/__init__.py b/binding/generator/__init__.py new file mode 100644 index 00000000..838c2d2c --- /dev/null +++ b/binding/generator/__init__.py @@ -0,0 +1 @@ +# this file is created only for making pylint work diff --git a/binding/generator/autocxxpy/__init__.py b/binding/generator/autocxxpy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/binding/generator/autocxxpy/preprocessor.py b/binding/generator/autocxxpy/preprocessor.py index 4fcca56c..2c8dee90 100644 --- a/binding/generator/autocxxpy/preprocessor.py +++ b/binding/generator/autocxxpy/preprocessor.py @@ -4,7 +4,6 @@ import ast import re from collections import defaultdict from dataclasses import dataclass, field -from enum import Enum from typing import Dict, List, Optional, Set from .cxxparser import ( @@ -18,12 +17,6 @@ from .cxxparser import ( from .type import array_base, base_types, is_array_type -class CallbackType(Enum): - NotCallback = 0 # not a callback - Direct = 1 - Async = 2 - - """ 42 - dec 0b101010 - bin diff --git a/binding/generator/autocxxpy/type.py b/binding/generator/autocxxpy/type.py index eb57d84d..a09f2636 100644 --- a/binding/generator/autocxxpy/type.py +++ b/binding/generator/autocxxpy/type.py @@ -35,11 +35,11 @@ def is_pointer_type(t: str): return "*" in t -_remove_pointer_re = re.compile("[ \t]*\\*[ \t]*") +_REMOVE_POINTER_RE = re.compile("[ \t]*\\*[ \t]*") def pointer_base(t: str): - return _remove_pointer_re.sub("", t) + return _REMOVE_POINTER_RE.sub("", t) def is_reference_type(t: str): diff --git a/binding/tests/__init__.py b/binding/tests/__init__.py new file mode 100644 index 00000000..838c2d2c --- /dev/null +++ b/binding/tests/__init__.py @@ -0,0 +1 @@ +# this file is created only for making pylint work diff --git a/binding/tests/test.py b/binding/tests/test.py index 65eead86..bb3ff46d 100644 --- a/binding/tests/test.py +++ b/binding/tests/test.py @@ -26,6 +26,7 @@ api = CThostFtdcTraderApi.CreateFtdcTraderApi("flow2") print("creating ctp spi") +# pylint: disable=invalid-name class Spi(CThostFtdcTraderSpi): def OnFrontConnected(self) -> None: print("OnFrontConnected!") @@ -64,6 +65,7 @@ class Spi(CThostFtdcTraderSpi): self, pRspInfo: CThostFtdcRspInfoField, nRequestID: int, bIsLast: bool ) -> None: print("OnRspError!") +# pylint: enable=invalid-name spi = Spi() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..838c2d2c --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# this file is created only for making pylint work diff --git a/tests/trader/__init__.py b/tests/trader/__init__.py new file mode 100644 index 00000000..838c2d2c --- /dev/null +++ b/tests/trader/__init__.py @@ -0,0 +1 @@ +# this file is created only for making pylint work diff --git a/tools/check/check_linter.py b/tools/check/check_linter.py index d4dbc7a4..3f59a3a7 100644 --- a/tools/check/check_linter.py +++ b/tools/check/check_linter.py @@ -18,7 +18,7 @@ def check_flake8(): def check_pylint(): passed = True try: - subprocess.check_call(["pylint", "vnpy", "-j", "0"]) + subprocess.check_call(["pylint", "-j", "0", "vnpy", "binding", "tests"]) except subprocess.SubprocessError: passed = False return passed diff --git a/tools/check/utils.py b/tools/check/utils.py index 02548a3c..52152c6c 100644 --- a/tools/check/utils.py +++ b/tools/check/utils.py @@ -1,4 +1,5 @@ import logging +import os from typing import Callable logger = logging.getLogger(__file__) @@ -9,7 +10,10 @@ def check_and_warning(*args, fast_fail: bool = False): for i in args: if isinstance(i, Callable): print(f"check using {i}") - if not 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: diff --git a/vnpy/app/cta_strategy/template.py b/vnpy/app/cta_strategy/template.py index 3dc3624d..1f4e328f 100644 --- a/vnpy/app/cta_strategy/template.py +++ b/vnpy/app/cta_strategy/template.py @@ -192,10 +192,7 @@ class CtaTemplate(ABC): return self.cta_engine.get_engine_type() def load_bar( - self, - days: int, - interval: Interval = Interval.MINUTE, - callback=None, + self, days: int, interval: Interval = Interval.MINUTE, callback=None ): """ Load historical bar data for initializing strategy.