Skip to content

Commit 14878e3

Browse files
authored
Use setup.cfg to configure flake8, instead of in the ci code (#930)
This makes flake8's configuration more discoverable and easier to use with other tools (IDE, etc.).
1 parent 65c0a13 commit 14878e3

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

setup.cfg

+30
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,35 @@ markers =
77
linter
88
online
99

10+
[flake8]
11+
exclude =
12+
conf.py,
13+
.venv,
14+
ignore =
15+
# ignore presence of unnecessary generators
16+
C402,
17+
# ignore presence of unnecessary literals
18+
C405,
19+
# ignore presence of unnecessary comprehensions
20+
C407,
21+
# ignore presence of unnecessary tuple/list/dict
22+
C408,
23+
# ignore documentation related warnings
24+
D,
25+
# ignore presence of unused imports
26+
F401,
27+
# ignore presence of unused variables
28+
F841,
29+
# ignore import order related warnings
30+
I,
31+
# ignore presence of upper case in function names
32+
N802,
33+
# ignore line breaks after binary operator (new rule added in 2018)
34+
W504,
35+
max-line-length = 200
36+
# due to complexity not being enforced before, 26 is the minimum for not
37+
# throwing errors.
38+
max-complexity = 26
39+
1040
[coverage:run]
1141
source = rosdep2

test/test_flake8.py

+10-37
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,22 @@
1515
from __future__ import print_function
1616

1717
import os
18+
import subprocess
1819
import sys
1920

20-
from flake8.api.legacy import get_style_guide
2121
import pytest
2222

2323

2424
@pytest.mark.flake8
2525
@pytest.mark.linter
2626
def test_flake8():
27-
style_guide = get_style_guide(
28-
exclude=['conf.py'],
29-
ignore=[
30-
'C402', # ignore presence of unnecessary generators
31-
'C405', # ignore presence of unnecessary literals
32-
'C407', # ignore presence of unnecessary comprehensions
33-
'C408', # ignore presence of unnecessary tuple/list/dict
34-
'D', # ignore documentation related warnings
35-
'F401', # ignore presence of unused imports
36-
'F841', # ignore presence of unused variables
37-
'I', # ignore import order related warnings
38-
'N802', # ignore presence of upper case in function names
39-
'W504', # ignore line breaks after binary operator (new rule added in 2018)
40-
],
41-
max_line_length=200,
42-
max_complexity=10,
43-
show_source=True,
27+
# flake8 doesn't have a stable public API as of ver 6.1.0.
28+
# See: https://flake8.pycqa.org/en/latest/user/python-api.html
29+
# Calling through subprocess is the most stable way to run it.
30+
31+
# We still need to support Python 2.7, so we can't use run()
32+
ret_code = subprocess.call(
33+
[sys.executable, "-m", "flake8"],
34+
cwd=os.path.dirname(os.path.dirname(__file__)),
4435
)
45-
46-
stdout = sys.stdout
47-
sys.stdout = sys.stderr
48-
# implicitly calls report_errors()
49-
report = style_guide.check_files([
50-
os.path.dirname(os.path.dirname(__file__)),
51-
])
52-
sys.stdout = stdout
53-
54-
if report.total_errors:
55-
# output summary with per-category counts
56-
print()
57-
report._application.formatter.show_statistics(report._stats)
58-
print(
59-
'flake8 reported {report.total_errors} errors'
60-
.format(**locals()), file=sys.stderr)
61-
62-
assert not report.total_errors, \
63-
'flake8 reported {report.total_errors} errors'.format(**locals())
36+
assert 0 == ret_code, "flake8 found violations"

0 commit comments

Comments
 (0)