Skip to content

Commit a4a750b

Browse files
committed
Consolidate in __init__.py
1 parent aca6fce commit a4a750b

File tree

5 files changed

+61
-89
lines changed

5 files changed

+61
-89
lines changed

.github/workflows/flake8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ jobs:
3030
python -m pip install .
3131
3232
- name: "Run Flake8"
33-
run: "python -m flake8_prettycount flake8_github_action --exit-zero"
33+
run: "python -m flake8_prettycount flake8_github_action --exit-zero --format github"
3434
env:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

flake8_github_action/__init__.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,66 @@
2626
# OR OTHER DEALINGS IN THE SOFTWARE.
2727
#
2828

29+
# stdlib
30+
from functools import partial
31+
from gettext import ngettext
32+
33+
# 3rd party
34+
from flake8.formatting.base import BaseFormatter # type: ignore
35+
2936
__author__: str = "Dominic Davis-Foster"
3037
__copyright__: str = "2020 Dominic Davis-Foster"
3138
__license__: str = "MIT License"
3239
__version__: str = "0.0.0"
3340
__email__: str = "dominic@davis-foster.co.uk"
41+
42+
__all__ = ["GitHubFormatter"]
43+
44+
_error = partial(ngettext, "error", "errors")
45+
_file = partial(ngettext, "file", "files")
46+
47+
48+
class GitHubFormatter(BaseFormatter):
49+
50+
def write_line(self, line):
51+
"""
52+
Override write for convenience.
53+
"""
54+
self.write(line, None)
55+
56+
def start(self):
57+
super().start()
58+
self.files_reported_count = 0
59+
60+
def beginning(self, filename):
61+
"""
62+
We're starting a new file.
63+
"""
64+
65+
self.reported_errors_count = 0
66+
67+
def finished(self, filename):
68+
"""
69+
We've finished processing a file.
70+
"""
71+
72+
self.files_reported_count += 1
73+
74+
def format(self, violation):
75+
"""
76+
Format a violation.
77+
"""
78+
79+
if self.reported_errors_count == 0:
80+
self.write_line(violation.filename)
81+
82+
self.write_line(
83+
f"::warning "
84+
f"file={violation.filename},line={violation.line_number},col={violation.column_number}"
85+
f"::{violation.code}: {violation.text}"
86+
)
87+
88+
self.reported_errors_count += 1
89+
90+
91+

flake8_github_action/reporters

Lines changed: 0 additions & 86 deletions
This file was deleted.

repo_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ keywords:
3030

3131
entry_points:
3232
flake8.report:
33-
- github = flake8_github_action.reporters:GitHubFormatter
33+
- github = flake8_github_action:GitHubFormatter

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ check_untyped_defs = True
4949
warn_unused_ignores = True
5050

5151
[options.entry_points]
52-
flake8.report = github = flake8_github_action.reporters:GitHubFormatter
52+
flake8.report = github = flake8_github_action:GitHubFormatter

0 commit comments

Comments
 (0)