我遇到了numpy,scipy,sklearn,nipy等问题,并通过包裹epylint来解决了这个问题,如下所示:
$猫epylint.py
#!/usr/bin/python
"""
Synopsis: epylint wrapper that filters a bunch of false-positive warnings and errors
Author: DOHMATOB Elvis Dopgima <gmdopp@gmail.com> <elvis.dohmatob@inria.fr>
"""
import os
import sys
import re
from subprocess import Popen, STDOUT, PIPE
NUMPY_HAS_NO_MEMBER = re.compile("Module 'numpy(?:\..+)?' has no '.+' member")
SCIPY_HAS_NO_MEMBER = re.compile("Module 'scipy(?:\..+)?' has no '.+' member")
SCIPY_HAS_NO_MEMBER2 = re.compile("No name '.+' in module 'scipy(?:\..+)?'")
NIPY_HAS_NO_MEMBER = re.compile("Module 'nipy(?:\..+)?' has no '.+' member")
SK_ATTR_DEFINED_OUTSIDE_INIT = re.compile("Attribute '.+_' defined outside __init__")
REL_IMPORT_SHOULD_BE = re.compile("Relative import '.+', should be '.+")
REDEFINING_NAME_FROM_OUTER_SCOPE = re.compile("Redefining name '.+' from outer scope")
if __name__ == "__main__":
basename = os.path.basename(sys.argv[1])
for line in Popen(['epylint', sys.argv[1], '--disable=C,R,I' # filter thesew arnings
], stdout=PIPE, stderr=STDOUT, universal_newlines=True).stdout:
if line.startswith("***********"):
continue
elif line.startswith("No config file found,"):
continue
elif "anomalous-backslash-in-string," in line:
continue
if NUMPY_HAS_NO_MEMBER.search(line):
continue
if SCIPY_HAS_NO_MEMBER.search(line):
continue
if SCIPY_HAS_NO_MEMBER2.search(line):
continue
if "Used * or ** magic" in line:
continue
if "No module named" in line and "_flymake" in line:
continue
if SK_ATTR_DEFINED_OUTSIDE_INIT.search(line):
continue
if "Access to a protected member" in line:
continue
if REL_IMPORT_SHOULD_BE.search(line):
continue
if REDEFINING_NAME_FROM_OUTER_SCOPE.search(line):
continue
if NIPY_HAS_NO_MEMBER.search(line):
continue
# XXX extend by adding more handles for false-positives here
else:
print line,
该脚本仅运行epylint,然后刮擦其输出以过滤掉错误肯定的警告和错误。您可以通过添加更多elif案例来扩展它。
注意:如果这适用于您,则您需要修改pychechers.sh,使其像这样
#!/bin/bash
epylint.py "$1" 2>/dev/null
pyflakes "$1"
pep8 --ignore=E221,E701,E202 --repeat "$1"
true
(当然,您必须首先使epylint.py可执行)
这是我的.emacs https://github.com/dohmatob/mydotemacs的链接。希望这对某人有用。