Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/pylint/reporters/text.py

Issue 753543006: pylint: upgrade to 1.4.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pylint/reporters/html.py ('k') | third_party/pylint/testutils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE). 1 # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
2 # This program is free software; you can redistribute it and/or modify it under 2 # This program is free software; you can redistribute it and/or modify it under
3 # the terms of the GNU General Public License as published by the Free Software 3 # the terms of the GNU General Public License as published by the Free Software
4 # Foundation; either version 2 of the License, or (at your option) any later 4 # Foundation; either version 2 of the License, or (at your option) any later
5 # version. 5 # version.
6 # 6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT 7 # This program is distributed in the hope that it will be useful, but WITHOUT
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 # 10 #
11 # You should have received a copy of the GNU General Public License along with 11 # You should have received a copy of the GNU General Public License along with
12 # this program; if not, write to the Free Software Foundation, Inc., 12 # this program; if not, write to the Free Software Foundation, Inc.,
13 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 13 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 """Plain text reporters: 14 """Plain text reporters:
15 15
16 :text: the default one grouping messages by module 16 :text: the default one grouping messages by module
17 :colorized: an ANSI colorized text reporter 17 :colorized: an ANSI colorized text reporter
18 """ 18 """
19 from __future__ import print_function
19 20
20 import warnings 21 import warnings
21 22
22 from logilab.common.ureports import TextWriter 23 from logilab.common.ureports import TextWriter
23 from logilab.common.textutils import colorize_ansi 24 from logilab.common.textutils import colorize_ansi
24 25
25 from pylint.interfaces import IReporter 26 from pylint.interfaces import IReporter
26 from pylint.reporters import BaseReporter, Message 27 from pylint.reporters import BaseReporter
28 import six
27 29
28 TITLE_UNDERLINES = ['', '=', '-', '.'] 30 TITLE_UNDERLINES = ['', '=', '-', '.']
29 31
30 32
31 class TextReporter(BaseReporter): 33 class TextReporter(BaseReporter):
32 """reports messages and layouts in plain text""" 34 """reports messages and layouts in plain text"""
33 35
34 __implements__ = IReporter 36 __implements__ = IReporter
35 name = 'text' 37 name = 'text'
36 extension = 'txt' 38 extension = 'txt'
37 line_format = '{C}:{line:3d},{column:2d}: {msg} ({symbol})' 39 line_format = '{C}:{line:3d},{column:2d}: {msg} ({symbol})'
38 40
39 def __init__(self, output=None): 41 def __init__(self, output=None):
40 BaseReporter.__init__(self, output) 42 BaseReporter.__init__(self, output)
41 self._modules = set() 43 self._modules = set()
42 self._template = None 44 self._template = None
43 45
44 def on_set_current_module(self, module, filepath): 46 def on_set_current_module(self, module, filepath):
45 self._template = unicode(self.linter.config.msg_template or self.line_fo rmat) 47 self._template = six.text_type(self.linter.config.msg_template or self.l ine_format)
46 48
47 def write_message(self, msg): 49 def write_message(self, msg):
48 """Convenience method to write a formated message with class default tem plate""" 50 """Convenience method to write a formated message with class default tem plate"""
49 self.writeln(msg.format(self._template)) 51 self.writeln(msg.format(self._template))
50 52
51 def add_message(self, msg_id, location, msg): 53 def handle_message(self, msg):
52 """manage message of different type and in the context of path""" 54 """manage message of different type and in the context of path"""
53 m = Message(self, msg_id, location, msg) 55 if msg.module not in self._modules:
54 if m.module not in self._modules: 56 if msg.module:
55 if m.module: 57 self.writeln('************* Module %s' % msg.module)
56 self.writeln('************* Module %s' % m.module) 58 self._modules.add(msg.module)
57 self._modules.add(m.module)
58 else: 59 else:
59 self.writeln('************* ') 60 self.writeln('************* ')
60 self.write_message(m) 61 self.write_message(msg)
61 62
62 def _display(self, layout): 63 def _display(self, layout):
63 """launch layouts display""" 64 """launch layouts display"""
64 print >> self.out 65 print(file=self.out)
65 TextWriter().format(layout, self.out) 66 TextWriter().format(layout, self.out)
66 67
67 68
68 class ParseableTextReporter(TextReporter): 69 class ParseableTextReporter(TextReporter):
69 """a reporter very similar to TextReporter, but display messages in a form 70 """a reporter very similar to TextReporter, but display messages in a form
70 recognized by most text editors : 71 recognized by most text editors :
71 72
72 <filename>:<linenum>:<msg> 73 <filename>:<linenum>:<msg>
73 """ 74 """
74 name = 'parseable' 75 name = 'parseable'
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 def _get_decoration(self, msg_id): 109 def _get_decoration(self, msg_id):
109 """Returns the tuple color, style associated with msg_id as defined 110 """Returns the tuple color, style associated with msg_id as defined
110 in self.color_mapping 111 in self.color_mapping
111 """ 112 """
112 try: 113 try:
113 return self.color_mapping[msg_id[0]] 114 return self.color_mapping[msg_id[0]]
114 except KeyError: 115 except KeyError:
115 return None, None 116 return None, None
116 117
117 def add_message(self, msg_id, location, msg): 118 def handle_message(self, msg):
118 """manage message of different types, and colorize output 119 """manage message of different types, and colorize output
119 using ansi escape codes 120 using ansi escape codes
120 """ 121 """
121 msg = Message(self, msg_id, location, msg)
122 if msg.module not in self._modules: 122 if msg.module not in self._modules:
123 color, style = self._get_decoration('S') 123 color, style = self._get_decoration('S')
124 if msg.module: 124 if msg.module:
125 modsep = colorize_ansi('************* Module %s' % msg.module, 125 modsep = colorize_ansi('************* Module %s' % msg.module,
126 color, style) 126 color, style)
127 else: 127 else:
128 modsep = colorize_ansi('************* %s' % msg.module, 128 modsep = colorize_ansi('************* %s' % msg.module,
129 color, style) 129 color, style)
130 self.writeln(modsep) 130 self.writeln(modsep)
131 self._modules.add(msg.module) 131 self._modules.add(msg.module)
132 color, style = self._get_decoration(msg.C) 132 color, style = self._get_decoration(msg.C)
133 for attr in ('msg', 'symbol', 'category', 'C'): 133
134 setattr(msg, attr, colorize_ansi(getattr(msg, attr), color, style)) 134 msg = msg._replace(
135 **{attr: colorize_ansi(getattr(msg, attr), color, style)
136 for attr in ('msg', 'symbol', 'category', 'C')})
135 self.write_message(msg) 137 self.write_message(msg)
136 138
137 139
138 def register(linter): 140 def register(linter):
139 """Register the reporter classes with the linter.""" 141 """Register the reporter classes with the linter."""
140 linter.register_reporter(TextReporter) 142 linter.register_reporter(TextReporter)
141 linter.register_reporter(ParseableTextReporter) 143 linter.register_reporter(ParseableTextReporter)
142 linter.register_reporter(VSTextReporter) 144 linter.register_reporter(VSTextReporter)
143 linter.register_reporter(ColorizedTextReporter) 145 linter.register_reporter(ColorizedTextReporter)
OLDNEW
« no previous file with comments | « third_party/pylint/reporters/html.py ('k') | third_party/pylint/testutils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698