Skip to main content
 首页 » 编程设计

python之从 TextMate 运行时,pylint 忽略 .pylintrc

2025年05月04日10oomusou

当我在 TextMate 中的 python 文件上运行验证语法时,我试图让 pylint 提供 html 输出。我安装了 pycheckmate、pylint,并在 $HOME 中创建了一个 .pylintrc 文件,将输出格式设置为 html。

在 TextMate 的高级控制面板中,在 Shell 变量选项卡中,我将 TM_PYCHECKER 设置为 /usr/local/share/python/pylint。如果我触发 Validate Syntax,它会使用所有默认选项运行 pylint,并提供输出。如果我将 TM_PYCHECKER 更改为 /usr/local/share/python/pylint --rcfile "$HOME/.pylintrc" 并再次验证语法,我得到:

Please install PyChecker, PyFlakes or Pylint for more extensive code checking.

如果我从命令行运行/usr/local/share/python/pylint,没有任何参数,输出是 html,所以我知道在那种情况下它正在读取 rcfile。我错过了什么?

请您参考如下方法:

好的,我想我发现了问题:pycheckmate 将 --output-format=parseable' 设置为 pylint 的强制参数。我通过用打印出其参数的包装脚本替换/usr/local/share/python/pylint 来发现这一点:

#!/usr/bin/env python 
 
import sys 
from pylint import lint 
 
print sys.argv[1:] 
lint.Run(sys.argv[1:]) 

当我在 TextMate 中运行它时,我看到了这个:

['--output-format=parseable', '/Users/smithm5/test.py'] 
test.py:26 [C] Line too long (90/80) 
… 

所以我深入研究了/Applications/TextMate.app/Contents/SharedSupport/Bundles/Python.tmbundle/Support/bin/pycheckmate.py 本身。果然,它添加了该参数,以及 大量 硬编码 html。所以为了修复它,我删除了所有的 escape() 包装器,在第 287 行设置 opts = () 这样我就可以设置我自己的该死的选项,并将第 332 行更改为打印行。