From 9350f9e4bf43d43d285bc12fa2f88d72c16414dd Mon Sep 17 00:00:00 2001 From: Rick Nickle Date: Fri, 12 Nov 2021 19:59:55 -0500 Subject: [PATCH 1/3] Adapt stats collection to allow for colon Also ignore lines that are source file reports. --- genbadge/utils_flake8.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/genbadge/utils_flake8.py b/genbadge/utils_flake8.py index c8c9af6..dbed78e 100644 --- a/genbadge/utils_flake8.py +++ b/genbadge/utils_flake8.py @@ -5,6 +5,7 @@ from __future__ import division from warnings import warn +import os import re from .utils_badge import Badge @@ -104,7 +105,8 @@ def get_flake8_stats(flake8_stats_file): return parse_flake8_stats(flake8_stats_txt) -RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+)\s.*") +RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+):*\s.*") +SOURCE_MATCH = re.compile(r"([^:]+):\d+:\s.*") def parse_flake8_stats(stats_txt # type: str @@ -115,7 +117,14 @@ def parse_flake8_stats(stats_txt # type: str for line in stats_txt.splitlines(): match = RE_TO_MATCH.match(line) if not match: - warn("Line in Flake8 statistics report does not match template and will be ignored: %r" % line) + smatch = SOURCE_MATCH.match(line) + if smatch: + source = smatch.groups() + if not os.path.exists(source): + warn("Source report line does not refer to file: %r" %line) + else: + # warn on lines that do not match stats or source report. + warn("Line in Flake8 statistics report does not match template and will be ignored: %r" % line) else: nb, code = match.groups() stats.add(int(nb), code) From 0762b68fcf8e2c4d24420c1995d5733d9e327acc Mon Sep 17 00:00:00 2001 From: Rick Nickle Date: Fri, 12 Nov 2021 20:44:25 -0500 Subject: [PATCH 2/3] Add extra field for column. --- genbadge/utils_flake8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genbadge/utils_flake8.py b/genbadge/utils_flake8.py index dbed78e..e83dc33 100644 --- a/genbadge/utils_flake8.py +++ b/genbadge/utils_flake8.py @@ -106,7 +106,7 @@ def get_flake8_stats(flake8_stats_file): RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+):*\s.*") -SOURCE_MATCH = re.compile(r"([^:]+):\d+:\s.*") +SOURCE_MATCH = re.compile(r"([^:]+):\d+:\d+:\s+.*") def parse_flake8_stats(stats_txt # type: str From 4cdda0cd824d856b29d03257f0b4071b78c293a7 Mon Sep 17 00:00:00 2001 From: Rick Nickle Date: Fri, 12 Nov 2021 21:00:55 -0500 Subject: [PATCH 3/3] Make sure group returns str not tuple --- genbadge/utils_flake8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genbadge/utils_flake8.py b/genbadge/utils_flake8.py index e83dc33..07ef7a4 100644 --- a/genbadge/utils_flake8.py +++ b/genbadge/utils_flake8.py @@ -119,7 +119,7 @@ def parse_flake8_stats(stats_txt # type: str if not match: smatch = SOURCE_MATCH.match(line) if smatch: - source = smatch.groups() + source = smatch.group(1) if not os.path.exists(source): warn("Source report line does not refer to file: %r" %line) else: