From cac3be2c2374a31c613d6a8e9a42dfb4b83615c3 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 2 Apr 2018 07:26:22 +0200 Subject: [PATCH 1/7] Run flake8 instead of pep8 on Python 3.6 As discussed at https://github.com/matplotlib/matplotlib/pull/10938#issuecomment-377855594 _undefined names_ have [occurred often in the past](https://github.com/matplotlib/matplotlib/pulls?q=is%3Apr+author%3Acclauss+is%3Aclosed) and this change would help to avoid recurrence in the future. --- .travis.yml | 5 ++--- pytest.ini | 4 ++-- requirements/testing/travis36.txt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59be49011f60..9ca5c96541ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,8 +63,7 @@ env: - NPROC=2 - OPENBLAS_NUM_THREADS=1 - PYTHONFAULTHANDLER=1 - - PYTEST_ADDOPTS="-rawR --maxfail=50 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC" - - RUN_PEP8= + - PYTEST_ADDOPTS="-rawR --maxfail=50 --timeout=350 --durations=25 --cov-report= --cov=lib -n $NPROC" matrix: include: @@ -78,7 +77,7 @@ matrix: - python: 3.6 env: - DELETE_FONT_CACHE=1 - - PYTEST_ADDOPTS="$PYTEST_ADDOPTS --pep8" + - PYTEST_ADDOPTS="$PYTEST_ADDOPTS --flake8" - EXTRAREQS='-r requirements/testing/travis36.txt' - python: "nightly" env: PRE=--pre diff --git a/pytest.ini b/pytest.ini index fd510238c86b..314d36c73815 100644 --- a/pytest.ini +++ b/pytest.ini @@ -7,8 +7,8 @@ markers = network: Mark a test that uses the network. style: Set alternate Matplotlib style temporarily. -pep8ignore = - * E111 E114 E115 E116 E121 E122 E123 E124 E125 E126 E127 E128 E129 E131 E226 E240 E241 E242 E243 E244 E245 E246 E247 E248 E249 E265 E266 E704 W503 +flake8-ignore = + * E111 E114 E115 E116 E121 E122 E123 E124 E125 E126 E127 E128 E129 E131 E226 E240 E241 E242 E243 E244 E245 E246 E247 E248 E249 E265 E266 E305 E306 E704 E722 E741 F401 F403 F811 F841 W503 setup.py E402 setupext.py E301 E302 E501 diff --git a/requirements/testing/travis36.txt b/requirements/testing/travis36.txt index 1b8dd3e3ff7b..f7fe1f5a6058 100644 --- a/requirements/testing/travis36.txt +++ b/requirements/testing/travis36.txt @@ -2,4 +2,4 @@ pandas<0.21.0 jupyter -pytest-pep8 +pytest-flake8 From 5e859f80892efe78cf3b6e93e3cfd193d5d6d913 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 Jul 2018 15:25:57 -0400 Subject: [PATCH 2/7] Fix undefined names. Fixes #11550. --- lib/matplotlib/__init__.py | 2 +- lib/matplotlib/gridspec.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 29fc2f1388db..28b0d63c3f0d 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -918,7 +918,7 @@ def __getitem__(self, key): elif key in _deprecated_ignore_map: version, alt_key = _deprecated_ignore_map[key] cbook.warn_deprecated( - version, key, obj_type, alternative=alt_key) + version, key, obj_type="rcparam", alternative=alt_key) return dict.__getitem__(self, alt_key) if alt_key else None elif key == 'examples.directory': diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index baaab83a217e..f85f061f0528 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -20,7 +20,7 @@ import numpy as np import matplotlib as mpl -from matplotlib import _pylab_helpers, tight_layout, rcParams +from matplotlib import _pylab_helpers, cbook, tight_layout, rcParams from matplotlib.transforms import Bbox import matplotlib._layoutbox as layoutbox From cdcb282521a26fafc2565285f997365b242d3b80 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 Jul 2018 15:38:03 -0400 Subject: [PATCH 3/7] STY: Fix some whitespace issues. --- doc/conf.py | 2 -- doc/sphinxext/gallery_order.py | 2 +- doc/users/generate_credits.py | 2 +- setupext.py | 4 ++-- tools/memleak.py | 1 - tutorials/intermediate/constrainedlayout_guide.py | 2 +- tutorials/intermediate/tight_layout_guide.py | 4 ++-- 7 files changed, 7 insertions(+), 10 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 9275fcc2b7b3..8e9e7134a8e9 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -95,7 +95,6 @@ def _check_deps(): } - # Sphinx gallery configuration sphinx_gallery_conf = { 'examples_dirs': ['../examples', '../tutorials'], @@ -149,7 +148,6 @@ def _check_deps(): 'team; 2012 - 2018 The Matplotlib development team') - # The default replacements for |version| and |release|, also used in various # other places throughout the built documents. # diff --git a/doc/sphinxext/gallery_order.py b/doc/sphinxext/gallery_order.py index 06f6c207ce2d..40c9b82be61c 100644 --- a/doc/sphinxext/gallery_order.py +++ b/doc/sphinxext/gallery_order.py @@ -69,7 +69,7 @@ def __call__(self, item): class MplExplicitSubOrder(object): """ for use within the 'within_subsection_order' key """ def __init__(self, src_dir): - self.src_dir = src_dir #src_dir is unused here + self.src_dir = src_dir # src_dir is unused here self.ordered_list = explicit_subsection_order def __call__(self, item): diff --git a/doc/users/generate_credits.py b/doc/users/generate_credits.py index ae48a4ff87c9..a81d9c5cb8f7 100755 --- a/doc/users/generate_credits.py +++ b/doc/users/generate_credits.py @@ -63,7 +63,7 @@ def check_duplicates(): contributors = [line.split('\t', 1)[1].strip() for line in lines if line] emails = [re.match('.*<(.*)>', line).group(1) for line in contributors] email_counter = Counter(emails) - + if email_counter.most_common(1)[0][1] > 1: print('DUPLICATE CHECK: The following email addesses are used with more ' 'than one name.\nConsider adding them to .mailmap.\n') diff --git a/setupext.py b/setupext.py index fbf8a8f599c6..ce1d807c9c60 100644 --- a/setupext.py +++ b/setupext.py @@ -1115,8 +1115,8 @@ def do_custom_build(self): if sys.platform != 'win32': # compilation on all other platforms than windows - env={**os.environ, - "CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))} + env = {**os.environ, + "CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))} subprocess.check_call( ["./configure", "--with-zlib=no", "--with-bzip2=no", "--with-png=no", "--with-harfbuzz=no"], diff --git a/tools/memleak.py b/tools/memleak.py index 32af8d0d8176..df86ea4ce08b 100755 --- a/tools/memleak.py +++ b/tools/memleak.py @@ -127,7 +127,6 @@ def __call__(self): help="Turn on interactive mode to actually open " "windows. Only works with some GUI backends.") - args = parser.parse_args() import matplotlib diff --git a/tutorials/intermediate/constrainedlayout_guide.py b/tutorials/intermediate/constrainedlayout_guide.py index 74e5e13d4abf..179b520761c3 100644 --- a/tutorials/intermediate/constrainedlayout_guide.py +++ b/tutorials/intermediate/constrainedlayout_guide.py @@ -126,7 +126,7 @@ def example_plot(ax, fontsize=12, nodec=False): arr = np.arange(100).reshape((10, 10)) norm = mcolors.Normalize(vmin=0., vmax=100.) # see note above: this makes all pcolormesh calls consistent: -pc_kwargs = {'rasterized':True, 'cmap':'viridis', 'norm':norm} +pc_kwargs = {'rasterized': True, 'cmap': 'viridis', 'norm': norm} fig, ax = plt.subplots(figsize=(4, 4), constrained_layout=True) im = ax.pcolormesh(arr, **pc_kwargs) fig.colorbar(im, ax=ax, shrink=0.6) diff --git a/tutorials/intermediate/tight_layout_guide.py b/tutorials/intermediate/tight_layout_guide.py index b31b65ae4788..333333bda7c1 100644 --- a/tutorials/intermediate/tight_layout_guide.py +++ b/tutorials/intermediate/tight_layout_guide.py @@ -10,8 +10,8 @@ feature and may not work for some cases. It only checks the extents of ticklabels, axis labels, and titles. -An alternative to *tight_layout* is -:doc:`constrained_layout`. +An alternative to *tight_layout* is :doc:`constrained_layout +`. Simple Example From 34d8eb2adc8dec8cb7542c24a587e567921df5e7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 Jul 2018 16:29:43 -0400 Subject: [PATCH 4/7] Use raw strings to avoid invalid escape sequences. --- examples/lines_bars_and_markers/marker_reference.py | 2 +- examples/recipes/fill_between_alpha.py | 2 +- examples/recipes/placing_text_boxes.py | 5 ++++- examples/scales/power_norm.py | 2 +- examples/text_labels_and_annotations/arrow_demo.py | 2 +- examples/ticks_and_spines/spines_bounds.py | 2 +- lib/matplotlib/sphinxext/plot_directive.py | 2 +- tests.py | 2 +- tutorials/text/annotations.py | 2 +- tutorials/text/pgf.py | 2 +- tutorials/text/usetex.py | 2 +- tutorials/toolkits/axes_grid.py | 2 +- tutorials/toolkits/axisartist.py | 2 +- 13 files changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/lines_bars_and_markers/marker_reference.py b/examples/lines_bars_and_markers/marker_reference.py index 829557c4647a..c275f5d503f5 100644 --- a/examples/lines_bars_and_markers/marker_reference.py +++ b/examples/lines_bars_and_markers/marker_reference.py @@ -34,7 +34,7 @@ def nice_repr(text): def math_repr(text): tx = repr(text).lstrip('u').strip("'").strip("$") - return "'\${}\$'".format(tx) + return r"'\${}\$'".format(tx) def split_list(a_list): diff --git a/examples/recipes/fill_between_alpha.py b/examples/recipes/fill_between_alpha.py index ec004af3b031..dc0eaaf9326d 100644 --- a/examples/recipes/fill_between_alpha.py +++ b/examples/recipes/fill_between_alpha.py @@ -81,7 +81,7 @@ ax.plot(t, mu2, lw=2, label='mean population 2', color='yellow') ax.fill_between(t, mu1+sigma1, mu1-sigma1, facecolor='blue', alpha=0.5) ax.fill_between(t, mu2+sigma2, mu2-sigma2, facecolor='yellow', alpha=0.5) -ax.set_title('random walkers empirical $\mu$ and $\pm \sigma$ interval') +ax.set_title(r'random walkers empirical $\mu$ and $\pm \sigma$ interval') ax.legend(loc='upper left') ax.set_xlabel('num steps') ax.set_ylabel('position') diff --git a/examples/recipes/placing_text_boxes.py b/examples/recipes/placing_text_boxes.py index 51a6c143742f..ef64337f0075 100644 --- a/examples/recipes/placing_text_boxes.py +++ b/examples/recipes/placing_text_boxes.py @@ -20,7 +20,10 @@ mu = x.mean() median = np.median(x) sigma = x.std() -textstr = '$\mu=%.2f$\n$\mathrm{median}=%.2f$\n$\sigma=%.2f$' % (mu, median, sigma) +textstr = '\n'.join(( + r'$\mu=%.2f$' % (mu, ), + r'$\mathrm{median}=%.2f$' % (median, ), + r'$\sigma=%.2f$' % (sigma, ))) ax.hist(x, 50) # these are matplotlib.patch.Patch properties diff --git a/examples/scales/power_norm.py b/examples/scales/power_norm.py index e22cc590e181..25db8bd2834a 100644 --- a/examples/scales/power_norm.py +++ b/examples/scales/power_norm.py @@ -25,7 +25,7 @@ axes[0, 0].hist2d(data[:, 0], data[:, 1], bins=100) for ax, gamma in zip(axes.flat[1:], gammas): - ax.set_title('Power law $(\gamma=%1.1f)$' % gamma) + ax.set_title(r'Power law $(\gamma=%1.1f)$' % gamma) ax.hist2d(data[:, 0], data[:, 1], bins=100, norm=mcolors.PowerNorm(gamma)) diff --git a/examples/text_labels_and_annotations/arrow_demo.py b/examples/text_labels_and_annotations/arrow_demo.py index 00d4a57f6fc0..49b07205d0c8 100644 --- a/examples/text_labels_and_annotations/arrow_demo.py +++ b/examples/text_labels_and_annotations/arrow_demo.py @@ -213,7 +213,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): coords = np.dot(orig_position, M) + [[x_pos, y_pos]] x, y = np.ravel(coords) orig_label = rate_labels[pair] - label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:]) + label = r'$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:]) plt.text(x, y, label, size=label_text_size, ha='center', va='center', color=labelcolor or fc) diff --git a/examples/ticks_and_spines/spines_bounds.py b/examples/ticks_and_spines/spines_bounds.py index fd66eb5612bd..be4f9935e281 100644 --- a/examples/ticks_and_spines/spines_bounds.py +++ b/examples/ticks_and_spines/spines_bounds.py @@ -22,7 +22,7 @@ # set ticks and tick labels ax.set_xlim((0, 2*np.pi)) ax.set_xticks([0, np.pi, 2*np.pi]) -ax.set_xticklabels(['0', '$\pi$', '2$\pi$']) +ax.set_xticklabels(['0', r'$\pi$', r'2$\pi$']) ax.set_ylim((-1.5, 1.5)) ax.set_yticks([-1, 0, 1]) diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index da081d00b2e4..92d094d0410a 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -340,7 +340,7 @@ def remove_coding(text): Remove the coding comment, which six.exec\_ doesn't like. """ cbook.warn_deprecated('3.0', name='remove_coding', removal='3.1') - sub_re = re.compile("^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE) + sub_re = re.compile(r"^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE) return sub_re.sub("", text) #------------------------------------------------------------------------------ diff --git a/tests.py b/tests.py index 5817b6c0a9ee..f09e10be04b2 100755 --- a/tests.py +++ b/tests.py @@ -33,7 +33,7 @@ category=DeprecationWarning) warnings.filterwarnings( 'default', - '.*inspect.getargspec\(\) is deprecated.*', + r'.*inspect.getargspec\(\) is deprecated.*', category=DeprecationWarning) from matplotlib import test diff --git a/tutorials/text/annotations.py b/tutorials/text/annotations.py index 43f26648b2f8..945460b0bd9e 100644 --- a/tutorials/text/annotations.py +++ b/tutorials/text/annotations.py @@ -1,4 +1,4 @@ -""" +r""" Annotations =========== diff --git a/tutorials/text/pgf.py b/tutorials/text/pgf.py index ec71c58281c1..31b413d065a8 100644 --- a/tutorials/text/pgf.py +++ b/tutorials/text/pgf.py @@ -1,4 +1,4 @@ -""" +r""" ********************************* Typesetting With XeLaTeX/LuaLaTeX ********************************* diff --git a/tutorials/text/usetex.py b/tutorials/text/usetex.py index 78808be4acbb..1af699dc4224 100644 --- a/tutorials/text/usetex.py +++ b/tutorials/text/usetex.py @@ -1,4 +1,4 @@ -""" +r""" ************************* Text rendering With LaTeX ************************* diff --git a/tutorials/toolkits/axes_grid.py b/tutorials/toolkits/axes_grid.py index a5e8072a9301..55645da3efb5 100644 --- a/tutorials/toolkits/axes_grid.py +++ b/tutorials/toolkits/axes_grid.py @@ -1,4 +1,4 @@ -""" +r""" ============================== Overview of axes_grid1 toolkit ============================== diff --git a/tutorials/toolkits/axisartist.py b/tutorials/toolkits/axisartist.py index f32d81bab0d4..9465ab02551a 100644 --- a/tutorials/toolkits/axisartist.py +++ b/tutorials/toolkits/axisartist.py @@ -1,4 +1,4 @@ -""" +r""" ============================== Overview of axisartist toolkit ============================== From 99a6b8ac7d1c9ffd38fd255c17860281a0c5e1c0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 Jul 2018 16:46:05 -0400 Subject: [PATCH 5/7] STY: Use consistent (class)method parameter names. --- examples/units/basic_units.py | 10 +++++----- lib/matplotlib/patches.py | 20 ++++++++++---------- lib/matplotlib/tests/test_animation.py | 2 +- lib/mpl_toolkits/axes_grid1/axes_size.py | 16 ++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index ed6990e1aa40..826f543e9c3d 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -25,13 +25,13 @@ def __get__(self, obj, objtype=None): class TaggedValueMeta(type): - def __init__(cls, name, bases, dict): - for fn_name in cls._proxies: + def __init__(self, name, bases, dict): + for fn_name in self._proxies: try: - dummy = getattr(cls, fn_name) + dummy = getattr(self, fn_name) except AttributeError: - setattr(cls, fn_name, - ProxyDelegate(fn_name, cls._proxies[fn_name])) + setattr(self, fn_name, + ProxyDelegate(fn_name, self._proxies[fn_name])) class PassThroughProxy(object): diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index d38676382eac..ed941afc6d38 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1858,7 +1858,7 @@ class _Style(object): where actual styles are declared as subclass of it, and it provides some helper functions. """ - def __new__(self, stylename, **kw): + def __new__(cls, stylename, **kw): """ return the instance of the subclass with the given style name. """ @@ -1869,7 +1869,7 @@ def __new__(self, stylename, **kw): _list = stylename.replace(" ", "").split(",") _name = _list[0].lower() try: - _cls = self._style_list[_name] + _cls = cls._style_list[_name] except KeyError: raise ValueError("Unknown style : %s" % stylename) @@ -1883,29 +1883,29 @@ def __new__(self, stylename, **kw): return _cls(**_args) @classmethod - def get_styles(klass): + def get_styles(cls): """ A class method which returns a dictionary of available styles. """ - return klass._style_list + return cls._style_list @classmethod - def pprint_styles(klass): + def pprint_styles(cls): """ A class method which returns a string of the available styles. """ - return _pprint_styles(klass._style_list) + return _pprint_styles(cls._style_list) @classmethod - def register(klass, name, style): + def register(cls, name, style): """ Register a new style. """ - if not issubclass(style, klass._Base): + if not issubclass(style, cls._Base): raise ValueError("%s must be a subclass of %s" % (style, - klass._Base)) - klass._style_list[name] = style + cls._Base)) + cls._style_list[name] = style def _register_style(style_list, cls=None, *, name=None): diff --git a/lib/matplotlib/tests/test_animation.py b/lib/matplotlib/tests/test_animation.py index 4e77883b732e..54bca6d3553a 100644 --- a/lib/matplotlib/tests/test_animation.py +++ b/lib/matplotlib/tests/test_animation.py @@ -109,7 +109,7 @@ def __init__(self, fps=None, codec=None, bitrate=None, pass @classmethod - def isAvailable(self): + def isAvailable(cls): return True diff --git a/lib/mpl_toolkits/axes_grid1/axes_size.py b/lib/mpl_toolkits/axes_grid1/axes_size.py index 74df33256c6c..64558e3393fa 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_size.py +++ b/lib/mpl_toolkits/axes_grid1/axes_size.py @@ -290,17 +290,17 @@ def get_size(self, renderer): class GetExtentHelper(object): - def _get_left(tight_bbox, axes_bbox): - return axes_bbox.xmin - tight_bbox.xmin + def _get_left(self, axes_bbox): + return axes_bbox.xmin - self.xmin - def _get_right(tight_bbox, axes_bbox): - return tight_bbox.xmax - axes_bbox.xmax + def _get_right(self, axes_bbox): + return self.xmax - axes_bbox.xmax - def _get_bottom(tight_bbox, axes_bbox): - return axes_bbox.ymin - tight_bbox.ymin + def _get_bottom(self, axes_bbox): + return axes_bbox.ymin - self.ymin - def _get_top(tight_bbox, axes_bbox): - return tight_bbox.ymax - axes_bbox.ymax + def _get_top(self, axes_bbox): + return self.ymax - axes_bbox.ymax _get_func_map = dict(left=_get_left, right=_get_right, From d09bfdff6fc71c302ca6e3317cb1dd2ca29ca375 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 Jul 2018 16:48:51 -0400 Subject: [PATCH 6/7] STY: Fix N813 camelcase imported as lowercase. --- lib/matplotlib/tests/test_font_manager.py | 4 ++-- lib/matplotlib/tests/test_pickle.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 84186c0f176a..703a4e6e3359 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -8,7 +8,7 @@ from matplotlib.font_manager import ( findfont, FontProperties, fontManager, json_dump, json_load, get_font, - get_fontconfig_fonts, is_opentype_cff_font, fontManager as fm) + get_fontconfig_fonts, is_opentype_cff_font) from matplotlib import rc_context has_fclist = shutil.which('fc-list') is not None @@ -67,7 +67,7 @@ def test_otf(): if os.path.exists(fname): assert is_opentype_cff_font(fname) - otf_files = [f for f in fm.ttffiles if 'otf' in f] + otf_files = [f for f in fontManager.ttffiles if 'otf' in f] for f in otf_files: with open(f, 'rb') as fd: res = fd.read(4) == b'OTTO' diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 1ba2e097181e..029fd8bd37e6 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -111,11 +111,11 @@ def test_complete(): def test_no_pyplot(): # tests pickle-ability of a figure not created with pyplot - from matplotlib.backends.backend_pdf import FigureCanvasPdf as fc + from matplotlib.backends.backend_pdf import FigureCanvasPdf from matplotlib.figure import Figure fig = Figure() - _ = fc(fig) + _ = FigureCanvasPdf(fig) ax = fig.add_subplot(1, 1, 1) ax.plot([1, 2, 3], [1, 2, 3]) pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL) From 6123369893c53b984d378a63f99f4458ec63294b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 Jul 2018 13:44:14 -0400 Subject: [PATCH 7/7] TST: Run flake8 outside of pytest. --- .flake8 | 112 ++++++++++++++++++++++++++++ .travis.yml | 16 ++-- pytest.ini | 120 +----------------------------- requirements/testing/travis36.txt | 5 +- 4 files changed, 127 insertions(+), 126 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000000..0c9fcd3fc117 --- /dev/null +++ b/.flake8 @@ -0,0 +1,112 @@ +[flake8] +ignore = + # Normal default + E121,E123,E126,E226,E24,E704,W503,W504, + # Additional ignores: + E111, E114, E115, E116, E122, E124, E125, E127, E128, E129, E131, + E265, E266, + E305, E306, + E722, E741, + F401, F403, F811, F841, + # Some new flake8 ignores: + N801, N802, N803, N806, N812, + +exclude = + .git + build + # External files. + versioneer.py + tools/gh_api.py + tools/github_stats.py + +per-file-ignores = + setup.py: E402 + setupext.py: E302, E501 + + tools/compare_backend_driver_results.py: E501 + tools/subset.py: E221, E231, E251, E261, E302, E501, E701 + + matplotlib/_cm.py: E202, E203 + matplotlib/_mathtext_data.py: E203, E261 + matplotlib/backend_bases.py: E225 + matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E401, E501, E701 + matplotlib/backends/backend_agg.py: E261, E302, E303, E701 + matplotlib/backends/backend_cairo.py: E203, E221, E261, E303, E402, E711 + matplotlib/backends/backend_gtk3.py: E203, E221, E222, E225, E251, E261, E501 + matplotlib/backends/backend_macosx.py: E231, E261 + matplotlib/backends/backend_pgf.py: E303, E731 + matplotlib/backends/backend_ps.py: E203, E225, E228, E231, E261, E262, E302, E303, E501, E701 + matplotlib/backends/backend_svg.py: E203, E225, E228, E231, E261, E302, E501 + matplotlib/backends/qt_editor/formlayout.py: E301, E501 + matplotlib/backends/tkagg.py: E231, E302, E701 + matplotlib/backends/windowing.py: E301, E302 + matplotlib/font_manager.py: E203, E221, E225, E251, E261, E262, E302, E501 + matplotlib/fontconfig_pattern.py: E201, E203, E221, E222, E225, E302 + matplotlib/legend_handler.py: E201, E501 + matplotlib/mathtext.py: E201, E202, E203, E211, E221, E222, E225, E231, E251, E261, E301, E302, E303, E402, E501 + matplotlib/patheffects.py: E231 + matplotlib/projections/geo.py: E203, E221, E231, E261, E502 + matplotlib/pylab.py: E501 + matplotlib/pyplot.py: E201, E202, E221, E222, E225, E231, E251, E261, E302, E501, E701 + matplotlib/rcsetup.py: E203, E225, E261, E302, E501 + matplotlib/sphinxext/mathmpl.py: E302 + matplotlib/sphinxext/only_directives.py: E302 + matplotlib/sphinxext/plot_directive.py: E261, E302, E402 + matplotlib/tests/test_image.py: E225, E231, E251, E302, E501 + matplotlib/tests/test_lines.py: E231, E261 + matplotlib/tests/test_mathtext.py: E261, E501 + matplotlib/transforms.py: E201, E202, E203, E501 + matplotlib/tri/triinterpolate.py: E201, E221 + matplotlib/type1font.py: E731 + + mpl_toolkits/__init__.py: E261 + mpl_toolkits/axes_grid/axes_divider.py: E501 + mpl_toolkits/axes_grid/axes_rgb.py: E302, E501 + mpl_toolkits/axes_grid1/axes_divider.py: E402, E501 + mpl_toolkits/axes_grid1/axes_grid.py: E225 + mpl_toolkits/axes_grid1/axes_rgb.py: E231 + mpl_toolkits/axes_grid1/axes_size.py: E261, E501 + mpl_toolkits/axes_grid1/colorbar.py: E225, E231, E261, E262, E302, E303, E501, E701 + mpl_toolkits/axes_grid1/inset_locator.py: E501 + mpl_toolkits/axes_grid1/mpl_axes.py: E303, E501 + mpl_toolkits/axes_grid1/parasite_axes.py: E225, E231, E302, E303, E501 + mpl_toolkits/axisartist/angle_helper.py: E201, E203, E221, E222, E225, E231, E251, E261, E262, E302, E303, E501 + mpl_toolkits/axisartist/axis_artist.py: E201, E202, E221, E225, E228, E231, E251, E261, E262, E302, E303, E402, E501, E701, E711 + mpl_toolkits/axisartist/axisline_style.py: E231, E261, E262, E302, E303 + mpl_toolkits/axisartist/axislines.py: E225, E231, E261, E303, E501 + mpl_toolkits/axisartist/clip_path.py: E225, E302, E303, E501 + mpl_toolkits/axisartist/floating_axes.py: E225, E231, E261, E262, E302, E303, E402, E501 + mpl_toolkits/axisartist/grid_finder.py: E231, E261, E302, E303, E402 + mpl_toolkits/axisartist/grid_helper_curvelinear.py: E225, E231, E261, E262, E271, E302, E303, E501 + mpl_toolkits/mplot3d/art3d.py: E203, E222, E225, E231 + mpl_toolkits/mplot3d/axes3d.py: E203, E231, E303, E402, E501, E701 + mpl_toolkits/mplot3d/axis3d.py: E231, E302 + mpl_toolkits/mplot3d/proj3d.py: E231, E302, E303 + mpl_toolkits/tests/test_axes_grid1.py: E201, E202 + mpl_toolkits/tests/test_mplot3d.py: E231, E302 + + doc/**: E302, E501 + doc/conf.py: E402 + tutorials/**: E402, E501 + + examples/**: E501, E402 + examples/images_contours_and_fields/tricontour_demo.py: E201 + examples/images_contours_and_fields/tripcolor_demo.py: E201 + examples/images_contours_and_fields/triplot_demo.py: E201 + examples/misc/table_demo.py: E201 + examples/pyplots/annotate_transform.py: E228, E251 + examples/pyplots/annotation_polar.py: E231 + examples/pyplots/auto_subplots_adjust.py: E231, E261, E302 + examples/pyplots/boxplot_demo_pyplot.py: E231 + examples/pyplots/compound_path_demo.py: E231 + examples/pyplots/fig_axes_customize_simple.py: E261 + examples/pyplots/pyplot_formatstr.py: E231 + examples/pyplots/pyplot_mathtext.py: E231 + examples/pyplots/pyplot_simple.py: E231 + examples/pyplots/pyplot_two_subplots.py: E302 + examples/pyplots/text_commands.py: E231 + examples/pyplots/text_layout.py: E231 + examples/pyplots/whats_new_98_4_fancy.py: E225, E261, E302 + examples/pyplots/whats_new_98_4_fill_between.py: E225 + examples/pyplots/whats_new_98_4_legend.py: E228 + examples/pyplots/whats_new_99_spines.py: E231, E261 diff --git a/.travis.yml b/.travis.yml index 9ca5c96541ca..bb928ebd2599 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,8 @@ env: - NPROC=2 - OPENBLAS_NUM_THREADS=1 - PYTHONFAULTHANDLER=1 - - PYTEST_ADDOPTS="-rawR --maxfail=50 --timeout=350 --durations=25 --cov-report= --cov=lib -n $NPROC" + - PYTEST_ADDOPTS="-rawR --maxfail=50 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC" + - RUN_FLAKE8= matrix: include: @@ -77,8 +78,8 @@ matrix: - python: 3.6 env: - DELETE_FONT_CACHE=1 - - PYTEST_ADDOPTS="$PYTEST_ADDOPTS --flake8" - EXTRAREQS='-r requirements/testing/travis36.txt' + - RUN_FLAKE8=1 - python: "nightly" env: PRE=--pre - os: osx @@ -156,9 +157,14 @@ before_script: | rm -rf ~/.cache/matplotlib fi -script: | - echo "Calling pytest with the following arguments: $PYTEST_ADDOPTS" - python -mpytest +script: + - | + echo "Calling pytest with the following arguments: $PYTEST_ADDOPTS" + python -mpytest + - | + if [[ $RUN_FLAKE8 == 1 ]]; then + flake8 --statistics && echo "Flake8 passed without any issues!" + fi before_cache: | rm -rf $HOME/.cache/matplotlib/tex.cache diff --git a/pytest.ini b/pytest.ini index 314d36c73815..fdad48c2e92f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,126 +1,8 @@ [pytest] -testpaths = lib examples +testpaths = lib python_files = test_*.py markers = backend: Set alternate Matplotlib backend temporarily. network: Mark a test that uses the network. style: Set alternate Matplotlib style temporarily. - -flake8-ignore = - * E111 E114 E115 E116 E121 E122 E123 E124 E125 E126 E127 E128 E129 E131 E226 E240 E241 E242 E243 E244 E245 E246 E247 E248 E249 E265 E266 E305 E306 E704 E722 E741 F401 F403 F811 F841 W503 - - setup.py E402 - setupext.py E301 E302 E501 - - versioneer.py ALL # External file. - tools/gh_api.py ALL # External file. - tools/github_stats.py ALL # External file. - - tools/subset.py E221 E231 E251 E261 E302 E501 E701 E703 - - matplotlib/backends/qt_editor/formlayout.py E301 E402 E501 - matplotlib/backends/backend_agg.py E225 E228 E231 E261 E301 E302 E303 E701 - matplotlib/backends/backend_cairo.py E203 E211 E221 E231 E261 E272 E302 E303 E401 E402 E701 E711 - matplotlib/backends/backend_gtk3.py E201 E202 E203 E211 E221 E222 E225 E231 E251 E261 E262 E301 E302 E401 E402 E501 E701 - matplotlib/backends/backend_macosx.py E222 E225 E231 E261 E701 E711 - matplotlib/backends/backend_pgf.py E261 E302 E303 E731 - matplotlib/backends/backend_ps.py E202 E203 E225 E228 E231 E261 E262 E271 E301 E302 E303 E401 E402 E501 E701 - matplotlib/backends/backend_svg.py E203 E221 E225 E228 E231 E261 E302 E401 E501 - matplotlib/backends/backend_template.py E302 E303 - matplotlib/backends/_backend_tk.py E201 E202 E203 E222 E225 E231 E251 E271 E301 E302 E303 E401 E501 E701 W293 - matplotlib/backends/tkagg.py E231 E302 E701 - matplotlib/backends/windowing.py E301 E302 - matplotlib/backend_bases.py E225 E712 - matplotlib/projections/__init__.py E302 - matplotlib/projections/geo.py E203 E221 E231 E261 E302 E402 E502 - matplotlib/sphinxext/mathmpl.py E302 - matplotlib/sphinxext/only_directives.py E302 - matplotlib/sphinxext/plot_directive.py E261 E301 E302 E401 E402 - matplotlib/testing/decorators.py E301 E303 - matplotlib/testing/jpl_units/__init__.py E201 E202 E302 - matplotlib/testing/jpl_units/Duration.py E201 E202 E302 - matplotlib/testing/jpl_units/Epoch.py E201 E202 E203 E302 E501 - matplotlib/testing/jpl_units/EpochConverter.py E201 E202 E251 E302 E711 - matplotlib/testing/jpl_units/StrConverter.py E201 E202 E221 E302 E303 - matplotlib/testing/jpl_units/UnitDbl.py E201 E202 E203 - matplotlib/testing/jpl_units/UnitDblConverter.py E201 E202 E203 E251 E302 E711 - matplotlib/testing/jpl_units/UnitDblFormatter.py E201 E202 E251 E302 - matplotlib/tests/test_image.py E225 E231 E251 E302 E303 E501 - matplotlib/tests/test_lines.py E231 E261 - matplotlib/tests/test_mathtext.py E261 E302 E501 - matplotlib/tri/triinterpolate.py E201 E221 - matplotlib/_cm.py E101 E202 E203 W191 - matplotlib/_mathtext_data.py E203 E231 E261 - matplotlib/font_manager.py E201 E203 E221 E225 E228 E231 E251 E261 E262 E302 E402 E501 - matplotlib/fontconfig_pattern.py E201 E203 E221 E222 E225 E302 E401 E501 - matplotlib/legend_handler.py E201 E301 E303 E501 - matplotlib/mathtext.py E201 E202 E203 E211 E221 E222 E225 E228 E231 E251 E261 E301 E302 E303 E401 E402 E501 - matplotlib/patheffects.py E231 - matplotlib/pylab.py E401 E402 E501 - matplotlib/pyplot.py E201 E202 E203 E221 E222 E225 E231 E251 E261 E302 E303 E501 E701 E713 - matplotlib/rcsetup.py E203 E225 E261 E302 E501 - matplotlib/stackplot.py E251 - matplotlib/transforms.py E201 E202 E203 E302 E501 - matplotlib/type1font.py E222 E731 - - mpl_toolkits/axes_grid/axes_divider.py E501 - mpl_toolkits/axes_grid/axes_grid.py E225 E302 - mpl_toolkits/axes_grid/axes_rgb.py E302 E501 - mpl_toolkits/axes_grid/parasite_axes.py E501 - mpl_toolkits/axes_grid1/axes_divider.py E402 E501 - mpl_toolkits/axes_grid1/axes_grid.py E225 W391 - mpl_toolkits/axes_grid1/axes_rgb.py E231 E501 - mpl_toolkits/axes_grid1/axes_size.py E225 E261 E302 E303 E501 - mpl_toolkits/axes_grid1/colorbar.py E225 E231 E261 E262 E302 E303 E501 E701 - mpl_toolkits/axes_grid1/inset_locator.py E501 - mpl_toolkits/axes_grid1/mpl_axes.py E302 E303 E501 - mpl_toolkits/axes_grid1/parasite_axes.py E225 E231 E302 E303 E402 E501 - mpl_toolkits/axisartist/angle_helper.py E201 E203 E221 E222 E225 E231 E251 E261 E262 E302 E303 E402 E501 - mpl_toolkits/axisartist/axes_grid.py E225 E302 - mpl_toolkits/axisartist/axis_artist.py E201 E202 E221 E225 E228 E231 E251 E261 E262 E302 E303 E402 E501 E701 E702 E711 - mpl_toolkits/axisartist/axisline_style.py E231 E261 E262 E302 E303 - mpl_toolkits/axisartist/axislines.py E225 E231 E261 E262 E302 E303 E501 E711 - mpl_toolkits/axisartist/clip_path.py E225 E228 E302 E303 E501 E502 - mpl_toolkits/axisartist/floating_axes.py E201 E225 E231 E261 E262 E271 E302 E303 E402 E501 - mpl_toolkits/axisartist/grid_finder.py E231 E261 E302 E303 E402 - mpl_toolkits/axisartist/grid_helper_curvelinear.py E221 E225 E231 E251 E261 E262 E271 E302 E303 E501 - mpl_toolkits/mplot3d/art3d.py E203 E222 E225 E231 - mpl_toolkits/mplot3d/axes3d.py E203 E225 E231 E271 E303 E402 E501 E502 E701 - mpl_toolkits/mplot3d/axis3d.py E201 E202 E203 E222 E231 E302 E303 E502 - mpl_toolkits/mplot3d/proj3d.py E231 E302 E303 - mpl_toolkits/tests/test_axes_grid1.py E201 E202 - mpl_toolkits/tests/test_mplot3d.py E231 E302 - mpl_toolkits/__init__.py E261 - mpl_toolkits/exceltools.py E201 E202 E225 E228 E302 E303 E501 E701 - mpl_toolkits/gtktools.py E221 E222 E225 E228 E231 E251 E261 E301 E302 E303 E401 E501 E701 - - doc/* E302 E501 - tutorials/* E402 E501 - - examples/* E501 E402 - examples/misc/table_demo.py E201 - examples/images_contours_and_fields/tricontour_demo.py E201 - examples/images_contours_and_fields/tripcolor_demo.py E201 - examples/images_contours_and_fields/triplot_demo.py E201 - examples/pyplots/align_ylabels.py E231 - examples/pyplots/annotate_transform.py E228 E251 - examples/pyplots/annotation_basic.py E231 - examples/pyplots/annotation_polar.py E231 - examples/pyplots/auto_subplots_adjust.py E231 E261 E302 W391 - examples/pyplots/boxplot_demo_pyplot.py E231 - examples/pyplots/compound_path_demo.py E231 - examples/pyplots/fig_axes_customize_simple.py E261 - examples/pyplots/pyplot_formatstr.py E231 - examples/pyplots/pyplot_mathtext.py E231 - examples/pyplots/pyplot_simple.py E231 - examples/pyplots/pyplot_two_subplots.py E302 - examples/pyplots/text_commands.py E231 - examples/pyplots/text_layout.py E231 - examples/pyplots/whats_new_1_subplot3d.py W391 - examples/pyplots/whats_new_98_4_fancy.py E225 E261 E302 - examples/pyplots/whats_new_98_4_fill_between.py E225 - examples/pyplots/whats_new_98_4_legend.py E228 - examples/pyplots/whats_new_99_axes_grid.py E225 E231 E302 E303 - examples/pyplots/whats_new_99_spines.py E231 E261 - examples/shapes_and_collections/artist_reference.py E203 diff --git a/requirements/testing/travis36.txt b/requirements/testing/travis36.txt index f7fe1f5a6058..70d746b82b51 100644 --- a/requirements/testing/travis36.txt +++ b/requirements/testing/travis36.txt @@ -1,5 +1,6 @@ # Extra pip requirements for the travis python 3.6 build -pandas<0.21.0 +flake8 +flake8-per-file-ignores jupyter -pytest-flake8 +pandas<0.21.0