Skip to content

Commit

Permalink
Merge pull request #686 from prospector-dev/add-sumary-everywhere
Browse files Browse the repository at this point in the history
Have the summary also on pylint and vscode output
  • Loading branch information
sbrunner authored Oct 21, 2024
2 parents 2ddbe3d + 4728ed3 commit ac38f1e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
38 changes: 38 additions & 0 deletions prospector/formatters/base_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from prospector.formatters.base import Formatter


class SummaryFormatter(Formatter):
"""
This abstract formatter is used to output a summary of the prospector run.
"""

summary_labels = (
("started", "Started", None),
("completed", "Finished", None),
("time_taken", "Time Taken", lambda x: "%s seconds" % x),
("formatter", "Formatter", None),
("profiles", "Profiles", None),
("strictness", "Strictness", None),
("libraries", "Libraries Used", ", ".join),
("tools", "Tools Run", ", ".join),
("adaptors", "Adaptors", ", ".join),
("message_count", "Messages Found", None),
("external_config", "External Config", None),
)

def render_summary(self):
output = [
"Check Information",
"=================",
]

label_width = max(len(label[1]) for label in self.summary_labels)

for key, label, formatter in self.summary_labels:
if key in self.summary:
value = self.summary[key]
if formatter is not None:
value = formatter(value)
output.append(f" {label.rjust(label_width)}: {value}")

return "\n".join(output)
8 changes: 6 additions & 2 deletions prospector/formatters/pylint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import re

from prospector.formatters.base import Formatter
from prospector.formatters.base_summary import SummaryFormatter


class PylintFormatter(Formatter):
class PylintFormatter(SummaryFormatter):
"""
This formatter outputs messages in the same way as pylint -f parseable , which is used by several
tools to parse pylint output. This formatter is therefore a compatibility shim between tools built
Expand Down Expand Up @@ -41,4 +41,8 @@ def render(self, summary=True, messages=True, profile=False):
}
)

if summary:
output.append("")
output.append(self.render_summary())

return "\n".join(output)
43 changes: 2 additions & 41 deletions prospector/formatters/text.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@
from prospector.formatters.base import Formatter
from prospector.formatters.base_summary import SummaryFormatter

__all__ = ("TextFormatter",)


# pylint: disable=unnecessary-lambda


class TextFormatter(Formatter):
summary_labels = (
("started", "Started"),
("completed", "Finished"),
("time_taken", "Time Taken", lambda x: "%s seconds" % x),
("formatter", "Formatter"),
("profiles", "Profiles"),
("strictness", "Strictness"),
("libraries", "Libraries Used", lambda x: ", ".join(x)),
("tools", "Tools Run", lambda x: ", ".join(x)),
("adaptors", "Adaptors", lambda x: ", ".join(x)),
("message_count", "Messages Found"),
("external_config", "External Config"),
)

def render_summary(self):
output = [
"Check Information",
"=================",
]

label_width = max(len(label[1]) for label in self.summary_labels)

for summary_label in self.summary_labels:
key = summary_label[0]
if key in self.summary:
label = summary_label[1]
if len(summary_label) > 2:
value = summary_label[2](self.summary[key])
else:
value = self.summary[key]
output.append(
" %s: %s"
% (
label.rjust(label_width),
value,
)
)

return "\n".join(output)
class TextFormatter(SummaryFormatter):

def render_message(self, message):
output = []
Expand Down
7 changes: 5 additions & 2 deletions prospector/formatters/vscode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import re

from prospector.formatters.base import Formatter
from prospector.formatters.base_summary import SummaryFormatter


class VSCodeFormatter(Formatter):
class VSCodeFormatter(SummaryFormatter):
"""
This formatter outputs messages in the same way as vscode prospector linter expects.
"""
Expand Down Expand Up @@ -34,5 +34,8 @@ def render(self, summary=True, messages=True, profile=False):
"message": message.message.strip(),
}
)
if summary:
output.append("")
output.append(self.render_summary())

return "\n".join(output)

0 comments on commit ac38f1e

Please sign in to comment.