Skip to content

Commit 94f41d1

Browse files
authored
Merge pull request #11477 from QuLogic/flake8
CI: Enable flake8 and re-enable it everywhere
2 parents f7486e7 + 6123369 commit 94f41d1

32 files changed

+179
-179
lines changed

.flake8

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
[flake8]
2+
ignore =
3+
# Normal default
4+
E121,E123,E126,E226,E24,E704,W503,W504,
5+
# Additional ignores:
6+
E111, E114, E115, E116, E122, E124, E125, E127, E128, E129, E131,
7+
E265, E266,
8+
E305, E306,
9+
E722, E741,
10+
F401, F403, F811, F841,
11+
# Some new flake8 ignores:
12+
N801, N802, N803, N806, N812,
13+
14+
exclude =
15+
.git
16+
build
17+
# External files.
18+
versioneer.py
19+
tools/gh_api.py
20+
tools/github_stats.py
21+
22+
per-file-ignores =
23+
setup.py: E402
24+
setupext.py: E302, E501
25+
26+
tools/compare_backend_driver_results.py: E501
27+
tools/subset.py: E221, E231, E251, E261, E302, E501, E701
28+
29+
matplotlib/_cm.py: E202, E203
30+
matplotlib/_mathtext_data.py: E203, E261
31+
matplotlib/backend_bases.py: E225
32+
matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E401, E501, E701
33+
matplotlib/backends/backend_agg.py: E261, E302, E303, E701
34+
matplotlib/backends/backend_cairo.py: E203, E221, E261, E303, E402, E711
35+
matplotlib/backends/backend_gtk3.py: E203, E221, E222, E225, E251, E261, E501
36+
matplotlib/backends/backend_macosx.py: E231, E261
37+
matplotlib/backends/backend_pgf.py: E303, E731
38+
matplotlib/backends/backend_ps.py: E203, E225, E228, E231, E261, E262, E302, E303, E501, E701
39+
matplotlib/backends/backend_svg.py: E203, E225, E228, E231, E261, E302, E501
40+
matplotlib/backends/qt_editor/formlayout.py: E301, E501
41+
matplotlib/backends/tkagg.py: E231, E302, E701
42+
matplotlib/backends/windowing.py: E301, E302
43+
matplotlib/font_manager.py: E203, E221, E225, E251, E261, E262, E302, E501
44+
matplotlib/fontconfig_pattern.py: E201, E203, E221, E222, E225, E302
45+
matplotlib/legend_handler.py: E201, E501
46+
matplotlib/mathtext.py: E201, E202, E203, E211, E221, E222, E225, E231, E251, E261, E301, E302, E303, E402, E501
47+
matplotlib/patheffects.py: E231
48+
matplotlib/projections/geo.py: E203, E221, E231, E261, E502
49+
matplotlib/pylab.py: E501
50+
matplotlib/pyplot.py: E201, E202, E221, E222, E225, E231, E251, E261, E302, E501, E701
51+
matplotlib/rcsetup.py: E203, E225, E261, E302, E501
52+
matplotlib/sphinxext/mathmpl.py: E302
53+
matplotlib/sphinxext/only_directives.py: E302
54+
matplotlib/sphinxext/plot_directive.py: E261, E302, E402
55+
matplotlib/tests/test_image.py: E225, E231, E251, E302, E501
56+
matplotlib/tests/test_lines.py: E231, E261
57+
matplotlib/tests/test_mathtext.py: E261, E501
58+
matplotlib/transforms.py: E201, E202, E203, E501
59+
matplotlib/tri/triinterpolate.py: E201, E221
60+
matplotlib/type1font.py: E731
61+
62+
mpl_toolkits/__init__.py: E261
63+
mpl_toolkits/axes_grid/axes_divider.py: E501
64+
mpl_toolkits/axes_grid/axes_rgb.py: E302, E501
65+
mpl_toolkits/axes_grid1/axes_divider.py: E402, E501
66+
mpl_toolkits/axes_grid1/axes_grid.py: E225
67+
mpl_toolkits/axes_grid1/axes_rgb.py: E231
68+
mpl_toolkits/axes_grid1/axes_size.py: E261, E501
69+
mpl_toolkits/axes_grid1/colorbar.py: E225, E231, E261, E262, E302, E303, E501, E701
70+
mpl_toolkits/axes_grid1/inset_locator.py: E501
71+
mpl_toolkits/axes_grid1/mpl_axes.py: E303, E501
72+
mpl_toolkits/axes_grid1/parasite_axes.py: E225, E231, E302, E303, E501
73+
mpl_toolkits/axisartist/angle_helper.py: E201, E203, E221, E222, E225, E231, E251, E261, E262, E302, E303, E501
74+
mpl_toolkits/axisartist/axis_artist.py: E201, E202, E221, E225, E228, E231, E251, E261, E262, E302, E303, E402, E501, E701, E711
75+
mpl_toolkits/axisartist/axisline_style.py: E231, E261, E262, E302, E303
76+
mpl_toolkits/axisartist/axislines.py: E225, E231, E261, E303, E501
77+
mpl_toolkits/axisartist/clip_path.py: E225, E302, E303, E501
78+
mpl_toolkits/axisartist/floating_axes.py: E225, E231, E261, E262, E302, E303, E402, E501
79+
mpl_toolkits/axisartist/grid_finder.py: E231, E261, E302, E303, E402
80+
mpl_toolkits/axisartist/grid_helper_curvelinear.py: E225, E231, E261, E262, E271, E302, E303, E501
81+
mpl_toolkits/mplot3d/art3d.py: E203, E222, E225, E231
82+
mpl_toolkits/mplot3d/axes3d.py: E203, E231, E303, E402, E501, E701
83+
mpl_toolkits/mplot3d/axis3d.py: E231, E302
84+
mpl_toolkits/mplot3d/proj3d.py: E231, E302, E303
85+
mpl_toolkits/tests/test_axes_grid1.py: E201, E202
86+
mpl_toolkits/tests/test_mplot3d.py: E231, E302
87+
88+
doc/**: E302, E501
89+
doc/conf.py: E402
90+
tutorials/**: E402, E501
91+
92+
examples/**: E501, E402
93+
examples/images_contours_and_fields/tricontour_demo.py: E201
94+
examples/images_contours_and_fields/tripcolor_demo.py: E201
95+
examples/images_contours_and_fields/triplot_demo.py: E201
96+
examples/misc/table_demo.py: E201
97+
examples/pyplots/annotate_transform.py: E228, E251
98+
examples/pyplots/annotation_polar.py: E231
99+
examples/pyplots/auto_subplots_adjust.py: E231, E261, E302
100+
examples/pyplots/boxplot_demo_pyplot.py: E231
101+
examples/pyplots/compound_path_demo.py: E231
102+
examples/pyplots/fig_axes_customize_simple.py: E261
103+
examples/pyplots/pyplot_formatstr.py: E231
104+
examples/pyplots/pyplot_mathtext.py: E231
105+
examples/pyplots/pyplot_simple.py: E231
106+
examples/pyplots/pyplot_two_subplots.py: E302
107+
examples/pyplots/text_commands.py: E231
108+
examples/pyplots/text_layout.py: E231
109+
examples/pyplots/whats_new_98_4_fancy.py: E225, E261, E302
110+
examples/pyplots/whats_new_98_4_fill_between.py: E225
111+
examples/pyplots/whats_new_98_4_legend.py: E228
112+
examples/pyplots/whats_new_99_spines.py: E231, E261

.travis.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ env:
6464
- OPENBLAS_NUM_THREADS=1
6565
- PYTHONFAULTHANDLER=1
6666
- PYTEST_ADDOPTS="-rawR --maxfail=50 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
67-
- RUN_PEP8=
67+
- RUN_FLAKE8=
6868

6969
matrix:
7070
include:
@@ -78,8 +78,8 @@ matrix:
7878
- python: 3.6
7979
env:
8080
- DELETE_FONT_CACHE=1
81-
- PYTEST_ADDOPTS="$PYTEST_ADDOPTS --pep8"
8281
- EXTRAREQS='-r requirements/testing/travis36.txt'
82+
- RUN_FLAKE8=1
8383
- python: "nightly"
8484
env: PRE=--pre
8585
- os: osx
@@ -157,9 +157,14 @@ before_script: |
157157
rm -rf ~/.cache/matplotlib
158158
fi
159159
160-
script: |
161-
echo "Calling pytest with the following arguments: $PYTEST_ADDOPTS"
162-
python -mpytest
160+
script:
161+
- |
162+
echo "Calling pytest with the following arguments: $PYTEST_ADDOPTS"
163+
python -mpytest
164+
- |
165+
if [[ $RUN_FLAKE8 == 1 ]]; then
166+
flake8 --statistics && echo "Flake8 passed without any issues!"
167+
fi
163168
164169
before_cache: |
165170
rm -rf $HOME/.cache/matplotlib/tex.cache

doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def _check_deps():
9595
}
9696

9797

98-
9998
# Sphinx gallery configuration
10099
sphinx_gallery_conf = {
101100
'examples_dirs': ['../examples', '../tutorials'],
@@ -149,7 +148,6 @@ def _check_deps():
149148
'team; 2012 - 2018 The Matplotlib development team')
150149

151150

152-
153151
# The default replacements for |version| and |release|, also used in various
154152
# other places throughout the built documents.
155153
#

doc/sphinxext/gallery_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __call__(self, item):
6969
class MplExplicitSubOrder(object):
7070
""" for use within the 'within_subsection_order' key """
7171
def __init__(self, src_dir):
72-
self.src_dir = src_dir #src_dir is unused here
72+
self.src_dir = src_dir # src_dir is unused here
7373
self.ordered_list = explicit_subsection_order
7474

7575
def __call__(self, item):

doc/users/generate_credits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def check_duplicates():
6363
contributors = [line.split('\t', 1)[1].strip() for line in lines if line]
6464
emails = [re.match('.*<(.*)>', line).group(1) for line in contributors]
6565
email_counter = Counter(emails)
66-
66+
6767
if email_counter.most_common(1)[0][1] > 1:
6868
print('DUPLICATE CHECK: The following email addesses are used with more '
6969
'than one name.\nConsider adding them to .mailmap.\n')

examples/lines_bars_and_markers/marker_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def nice_repr(text):
3434

3535
def math_repr(text):
3636
tx = repr(text).lstrip('u').strip("'").strip("$")
37-
return "'\${}\$'".format(tx)
37+
return r"'\${}\$'".format(tx)
3838

3939

4040
def split_list(a_list):

examples/recipes/fill_between_alpha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
ax.plot(t, mu2, lw=2, label='mean population 2', color='yellow')
8282
ax.fill_between(t, mu1+sigma1, mu1-sigma1, facecolor='blue', alpha=0.5)
8383
ax.fill_between(t, mu2+sigma2, mu2-sigma2, facecolor='yellow', alpha=0.5)
84-
ax.set_title('random walkers empirical $\mu$ and $\pm \sigma$ interval')
84+
ax.set_title(r'random walkers empirical $\mu$ and $\pm \sigma$ interval')
8585
ax.legend(loc='upper left')
8686
ax.set_xlabel('num steps')
8787
ax.set_ylabel('position')

examples/recipes/placing_text_boxes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
mu = x.mean()
2121
median = np.median(x)
2222
sigma = x.std()
23-
textstr = '$\mu=%.2f$\n$\mathrm{median}=%.2f$\n$\sigma=%.2f$' % (mu, median, sigma)
23+
textstr = '\n'.join((
24+
r'$\mu=%.2f$' % (mu, ),
25+
r'$\mathrm{median}=%.2f$' % (median, ),
26+
r'$\sigma=%.2f$' % (sigma, )))
2427

2528
ax.hist(x, 50)
2629
# these are matplotlib.patch.Patch properties

examples/scales/power_norm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
axes[0, 0].hist2d(data[:, 0], data[:, 1], bins=100)
2626

2727
for ax, gamma in zip(axes.flat[1:], gammas):
28-
ax.set_title('Power law $(\gamma=%1.1f)$' % gamma)
28+
ax.set_title(r'Power law $(\gamma=%1.1f)$' % gamma)
2929
ax.hist2d(data[:, 0], data[:, 1],
3030
bins=100, norm=mcolors.PowerNorm(gamma))
3131

examples/text_labels_and_annotations/arrow_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
213213
coords = np.dot(orig_position, M) + [[x_pos, y_pos]]
214214
x, y = np.ravel(coords)
215215
orig_label = rate_labels[pair]
216-
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])
216+
label = r'$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])
217217

218218
plt.text(x, y, label, size=label_text_size, ha='center', va='center',
219219
color=labelcolor or fc)

examples/ticks_and_spines/spines_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# set ticks and tick labels
2323
ax.set_xlim((0, 2*np.pi))
2424
ax.set_xticks([0, np.pi, 2*np.pi])
25-
ax.set_xticklabels(['0', '$\pi$', '2$\pi$'])
25+
ax.set_xticklabels(['0', r'$\pi$', r'2$\pi$'])
2626
ax.set_ylim((-1.5, 1.5))
2727
ax.set_yticks([-1, 0, 1])
2828

examples/units/basic_units.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def __get__(self, obj, objtype=None):
2525

2626

2727
class TaggedValueMeta(type):
28-
def __init__(cls, name, bases, dict):
29-
for fn_name in cls._proxies:
28+
def __init__(self, name, bases, dict):
29+
for fn_name in self._proxies:
3030
try:
31-
dummy = getattr(cls, fn_name)
31+
dummy = getattr(self, fn_name)
3232
except AttributeError:
33-
setattr(cls, fn_name,
34-
ProxyDelegate(fn_name, cls._proxies[fn_name]))
33+
setattr(self, fn_name,
34+
ProxyDelegate(fn_name, self._proxies[fn_name]))
3535

3636

3737
class PassThroughProxy(object):

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def __getitem__(self, key):
918918
elif key in _deprecated_ignore_map:
919919
version, alt_key = _deprecated_ignore_map[key]
920920
cbook.warn_deprecated(
921-
version, key, obj_type, alternative=alt_key)
921+
version, key, obj_type="rcparam", alternative=alt_key)
922922
return dict.__getitem__(self, alt_key) if alt_key else None
923923

924924
elif key == 'examples.directory':

lib/matplotlib/gridspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import numpy as np
2121

2222
import matplotlib as mpl
23-
from matplotlib import _pylab_helpers, tight_layout, rcParams
23+
from matplotlib import _pylab_helpers, cbook, tight_layout, rcParams
2424
from matplotlib.transforms import Bbox
2525
import matplotlib._layoutbox as layoutbox
2626

lib/matplotlib/patches.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ class _Style(object):
18581858
where actual styles are declared as subclass of it, and it
18591859
provides some helper functions.
18601860
"""
1861-
def __new__(self, stylename, **kw):
1861+
def __new__(cls, stylename, **kw):
18621862
"""
18631863
return the instance of the subclass with the given style name.
18641864
"""
@@ -1869,7 +1869,7 @@ def __new__(self, stylename, **kw):
18691869
_list = stylename.replace(" ", "").split(",")
18701870
_name = _list[0].lower()
18711871
try:
1872-
_cls = self._style_list[_name]
1872+
_cls = cls._style_list[_name]
18731873
except KeyError:
18741874
raise ValueError("Unknown style : %s" % stylename)
18751875

@@ -1883,29 +1883,29 @@ def __new__(self, stylename, **kw):
18831883
return _cls(**_args)
18841884

18851885
@classmethod
1886-
def get_styles(klass):
1886+
def get_styles(cls):
18871887
"""
18881888
A class method which returns a dictionary of available styles.
18891889
"""
1890-
return klass._style_list
1890+
return cls._style_list
18911891

18921892
@classmethod
1893-
def pprint_styles(klass):
1893+
def pprint_styles(cls):
18941894
"""
18951895
A class method which returns a string of the available styles.
18961896
"""
1897-
return _pprint_styles(klass._style_list)
1897+
return _pprint_styles(cls._style_list)
18981898

18991899
@classmethod
1900-
def register(klass, name, style):
1900+
def register(cls, name, style):
19011901
"""
19021902
Register a new style.
19031903
"""
19041904

1905-
if not issubclass(style, klass._Base):
1905+
if not issubclass(style, cls._Base):
19061906
raise ValueError("%s must be a subclass of %s" % (style,
1907-
klass._Base))
1908-
klass._style_list[name] = style
1907+
cls._Base))
1908+
cls._style_list[name] = style
19091909

19101910

19111911
def _register_style(style_list, cls=None, *, name=None):

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def remove_coding(text):
340340
Remove the coding comment, which six.exec\_ doesn't like.
341341
"""
342342
cbook.warn_deprecated('3.0', name='remove_coding', removal='3.1')
343-
sub_re = re.compile("^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE)
343+
sub_re = re.compile(r"^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE)
344344
return sub_re.sub("", text)
345345

346346
#------------------------------------------------------------------------------

lib/matplotlib/tests/test_animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self, fps=None, codec=None, bitrate=None,
109109
pass
110110

111111
@classmethod
112-
def isAvailable(self):
112+
def isAvailable(cls):
113113
return True
114114

115115

lib/matplotlib/tests/test_font_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from matplotlib.font_manager import (
1010
findfont, FontProperties, fontManager, json_dump, json_load, get_font,
11-
get_fontconfig_fonts, is_opentype_cff_font, fontManager as fm)
11+
get_fontconfig_fonts, is_opentype_cff_font)
1212
from matplotlib import rc_context
1313

1414
has_fclist = shutil.which('fc-list') is not None
@@ -67,7 +67,7 @@ def test_otf():
6767
if os.path.exists(fname):
6868
assert is_opentype_cff_font(fname)
6969

70-
otf_files = [f for f in fm.ttffiles if 'otf' in f]
70+
otf_files = [f for f in fontManager.ttffiles if 'otf' in f]
7171
for f in otf_files:
7272
with open(f, 'rb') as fd:
7373
res = fd.read(4) == b'OTTO'

lib/matplotlib/tests/test_pickle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def test_complete():
111111

112112
def test_no_pyplot():
113113
# tests pickle-ability of a figure not created with pyplot
114-
from matplotlib.backends.backend_pdf import FigureCanvasPdf as fc
114+
from matplotlib.backends.backend_pdf import FigureCanvasPdf
115115
from matplotlib.figure import Figure
116116

117117
fig = Figure()
118-
_ = fc(fig)
118+
_ = FigureCanvasPdf(fig)
119119
ax = fig.add_subplot(1, 1, 1)
120120
ax.plot([1, 2, 3], [1, 2, 3])
121121
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)

0 commit comments

Comments
 (0)