Skip to content

Commit 5591438

Browse files
committed
switch to pycodestyle for automated PEP8 testing
1 parent ed01e57 commit 5591438

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
python -m pip install --upgrade pip
34-
python -m pip install flake8
34+
python -m pip install pycodestyle
3535
pip install .[all]
3636
- name: Unit tests
3737
if: ${{ matrix.os != 'ubuntu-latest' }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install dependencies
4949
run: |
5050
python -m pip install --upgrade pip
51-
python -m pip install flake8
51+
python -m pip install pycodestyle
5252
pip install .[all]
5353
- name: Unit tests
5454
if: ${{ matrix.os != 'ubuntu-latest' }}
@@ -76,7 +76,7 @@ jobs:
7676
run: |
7777
sudo apt-get install xclip xvfb
7878
python -m pip install --upgrade pip
79-
python -m pip install flake8 pytest pytest-cov
79+
python -m pip install pycodestyle pytest pytest-cov
8080
pip install .[all]
8181
- name: Run tests and collect coverage
8282
run: |

refinery/units/compression/lzo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class LZOFlags(IntFlag):
3131

3232

3333
class LZOMethod(IntEnum):
34-
M_LZO1X_1 = 1 # noqa
35-
M_LZO1X_1_15 = 2 # noqa
36-
M_LZO1X_999 = 3 # noqa
34+
M_LZO1X_1 = 1 # noqa
35+
M_LZO1X_1_15 = 2 # noqa
36+
M_LZO1X_999 = 3 # noqa
3737

3838

3939
class LZOChunk(Struct):

test/units/test_misc.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,44 @@ def test_link_loader_tb01(self):
9595
class TestMetaProperties(TestUnitBase):
9696

9797
def test_style_guide(self):
98-
from flake8.api import legacy as flake8
99-
from flake8.main.options import JobsArgument
100-
logging.StreamHandler.terminator = '\n '
98+
import pycodestyle
99+
100+
class RespectFlake8NoQA(pycodestyle.StandardReport):
101+
def error(self, lno, offset, text, check):
102+
for line in self.lines[:5]:
103+
_, _, noqa = line.partition('flake8:')
104+
if noqa.lstrip().startswith('noqa'):
105+
return
106+
line: str = self.lines[lno - 1]
107+
_, _, comment = line.partition('#')
108+
if comment.lower().strip().startswith('noqa'):
109+
return
110+
super().error(lno, offset, text, check)
111+
112+
stylez = pycodestyle.StyleGuide(
113+
ignore=[
114+
'E128', # A continuation line is under-indented for a visual indentation.
115+
'E203', # Colons should not have any space before them.
116+
'E701', # Multiple statements on one line (colon)
117+
'E704', # Multiple statements on one line (def)
118+
'W503', # Line break occurred before a binary operator
119+
'F722', # syntax error in forward annotation
120+
'F821', # undefined name
121+
'E261', # at least two spaces before inline comment
122+
],
123+
max_line_length=140,
124+
reporter=RespectFlake8NoQA,
125+
)
126+
101127
root = os.path.abspath(inspect.stack()[0][1])
102128
for _ in range(3):
103129
root = os.path.dirname(root)
104130

105-
rules = flake8.get_style_guide(ignore=[
106-
'E128', # A continuation line is under-indented for a visual indentation.
107-
'E203', # Colons should not have any space before them.
108-
'E701', # Multiple statements on one line (colon)
109-
'E704', # Multiple statements on one line (def)
110-
'W503', # Line break occurred before a binary operator
111-
'F722', # syntax error in forward annotation
112-
'F821', # undefined name
113-
'E261', # at least two spaces before inline comment
114-
], max_line_length=140, jobs=JobsArgument('1'))
115-
report = rules.check_files(path for path in glob(
131+
python_files = [path for path in glob(
116132
os.path.join(root, 'refinery', '**', '*.py'), recursive=True)
117-
if 'thirdparty' not in path
118-
)
119-
self.assertEqual(report.total_errors, 0,
120-
msg='Flake8 formatting errors were found.')
133+
if 'thirdparty' not in path]
134+
report = stylez.check_files(python_files)
135+
self.assertEqual(report.total_errors, 0, 'PEP8 formatting errors were found.')
121136

122137
def test_no_legacy_interfaces(self):
123138
for unit in get_all_entry_points():

0 commit comments

Comments
 (0)