Python之pylint
发布于 2017-12-13 · 本文总共 2183 字 · 阅读大约需要
7 分钟
pylint
Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint默认使用的代码风格是PEP8)和有潜在问题的代码。
配置
pylint --generate-rcfile > pylint.conf
-
reports=no 不显示完整的报告,只显示消息。
-
添加命令别名(配置文件在用户目录“~/”下):
echo "alias pylt='pylint --rcfile=~/pylint.conf'" >> ~/.bashrc
MESSAGE_TYPE
有如下几种:
(C) 惯例。违反了编码风格标准;
(R) 重构。写得非常糟糕的代码;
(W) 警告。某些 Python 特定的问题;
(E) 错误。很可能是代码中的错误;
(F) 致命错误。阻止 Pylint 进一步运行的错误;
jenkins中的violations插件
https://wiki.jenkins-ci.org/display/JENKINS/Violations
安装pylint
sudo python -m pip install -U pylint
报错:
Installing collected packages: six, wrapt, astroid, futures, isort, configparser, pylint
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-R2Lacx-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
- 解决办法
sudo python -m pip install -U pylint --ignore-installed