Skip to content

Cleanups. #11566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/api/next_api_changes/2018-02-26-AL-removals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ The following deprecated API elements have been removed:

The following API elements have been removed:

- ``matplotlib.sphinxext.sphinx_version``,
- ``backend_cairo.HAS_CAIRO_CFFI``,
- ``sphinxext.sphinx_version``,
2 changes: 1 addition & 1 deletion doc/sphinxext/mock_gui_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class MyCairoCffi(MagicMock):
pass
__name__ = "cairocffi"


class MyPyQt4(MagicMock):
Expand Down
20 changes: 8 additions & 12 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,19 +1417,15 @@ def tk_window_focus():


def _init_tests():
try:
# CPython's faulthandler since v3.6 handles exceptions on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully grokking this, but I thought we were supporting 3.5 for the next release...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but why does the comment make reference to "since v3.6"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exists on all version (so we don't need the import check), but still need the version check to know if we want to use it on windows or not.

# https://bugs.python.org/issue23848 but until v3.6.4 it was printing
# non-fatal exceptions https://bugs.python.org/issue30557
import platform
if not (sys.platform == 'win32' and
(3, 6) < sys.version_info < (3, 6, 4) and
platform.python_implementation() == 'CPython'):
import faulthandler
except ImportError:
pass
else:
# CPython's faulthandler since v3.6 handles exceptions on Windows
# https://bugs.python.org/issue23848 but until v3.6.4 it was
# printing non-fatal exceptions https://bugs.python.org/issue30557
import platform
if not (sys.platform == 'win32' and
(3, 6) < sys.version_info < (3, 6, 4) and
platform.python_implementation() == 'CPython'):
faulthandler.enable()
faulthandler.enable()

# The version of FreeType to install locally for running the
# tests. This must match the value in `setupext.py`
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from PIL import Image
from PIL import PILLOW_VERSION
from distutils.version import LooseVersion
if LooseVersion(PILLOW_VERSION) >= LooseVersion("3.4"):
if LooseVersion(PILLOW_VERSION) >= "3.4":
_has_pil = True
else:
_has_pil = False
Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/backends/_gtk3_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import importlib
import sys


if "gi" in sys.modules:
import gi
elif "pgi" in sys.modules:
Expand All @@ -28,6 +27,16 @@
except ImportError:
raise ImportError("The Gtk3 backend requires PyGObject or pgi")

from .backend_cairo import cairo # noqa
# The following combinations are allowed:
# gi + pycairo
# gi + cairocffi
# pgi + cairocffi
# (pgi doesn't work with pycairo)
# We always try to import cairocffi first so if a check below fails it means
# that cairocffi was unavailable to start with.
if gi.__name__ == "pgi" and cairo.__name__ == "cairo":
raise ImportError("pgi and pycairo are not compatible")

