2

当我在 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"验证语法,我会得到:

请安装 PyChecker、PyFlakes 或 Pylint 以进行更广泛的代码检查。

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

4

2 回答 2

1

好的,我想我发现了问题: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()包装,设置opts = ()在第 287 行,这样我就可以设置自己的选项,并将第 332 行更改为print line.

于 2012-05-31T23:34:42.080 回答
0

一个有根据的猜测:尝试用$HOME你的主目录的绝对路径替换。像这样的 Shell 变量$HOME可能无法在 TextMate 的控制面板中使用。

更新:查看pycheckmate.py包含在我拥有的 TextMate 版本中的脚本Python.tmbundle,似乎无法包含参数,例如--rcfile /path/to/rcfile. 的值TM_PYCHECKER应该只是不带参数的检查器二进制文件的路径。但是,如果您制作自己的 Python.tmbundle 副本,您应该能够pycheckmate.py按照自己的意愿进行编辑。

于 2012-05-31T17:25:10.817 回答