From a897738699716a887c21b1152d433b2eed840dbf Mon Sep 17 00:00:00 2001 From: Yifan Xiong Date: Mon, 1 Feb 2021 14:12:02 +0800 Subject: [PATCH] Setup: Revision - Update lint rules (#7) Update some lint rules, including: * change max line length from 79 to 120, following [pytorch] * add dedent_closing_brackets in yapf * remove typed def requirements in mypy Fix return code bug in setup.py, when lint/test command return 1, `os.system` will return 256 and `sys.exit(256)` will get return code 0. [pytorch]: https://github.com/pytorch/pytorch/blob/d1dcd5f/.flake8#L3 --- .editorconfig | 2 +- .flake8 | 4 +++- .mypy.ini | 3 --- .style.yapf | 2 ++ setup.py | 23 +++++++++++++---------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.editorconfig b/.editorconfig index f4f3fe4d..eec2bdf8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ trim_trailing_whitespace = true insert_final_newline = true [*.py] -max_line_length = 79 +max_line_length = 120 [*.yaml] indent_size = 2 diff --git a/.flake8 b/.flake8 index 9db71b29..43028571 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,8 @@ [flake8] +max-complexity = 10 +max-line-length = 120 +# flake8-docstrings extension inline-quotes = single multiline-quotes = double docstring-quotes = double docstring-convention = google -max-complexity = 10 diff --git a/.mypy.ini b/.mypy.ini index a225426a..e7bced23 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -1,7 +1,4 @@ [mypy] ignore_missing_imports = True scripts_are_modules = True - -[superbench] warn_return_any = True -disallow_untyped_defs = True diff --git a/.style.yapf b/.style.yapf index 04b172bc..cbb028e2 100644 --- a/.style.yapf +++ b/.style.yapf @@ -1,4 +1,6 @@ [style] based_on_style = pep8 +column_limit = 120 spaces_before_comment = 4 blank_line_before_module_docstring = True +dedent_closing_brackets = True diff --git a/setup.py b/setup.py index 32529d3d..7ce4eab4 100644 --- a/setup.py +++ b/setup.py @@ -41,9 +41,8 @@ class Formatter(Command): def run(self): """Fromat the code using yapf.""" - errno = os.system( - 'python3 -m yapf --in-place --recursive --exclude .git .') - sys.exit(errno) + errno = os.system('python3 -m yapf --in-place --recursive --exclude .git .') + sys.exit(0 if errno == 0 else 1) class Linter(Command): @@ -67,12 +66,16 @@ class Linter(Command): def run(self): """Lint the code with yapf, mypy, and flake8.""" - errno = os.system(' && '.join([ - 'python3 -m yapf --diff --recursive --exclude .git .', - 'python3 -m mypy .', - 'python3 -m flake8', - ])) - sys.exit(errno) + errno = os.system( + ' && '.join( + [ + 'python3 -m yapf --diff --recursive --exclude .git .', + 'python3 -m mypy .', + 'python3 -m flake8', + ] + ) + ) + sys.exit(0 if errno == 0 else 1) class Tester(Command): @@ -97,7 +100,7 @@ class Tester(Command): def run(self): """Run pytest.""" errno = os.system('python3 -m pytest -v') - sys.exit(errno) + sys.exit(0 if errno == 0 else 1) setup(