[Mod] 再次进行一些格式修改

[Add] 增加对binding和tests的代码质量检查
[Add] 更新README.md
This commit is contained in:
nanoric 2019-01-24 06:17:50 -04:00
parent 21a46198fd
commit 8bb0bb5fbf
15 changed files with 22 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -9,8 +9,9 @@ vnpy 2.0
在提交代码的时候,请遵守以下规则,以提高代码质量:
* 使用[yapf]目前必须使用github上的最新代码```pip install https://github.com/google/yapf/archive/master.zip```)格式化你的代码。对你的每一个文件运行```yapf -i --style .style.yapf <file>```即可。
* 使用[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

1
binding/__init__.py Normal file
View File

@ -0,0 +1 @@
# this file is created only for making pylint work

View File

@ -0,0 +1 @@
# this file is created only for making pylint work

View File

View File

@ -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

View File

@ -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):

View File

@ -0,0 +1 @@
# this file is created only for making pylint work

View File

@ -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()

1
tests/__init__.py Normal file
View File

@ -0,0 +1 @@
# this file is created only for making pylint work

1
tests/trader/__init__.py Normal file
View File

@ -0,0 +1 @@
# this file is created only for making pylint work

View File

@ -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

View File

@ -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:

View File

@ -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.