diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-16 17:33:50 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-17 09:07:42 +0200 |
commit | 3f2842400795ae1aaffc4ae6c35c4ef26857c239 (patch) | |
tree | 057fb96b25b851998edce6dd40b8e496755422a1 /pylint/reporters | |
parent | c8e0992d31b831b7d60b1e8582b84068d50c3afd (diff) | |
download | pylint-git-3f2842400795ae1aaffc4ae6c35c4ef26857c239.tar.gz |
Reformat the code with black
Diffstat (limited to 'pylint/reporters')
-rw-r--r-- | pylint/reporters/__init__.py | 19 | ||||
-rw-r--r-- | pylint/reporters/json.py | 32 | ||||
-rw-r--r-- | pylint/reporters/text.py | 121 | ||||
-rw-r--r-- | pylint/reporters/ureports/__init__.py | 10 | ||||
-rw-r--r-- | pylint/reporters/ureports/nodes.py | 21 | ||||
-rw-r--r-- | pylint/reporters/ureports/text_writer.py | 30 |
6 files changed, 126 insertions, 107 deletions
diff --git a/pylint/reporters/__init__.py b/pylint/reporters/__init__.py index 340b072b8..c09ebdd0c 100644 --- a/pylint/reporters/__init__.py +++ b/pylint/reporters/__init__.py @@ -25,19 +25,21 @@ import os import warnings -CMPS = ['=', '-', '+'] +CMPS = ["=", "-", "+"] # py3k has no more cmp builtin if sys.version_info >= (3, 0): - def cmp(a, b): # pylint: disable=redefined-builtin + + def cmp(a, b): # pylint: disable=redefined-builtin return (a > b) - (a < b) + def diff_string(old, new): """given an old and new int value, return a string representing the difference """ diff = abs(old - new) - diff_str = "%s%s" % (CMPS[cmp(old, new)], diff and ('%.2f' % diff) or '') + diff_str = "%s%s" % (CMPS[cmp(old, new)], diff and ("%.2f" % diff) or "") return diff_str @@ -47,7 +49,7 @@ class BaseReporter: symbols: show short symbolic names for messages. """ - extension = '' + extension = "" def __init__(self, output=None): self.linter = None @@ -65,15 +67,15 @@ class BaseReporter: """set output stream""" self.out = output or sys.stdout - def writeln(self, string=''): + def writeln(self, string=""): """write a line in the output buffer""" print(string, file=self.out) def display_reports(self, layout): """display results encapsulated in the layout tree""" self.section = 0 - if hasattr(layout, 'report_id'): - layout.children[0].children[0].data += ' (%s)' % layout.report_id + if hasattr(layout, "report_id"): + layout.children[0].children[0].data += " (%s)" % layout.report_id self._display(layout) def _display(self, layout): @@ -103,7 +105,7 @@ class BaseReporter: class CollectingReporter(BaseReporter): """collects messages""" - name = 'collector' + name = "collector" def __init__(self): BaseReporter.__init__(self) @@ -118,4 +120,5 @@ class CollectingReporter(BaseReporter): def initialize(linter): """initialize linter with reporters in this package """ from pylint import utils + utils.register_plugins(linter, __path__[0]) diff --git a/pylint/reporters/json.py b/pylint/reporters/json.py index 7f465ca61..bb3ca0153 100644 --- a/pylint/reporters/json.py +++ b/pylint/reporters/json.py @@ -21,8 +21,8 @@ class JSONReporter(BaseReporter): """Report messages and layouts in JSON.""" __implements__ = IReporter - name = 'json' - extension = 'json' + name = "json" + extension = "json" def __init__(self, output=sys.stdout): BaseReporter.__init__(self, output) @@ -30,24 +30,26 @@ class JSONReporter(BaseReporter): def handle_message(self, msg): """Manage message of different type and in the context of path.""" - self.messages.append({ - 'type': msg.category, - 'module': msg.module, - 'obj': msg.obj, - 'line': msg.line, - 'column': msg.column, - 'path': msg.path, - 'symbol': msg.symbol, - # pylint: disable=deprecated-method; deprecated since 3.2. - 'message': cgi.escape(msg.msg or ''), - 'message-id': msg.msg_id, - }) + self.messages.append( + { + "type": msg.category, + "module": msg.module, + "obj": msg.obj, + "line": msg.line, + "column": msg.column, + "path": msg.path, + "symbol": msg.symbol, + # pylint: disable=deprecated-method; deprecated since 3.2. + "message": cgi.escape(msg.msg or ""), + "message-id": msg.msg_id, + } + ) def display_messages(self, layout): """Launch layouts display""" print(json.dumps(self.messages, indent=4), file=self.out) - def display_reports(self, layout): # pylint: disable=arguments-differ + def display_reports(self, layout): # pylint: disable=arguments-differ """Don't do nothing in this reporter.""" def _display(self, layout): diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py index 517c4484a..4c682ae05 100644 --- a/pylint/reporters/text.py +++ b/pylint/reporters/text.py @@ -30,32 +30,33 @@ from pylint import utils from pylint.reporters.ureports.text_writer import TextWriter -TITLE_UNDERLINES = ['', '=', '-', '.'] +TITLE_UNDERLINES = ["", "=", "-", "."] -ANSI_PREFIX = '\033[' -ANSI_END = 'm' -ANSI_RESET = '\033[0m' +ANSI_PREFIX = "\033[" +ANSI_END = "m" +ANSI_RESET = "\033[0m" ANSI_STYLES = { - 'reset': "0", - 'bold': "1", - 'italic': "3", - 'underline': "4", - 'blink': "5", - 'inverse': "7", - 'strike': "9", + "reset": "0", + "bold": "1", + "italic": "3", + "underline": "4", + "blink": "5", + "inverse": "7", + "strike": "9", } ANSI_COLORS = { - 'reset': "0", - 'black': "30", - 'red': "31", - 'green': "32", - 'yellow': "33", - 'blue': "34", - 'magenta': "35", - 'cyan': "36", - 'white': "37", + "reset": "0", + "black": "30", + "red": "31", + "green": "32", + "yellow": "33", + "blue": "34", + "magenta": "35", + "cyan": "36", + "white": "37", } + def _get_ansi_code(color=None, style=None): """return ansi escape code corresponding to color and style @@ -81,13 +82,14 @@ def _get_ansi_code(color=None, style=None): ansi_code.append(ANSI_STYLES[effect]) if color: if color.isdigit(): - ansi_code.extend(['38', '5']) + ansi_code.extend(["38", "5"]) ansi_code.append(color) else: ansi_code.append(ANSI_COLORS[color]) if ansi_code: - return ANSI_PREFIX + ';'.join(ansi_code) + ANSI_END - return '' + return ANSI_PREFIX + ";".join(ansi_code) + ANSI_END + return "" + def colorize_ansi(msg, color=None, style=None): """colorize message by wrapping it with ansi escape codes @@ -115,7 +117,7 @@ def colorize_ansi(msg, color=None, style=None): escape_code = _get_ansi_code(color, style) # If invalid (or unknown) color, don't wrap msg with ansi codes if escape_code: - return '%s%s%s' % (escape_code, msg, ANSI_RESET) + return "%s%s%s" % (escape_code, msg, ANSI_RESET) return msg @@ -123,9 +125,9 @@ class TextReporter(BaseReporter): """reports messages and layouts in plain text""" __implements__ = IReporter - name = 'text' - extension = 'txt' - line_format = '{path}:{line}:{column}: {msg_id}: {msg} ({symbol})' + name = "text" + extension = "txt" + line_format = "{path}:{line}:{column}: {msg_id}: {msg} ({symbol})" def __init__(self, output=None): BaseReporter.__init__(self, output) @@ -143,10 +145,10 @@ class TextReporter(BaseReporter): """manage message of different type and in the context of path""" if msg.module not in self._modules: if msg.module: - self.writeln('************* Module %s' % msg.module) + self.writeln("************* Module %s" % msg.module) self._modules.add(msg.module) else: - self.writeln('************* ') + self.writeln("************* ") self.write_message(msg) def _display(self, layout): @@ -161,45 +163,49 @@ class ParseableTextReporter(TextReporter): <filename>:<linenum>:<msg> """ - name = 'parseable' - line_format = '{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}' + + name = "parseable" + line_format = "{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" def __init__(self, output=None): - warnings.warn('%s output format is deprecated. This is equivalent ' - 'to --msg-template=%s' % (self.name, self.line_format), - DeprecationWarning) + warnings.warn( + "%s output format is deprecated. This is equivalent " + "to --msg-template=%s" % (self.name, self.line_format), + DeprecationWarning, + ) TextReporter.__init__(self, output) class VSTextReporter(ParseableTextReporter): """Visual studio text reporter""" - name = 'msvs' - line_format = '{path}({line}): [{msg_id}({symbol}){obj}] {msg}' + + name = "msvs" + line_format = "{path}({line}): [{msg_id}({symbol}){obj}] {msg}" class ColorizedTextReporter(TextReporter): """Simple TextReporter that colorizes text output""" - name = 'colorized' + name = "colorized" COLOR_MAPPING = { - "I" : ("green", None), - 'C' : (None, "bold"), - 'R' : ("magenta", "bold, italic"), - 'W' : ("magenta", None), - 'E' : ("red", "bold"), - 'F' : ("red", "bold, underline"), - 'S' : ("yellow", "inverse"), # S stands for module Separator + "I": ("green", None), + "C": (None, "bold"), + "R": ("magenta", "bold, italic"), + "W": ("magenta", None), + "E": ("red", "bold"), + "F": ("red", "bold, underline"), + "S": ("yellow", "inverse"), # S stands for module Separator } def __init__(self, output=None, color_mapping=None): TextReporter.__init__(self, output) - self.color_mapping = color_mapping or \ - dict(ColorizedTextReporter.COLOR_MAPPING) - ansi_terms = ['xterm-16color', 'xterm-256color'] - if os.environ.get('TERM') not in ansi_terms: - if sys.platform == 'win32': + self.color_mapping = color_mapping or dict(ColorizedTextReporter.COLOR_MAPPING) + ansi_terms = ["xterm-16color", "xterm-256color"] + if os.environ.get("TERM") not in ansi_terms: + if sys.platform == "win32": # pylint: disable=import-error import colorama + self.out = colorama.AnsiToWin32(self.out) def _get_decoration(self, msg_id): @@ -216,20 +222,23 @@ class ColorizedTextReporter(TextReporter): using ansi escape codes """ if msg.module not in self._modules: - color, style = self._get_decoration('S') + color, style = self._get_decoration("S") if msg.module: - modsep = colorize_ansi('************* Module %s' % msg.module, - color, style) + modsep = colorize_ansi( + "************* Module %s" % msg.module, color, style + ) else: - modsep = colorize_ansi('************* %s' % msg.module, - color, style) + modsep = colorize_ansi("************* %s" % msg.module, color, style) self.writeln(modsep) self._modules.add(msg.module) color, style = self._get_decoration(msg.C) msg = msg._replace( - **{attr: colorize_ansi(getattr(msg, attr), color, style) - for attr in ('msg', 'symbol', 'category', 'C')}) + **{ + attr: colorize_ansi(getattr(msg, attr), color, style) + for attr in ("msg", "symbol", "category", "C") + } + ) self.write_message(msg) diff --git a/pylint/reporters/ureports/__init__.py b/pylint/reporters/ureports/__init__.py index 2eec5e9ae..56a829fac 100644 --- a/pylint/reporters/ureports/__init__.py +++ b/pylint/reporters/ureports/__init__.py @@ -30,8 +30,8 @@ class BaseWriter: if stream is None: stream = sys.stdout if not encoding: - encoding = getattr(stream, 'encoding', 'UTF-8') - self.encoding = encoding or 'UTF-8' + encoding = getattr(stream, "encoding", "UTF-8") + self.encoding = encoding or "UTF-8" self.out = stream self.begin_format() layout.accept(self) @@ -41,10 +41,10 @@ class BaseWriter: """recurse on the layout children and call their accept method (see the Visitor pattern) """ - for child in getattr(layout, 'children', ()): + for child in getattr(layout, "children", ()): child.accept(self) - def writeln(self, string=''): + def writeln(self, string=""): """write a line in the output buffer""" self.write(string + os.linesep) @@ -74,7 +74,7 @@ class BaseWriter: result[-1].append(cell) # fill missing cells while len(result[-1]) < cols: - result[-1].append('') + result[-1].append("") return result def compute_content(self, layout): diff --git a/pylint/reporters/ureports/nodes.py b/pylint/reporters/ureports/nodes.py index 8b502fb62..8fafb206a 100644 --- a/pylint/reporters/ureports/nodes.py +++ b/pylint/reporters/ureports/nodes.py @@ -13,7 +13,6 @@ A micro report is a tree of layout and content objects. class VNode: - def __init__(self, nid=None): self.id = nid # navigation @@ -41,17 +40,17 @@ class VNode: """ try: # pylint: disable=no-member - return self.TYPE.replace('-', '_') + return self.TYPE.replace("-", "_") # pylint: disable=broad-except except Exception: return self.__class__.__name__.lower() def accept(self, visitor, *args, **kwargs): - func = getattr(visitor, 'visit_%s' % self._get_visit_name()) + func = getattr(visitor, "visit_%s" % self._get_visit_name()) return func(self, *args, **kwargs) def leave(self, visitor, *args, **kwargs): - func = getattr(visitor, 'leave_%s' % self._get_visit_name()) + func = getattr(visitor, "leave_%s" % self._get_visit_name()) return func(self, *args, **kwargs) @@ -61,6 +60,7 @@ class BaseLayout(VNode): attributes * children : components in this table (i.e. the table's cells) """ + def __init__(self, children=(), **kwargs): super(BaseLayout, self).__init__(**kwargs) for child in children: @@ -88,15 +88,17 @@ class BaseLayout(VNode): # non container nodes ######################################################### + class Text(VNode): """a text portion attributes : * data : the text value as an encoded or unicode string """ + def __init__(self, data, escaped=True, **kwargs): super(Text, self).__init__(**kwargs) - #if isinstance(data, unicode): + # if isinstance(data, unicode): # data = data.encode('ascii') assert isinstance(data, str), data.__class__ self.escaped = escaped @@ -110,8 +112,10 @@ class VerbatimText(Text): * data : the text value as an encoded or unicode string """ + # container nodes ############################################################# + class Section(BaseLayout): """a section @@ -123,6 +127,7 @@ class Section(BaseLayout): a description may also be given to the constructor, it'll be added as a first paragraph """ + def __init__(self, title=None, description=None, **kwargs): super(Section, self).__init__(**kwargs) if description: @@ -132,7 +137,6 @@ class Section(BaseLayout): class EvaluationSection(Section): - def __init__(self, message, **kwargs): super(EvaluationSection, self).__init__(**kwargs) title = Paragraph() @@ -174,9 +178,8 @@ class Table(BaseLayout): * cheaders : the first col's elements are table's header * title : the table's optional title """ - def __init__(self, cols, title=None, - rheaders=0, cheaders=0, - **kwargs): + + def __init__(self, cols, title=None, rheaders=0, cheaders=0, **kwargs): super(Table, self).__init__(**kwargs) assert isinstance(cols, int) self.cols = cols diff --git a/pylint/reporters/ureports/text_writer.py b/pylint/reporters/ureports/text_writer.py index 7dfe743bc..9d9e1ad34 100644 --- a/pylint/reporters/ureports/text_writer.py +++ b/pylint/reporters/ureports/text_writer.py @@ -11,13 +11,15 @@ from __future__ import print_function from pylint.reporters.ureports import BaseWriter -TITLE_UNDERLINES = ['', '=', '-', '`', '.', '~', '^'] -BULLETS = ['*', '-'] +TITLE_UNDERLINES = ["", "=", "-", "`", ".", "~", "^"] +BULLETS = ["*", "-"] + class TextWriter(BaseWriter): """format layouts as text (ReStructured inspiration but not totally handled yet) """ + def begin_format(self): super(TextWriter, self).begin_format() self.list_level = 0 @@ -39,7 +41,7 @@ class TextWriter(BaseWriter): self.writeln() def visit_title(self, layout): - title = ''.join(list(self.compute_content(layout))) + title = "".join(list(self.compute_content(layout))) self.writeln(title) try: self.writeln(TITLE_UNDERLINES[self.section] * len(title)) @@ -55,7 +57,7 @@ class TextWriter(BaseWriter): """display a table as text""" table_content = self.get_table_content(layout) # get columns width - cols_width = [0]*len(table_content[0]) + cols_width = [0] * len(table_content[0]) for row in table_content: for index, col in enumerate(row): cols_width[index] = max(cols_width[index], len(col)) @@ -64,19 +66,19 @@ class TextWriter(BaseWriter): def default_table(self, layout, table_content, cols_width): """format a table""" - cols_width = [size+1 for size in cols_width] - format_strings = ' '.join(['%%-%ss'] * len(cols_width)) + cols_width = [size + 1 for size in cols_width] + format_strings = " ".join(["%%-%ss"] * len(cols_width)) format_strings = format_strings % tuple(cols_width) - format_strings = format_strings.split(' ') - table_linesep = '\n+' + '+'.join(['-'*w for w in cols_width]) + '+\n' - headsep = '\n+' + '+'.join(['='*w for w in cols_width]) + '+\n' + format_strings = format_strings.split(" ") + table_linesep = "\n+" + "+".join(["-" * w for w in cols_width]) + "+\n" + headsep = "\n+" + "+".join(["=" * w for w in cols_width]) + "+\n" # FIXME: layout.cheaders self.write(table_linesep) for index, line in enumerate(table_content): - self.write('|') + self.write("|") for line_index, at_index in enumerate(line): self.write(format_strings[line_index] % at_index) - self.write('|') + self.write("|") if index == 0 and layout.rheaders: self.write(headsep) else: @@ -85,11 +87,11 @@ class TextWriter(BaseWriter): def visit_verbatimtext(self, layout): """display a verbatim layout as text (so difficult ;) """ - self.writeln('::\n') + self.writeln("::\n") for line in layout.data.splitlines(): - self.writeln(' ' + line) + self.writeln(" " + line) self.writeln() def visit_text(self, layout): """add some text""" - self.write('%s' % layout.data) + self.write("%s" % layout.data) |