最近项目codebase 迁移到了GoB/Gerrit 的体系中,提交代码后CI 会做code linting 操作并且提示错误信息,最好是在提交前在本地先自检,但目前似乎没有集成本地linting 的功能, 经过观察,可以自己搭建linting 的环境去对任意2次commits 之间改动过的py, yaml or other 文件进行语法,格式的检查。
Lint Steps
为了方便,这里使用python virtualenv, 也可以使用docker 环境,mount整个repo 然后处理. work on a python virtual env, for example virtualenv -p python3 venv
:
1 | # activate the venv first |
Disable PyLint
You may need to update .pylintrc setting to skip warnings/errors, edit disable line to add error code or statement, for example:
1 | disable=C0103,missing-docstring,too-many-branches |
Or disabling the pylint check inline:
1 | if __name__ == '__main__': |
Or more readable, use the symbolic name:
1 | if __name__ == '__main__': |
And disable in a function level, for example:
1 | def wont_raise_pylint(): |
And disable in a file or bigger scoup, the following part will be disabled by this rule, you can enable it again:
1 | # pylint: disable=use-implicit-booleaness-not-comparison |