gi.require_version("Gtk", "3.0")
globals().update(
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
raise ImportError("cairo backend requires that cairocffi or pycairo "
"is installed")
else:
HAS_CAIRO_CFFI = False
if cairo.version_info < (1, 11, 0):
# Introduced create_for_data for Py3.
raise ImportError(
"cairo {} is installed; cairo>=1.11.0 is required"
.format(cairo.version))
else:
HAS_CAIRO_CFFI = True

backend_version = cairo.version

Expand Down Expand Up @@ -65,7 +62,7 @@ def _premultiplied_argb32_to_unmultiplied_rgba8888(buf):
return rgba


if HAS_CAIRO_CFFI:
if cairo.__name__ == "cairocffi":
# Convert a pycairo context to a cairocffi one.
def _to_context(ctx):
if not isinstance(ctx, cairo.Context):
Expand Down Expand Up @@ -177,7 +174,8 @@ def _append_paths_fast(ctx, paths, transforms, clip=None):
cairo.cairo.cairo_append_path(ctx._pointer, ptr)


_append_paths = _append_paths_fast if HAS_CAIRO_CFFI else _append_paths_slow
_append_paths = (_append_paths_fast if cairo.__name__ == "cairocffi"
else _append_paths_slow)


def _append_path(ctx, path, transform, clip=None):
Expand Down
11 changes: 0 additions & 11 deletions lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import warnings

import numpy as np

Expand All @@ -9,16 +8,6 @@
from .backend_gtk3 import Gtk, _BackendGTK3
from matplotlib import transforms

# The following combinations are allowed:
# gi + pycairo
# gi + cairocffi
# pgi + cairocffi
# (pgi doesn't work with pycairo)
# We always try to import cairocffi first so if a check below fails it means
# that cairocffi was unavailable to start with.
if gi.__name__ == "pgi" and cairo.__name__ == "cairo":
raise ImportError("pgi and pycairo are not compatible")


class FigureCanvasGTK3Agg(backend_gtk3.FigureCanvasGTK3,
backend_agg.FigureCanvasAgg):
Expand Down
12 changes: 0 additions & 12 deletions lib/matplotlib/backends/backend_gtk3cairo.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
from . import backend_cairo, backend_gtk3
from ._gtk3_compat import gi
from .backend_cairo import cairo
from .backend_gtk3 import Gtk, _BackendGTK3
from matplotlib.backend_bases import cursors


# The following combinations are allowed:
# gi + pycairo
# gi + cairocffi
# pgi + cairocffi
# (pgi doesn't work with pycairo)
# We always try to import cairocffi first so if a check below fails it means
# that cairocffi was unavailable to start with.
if gi.__name__ == "pgi" and cairo.__name__ == "cairo":
raise ImportError("pgi and pycairo are not compatible")


class RendererGTK3Cairo(backend_cairo.RendererCairo):
def set_context(self, ctx):
self.gc.ctx = backend_cairo._to_context(ctx)
Expand Down
19 changes: 6 additions & 13 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,15 +1331,6 @@ def imread(fname, format=None):
.. _Pillow documentation: http://pillow.readthedocs.io/en/latest/
"""

def pilread(fname):
"""try to load the image with PIL or return None"""
try:
from PIL import Image
except ImportError:
return None
with Image.open(fname) as image:
return pil_to_array(image)

handlers = {'png': _png.read_png, }
if format is None:
if isinstance(fname, str):
Expand All @@ -1358,13 +1349,15 @@ def pilread(fname):
else:
ext = format

if ext not in handlers:
im = pilread(fname)
if im is None:
if ext not in handlers: # Try to load the image with PIL.
try:
from PIL import Image
except ImportError:
raise ValueError('Only know how to handle extensions: %s; '
'with Pillow installed matplotlib can handle '
'more images' % list(handlers))
return im
with Image.open(fname) as image:
return pil_to_array(image)

handler = handlers[ext]

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_image_python_io():
def test_imread_pil_uint16():
img = plt.imread(os.path.join(os.path.dirname(__file__),
'baseline_images', 'test_image', 'uint16.tif'))
assert (img.dtype == np.uint16)
assert img.dtype == np.uint16
assert np.sum(img) == 134184960


Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
from matplotlib.cbook.deprecation import MatplotlibDeprecationWarning


try:
from mpl_toolkits.natgrid import _natgrid
HAS_NATGRID = True
except ImportError:
HAS_NATGRID = False


'''
A lot of mlab.py has been deprecated in Matplotlib 2.2 and is scheduled for
removal in the future. The tests that use deprecated methods have a block
Expand Down Expand Up @@ -2174,8 +2167,9 @@ def get_z(x, y):
np.ma.getmask(correct_zi_masked))


@pytest.mark.xfail(not HAS_NATGRID, reason='natgrid not installed')
def test_griddata_nn():
pytest.importorskip('mpl_toolkits.natgrid')

# z is a linear function of x and y.
def get_z(x, y):
return 3.0*x - y
Expand Down