3
# pylint-wrapper: Script to wrap pylint output
5
# Author: Rodney Dawes <rodney.dawes@canonical.com>
7
# Copyright 2009 Canonical Ltd.
9
# This program is free software: you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License version 3, as published
11
# by the Free Software Foundation.
13
# This program is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranties of
15
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16
# PURPOSE. See the GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License along
19
# with this program. If not, see <http://www.gnu.org/licenses/>.
20
"""Wrapper script for pylint command"""
27
SRCDIR = os.environ['SRCDIR']
31
def _read_pylintrc_ignored():
32
"""Get the ignored files list from pylintrc"""
33
config = ConfigParser.ConfigParser()
34
config.read([os.path.join(SRCDIR, 'pylintrc')])
37
return config.get("MASTER", "ignore").split(",")
38
except ConfigParser.NoOptionError:
41
def _group_lines_by_file(data):
42
"""Format file:line:message output as lines grouped by file."""
46
for line in data.splitlines():
47
current = line.split(":", 3)
48
if line.startswith(" "):
49
outputs.append(" " + current[0] + "")
50
elif line.startswith("build/") or len(current) < 3:
52
elif filename == current[0]:
53
# pylint warning W0511 is a custom note
54
if not "[W0511]" in current[2]:
56
outputs.append(" " + current[1] + ": " + current[2])
57
elif filename != current[0]:
60
outputs.append(filename + ":")
61
# pylint warning W0511 is a custom note
62
if not "[W0511]" in current[2]:
64
outputs.append(" " + current[1] + ": " + current[2])
66
return (failed, "\n".join(outputs))
69
"""Find all Python files under the current tree."""
71
# pylint: disable-msg=W0612
72
for root, dirs, files in os.walk(SRCDIR, topdown=False):
75
if file.endswith(".py") or path.endswith("bin/"):
76
pyfiles.append(os.path.join(root, file))
84
ignored = _read_pylintrc_ignored()
86
# So that we can match the path correctly
87
moreignores = [os.path.join(SRCDIR, item) for item in ignored]
88
ignored.extend(moreignores)
89
if os.environ.get('USE_PYFLAKES'):
90
pylint_args = ["pyflakes"]
92
pylint_args = ["pylint",
93
"--output-format=parseable",
95
"--rcfile=" + os.path.join(SRCDIR, "pylintrc"),]
98
for path in _find_files():
99
if path not in ignored and not path.startswith(os.path.join(SRCDIR,
101
pylint_args.append(path)
103
p = subprocess.Popen(pylint_args,
104
bufsize=4096, stdout=subprocess.PIPE)
107
output = "".join(notices.readlines())
109
print "== Python Lint Notices =="
110
(failed, grouped) = _group_lines_by_file(output)
114
returncode = p.wait()