Skip to content

Commit aca6fce

Browse files
committed
Refactor into just a flake8 formatter.
1 parent ab2d039 commit aca6fce

File tree

10 files changed

+100
-257
lines changed

10 files changed

+100
-257
lines changed

.github/workflows/flake8.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ jobs:
2626
python -VV
2727
python -m site
2828
python -m pip install --upgrade pip setuptools wheel
29+
python -m pip install flake8-prettycount
2930
python -m pip install .
3031
3132
- name: "Run Flake8"
32-
run: "python -m flake8_github_action flake8_github_action --exit-zero"
33+
run: "python -m flake8_prettycount flake8_github_action --exit-zero"
3334
env:
3435
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.isort.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ known_third_party =
2121
dulwich
2222
flake8
2323
flake8_json
24+
flake8_prettycount
2425
github
2526
github3_py
2627
requests

flake8_github_action/__init__.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# __init__.py
44
"""
5-
GitHub Action to run flake8.
5+
GitHub Actions integration for flake8.
66
"""
77
#
88
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
@@ -26,28 +26,8 @@
2626
# OR OTHER DEALINGS IN THE SOFTWARE.
2727
#
2828

29-
# 3rd party
30-
from typing_extensions import NoReturn
31-
32-
# this package
33-
from flake8_github_action.flake8_app import Application
34-
3529
__author__: str = "Dominic Davis-Foster"
3630
__copyright__: str = "2020 Dominic Davis-Foster"
3731
__license__: str = "MIT License"
3832
__version__: str = "0.0.0"
3933
__email__: str = "dominic@davis-foster.co.uk"
40-
41-
__all__ = ["action"]
42-
43-
44-
def action(*args, ) -> NoReturn:
45-
r"""
46-
Action!
47-
48-
:param \*args: flake8 command line arguments.
49-
"""
50-
51-
flake8_app = Application()
52-
flake8_app.run(args)
53-
flake8_app.exit()

flake8_github_action/__main__.py

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

flake8_github_action/flake8_app.py

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

flake8_github_action/reporters

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
#
3+
# flake8_app.py
4+
"""
5+
Subclass of Flake8's ``Application``.
6+
"""
7+
#
8+
# Copyright (c) 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
9+
#
10+
# Permission is hereby granted, free of charge, to any person obtaining a copy
11+
# of this software and associated documentation files (the "Software"), to deal
12+
# in the Software without restriction, including without limitation the rights
13+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
# copies of the Software, and to permit persons to whom the Software is
15+
# furnished to do so, subject to the following conditions:
16+
#
17+
# The above copyright notice and this permission notice shall be included in
18+
# all copies or substantial portions of the Software.
19+
#
20+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
# THE SOFTWARE.
27+
#
28+
# "GitHubFormatter" based on https://gitlab.com/pycqa/flake8-json
29+
# Copyright (C) 2017-2018 Ian Stapleton Cordasco <graffatcolmingov@gmail.com>
30+
# MIT Licensed
31+
#
32+
33+
# stdlib
34+
from functools import partial
35+
from gettext import ngettext
36+
37+
# 3rd party
38+
from flake8.formatting.base import BaseFormatter # type: ignore
39+
40+
__all__ = ["GitHubFormatter"]
41+
42+
_error = partial(ngettext, "error", "errors")
43+
_file = partial(ngettext, "file", "files")
44+
45+
46+
class GitHubFormatter(BaseFormatter):
47+
48+
def write_line(self, line):
49+
"""
50+
Override write for convenience.
51+
"""
52+
self.write(line, None)
53+
54+
def start(self):
55+
super().start()
56+
self.files_reported_count = 0
57+
58+
def beginning(self, filename):
59+
"""
60+
We're starting a new file.
61+
"""
62+
63+
self.reported_errors_count = 0
64+
65+
def finished(self, filename):
66+
"""
67+
We've finished processing a file.
68+
"""
69+
70+
self.files_reported_count += 1
71+
72+
def format(self, violation):
73+
"""
74+
Format a violation.
75+
"""
76+
77+
if self.reported_errors_count == 0:
78+
self.write_line(violation.filename)
79+
80+
self.write_line(
81+
f"::warning "
82+
f"file={violation.filename},line={violation.line_number},col={violation.column_number}"
83+
f"::{violation.code}: {violation.text}"
84+
)
85+
86+
self.reported_errors_count += 1

repo_helper.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ keywords:
2727
- flake8
2828
- github
2929
- github-actions
30+
31+
entry_points:
32+
flake8.report:
33+
- github = flake8_github_action.reporters:GitHubFormatter

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
click>=7.1.2
2-
consolekit>=0.6.0
31
flake8>=3.8.4
4-
typing-extensions>=3.7.4.3

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ python_version = 3.6
4747
namespace_packages = True
4848
check_untyped_defs = True
4949
warn_unused_ignores = True
50+
51+
[options.entry_points]
52+
flake8.report = github = flake8_github_action.reporters:GitHubFormatter

0 commit comments

Comments
 (0)