4 from pathlib
import Path
11 from rich.console
import Console, Group
12 from rich.text
import Text
13 from rich.panel
import Panel
14 from rich.rule
import Rule
15 from rich.emoji
import Emoji
16 from rich.table
import Table
19 from item
import Item, ItemCollection
23 p = argparse.ArgumentParser()
24 p.add_argument(
"--report", type=Path, required=
True)
25 p.add_argument(
"--config", type=Path, required=
True)
26 p.add_argument(
"--strip-prefix-path", type=Path)
32 with args.config.open()
as fh:
33 config = yaml.safe_load(fh)
36 with args.report.open()
as fh:
39 if args.strip_prefix_path
and not item.path.is_absolute:
40 item.path = item.path.relative_to(args.strip_prefix_path)
42 counts = config[
"limits"].copy()
45 for file, items
in itertools.groupby(sorted(data, key=kf), key=kf):
51 {
"warning":
"yellow_circle",
"error":
"red_circle"}[item.severity]
55 if item.severity ==
"warning":
57 elif item.severity ==
"error":
62 s.append(f
" {item.path}:{item.line}:{item.col}", style=
"bold")
63 s.append(f
" {item.severity.upper()} ", style=style)
65 s.append(item.code, style=
"bold")
69 return f
"[bold]{m.group(1)}[/bold]:"
71 message = re.sub(
r"([\w/.\-+]+:\d+:\d+):", subpath, item.message)
74 for pattern
in config[
"limits"].keys():
76 if not fnmatch.fnmatch(item.code, pattern):
83 output.append(Panel(message))
87 counts.setdefault(item.code, 0)
88 counts[item.code] += 1
92 console.print(Panel(Group(*output), title=
str(file)))
95 table.add_column(
"", width=2)
96 table.add_column(
"code / pattern")
97 table.add_column(
"count", justify=
"right")
98 table.add_column(
"limit", justify=
"right")
100 for pattern, count
in counts.items():
101 limit = config[
"limits"].get(pattern, float(
"inf"))
102 emoji = Emoji(
"green_circle")
104 if limit == float(
"inf"):
105 emoji = Emoji(
"white_circle")
109 emoji = Emoji(
"red_circle")
111 table.add_row(emoji, pattern,
str(count),
str(limit), style=style)
114 console.print(Panel.fit(table, title=
"Results"), justify=
"center")
119 Text(f
"{Emoji('red_circle')} FAILURE", justify=
"center"),
126 Text(f
"{Emoji('green_circle')} SUCCESS", justify=
"center"),
134 if "__main__" == __name__: