Pylint:通过脚本获取输出,类似于 pylint 可执行文件的



我使用python 3.3,Windows,通过PIP工具安装的孔。
我可以通过"脚本 pylint.exe"工具运行此类命令(参数很重要,我需要特殊的明文输出)

pylint --msg-template="{line}:{column}:{msg_id}: {msg}" --module-rgx=.* --reports=n --persistent=n "D:TestLintsample_plugin.py"

这检查了我的文件并提供了此类输出

************* Module sample_plugin
1:0:C0111: Missing module docstring
1:0:F0401: Unable to import 'tst'
3:0:W0232: Class has no __init__ method
3:0:C0111: Missing class docstring
3:0:C1001: Old-style class defined.
4:4:C0111: Missing method docstring

现在,我想通过Python代码使用Pylint,而不是使用任何EXE工具。并希望具有相似/相同的输出我的测试文件。所以问题。我可以写什么py脚本来调用pylint并获得相同的输出(在字符串或列表中)?

有几种方法可以这样做。最简单的是:

from pylint.lint import Run
Run([file_or_module, '--message-template', '...'])

如果要在子过程中运行孔(建议多个运行),请尝试:

from pylint.epylint import lint
lint(file_or_module, [--message-template', '...']

最新更新