diff --git a/.travis.yml b/.travis.yml index 40609e31d86a..5c1bc3890dde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,11 +29,14 @@ addons: - graphviz - inkscape - libcairo2 + - libcairo2-dev + - libffi-dev - libgeos-dev - - libgirepository-1.0.1 + - libgirepository1.0-dev - lmodern - otf-freefont - pgf + - pkg-config - texlive-fonts-recommended - texlive-latex-base - texlive-latex-extra @@ -132,10 +135,11 @@ install: # install was successful by trying to import the toolkit (sometimes, the # install appears to be successful but shared libraries cannot be loaded at # runtime, so an actual import is a better check). - python -mpip install --upgrade cairocffi>=0.8 pgi>=0.0.11.2 && - python -c 'import pgi as gi; gi.require_version("Gtk", "3.0"); from pgi.repository import Gtk' && - echo 'pgi is available' || - echo 'pgi is not available' + python -mpip install --upgrade pycairo cairocffi>=0.8 + python -mpip install --upgrade PyGObject && + python -c 'import gi; gi.require_version("Gtk", "3.0"); from gi.repository import Gtk' && + echo 'PyGObject is available' || + echo 'PyGObject is not available' python -mpip install --upgrade pyqt5 && python -c 'import PyQt5.QtCore' && echo 'PyQt5 is available' || diff --git a/INSTALL.rst b/INSTALL.rst index 936d1f857918..704e76193fef 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -152,8 +152,7 @@ optional Matplotlib backends and the capabilities they provide. `PySide `_ (>= 1.0.3): for the Qt4-based backends; * `PyQt5 `_: for the Qt5-based backends; -* `PyGObject `_ or - `pgi `_ (>= 0.0.11.2): for the GTK3-based +* `PyGObject `_: for the GTK3-based backends; * :term:`wxpython` (>= 4): for the WX-based backends; * `cairocffi `_ (>= 0.8) or diff --git a/doc/api/next_api_changes/2018-12-19-gtk-drop-pgi.rst b/doc/api/next_api_changes/2018-12-19-gtk-drop-pgi.rst new file mode 100644 index 000000000000..0e47f17273ae --- /dev/null +++ b/doc/api/next_api_changes/2018-12-19-gtk-drop-pgi.rst @@ -0,0 +1,4 @@ +Drop support for ``pgi`` in the GTK3 backends +````````````````````````````````````````````` +``pgi``, an alternative implementation to PyGObject, is no longer supported in +the GTK3 backends. PyGObject should be used instead. diff --git a/doc/glossary/index.rst b/doc/glossary/index.rst index b951faef48e1..5a62de4f4ea0 100644 --- a/doc/glossary/index.rst +++ b/doc/glossary/index.rst @@ -67,13 +67,6 @@ Glossary channel. PDF was designed in part as a next-generation document format to replace postscript - pgi - `pgi ` exists as a relatively - new Python wrapper to GTK3 and acts as a pure python alternative to - PyGObject. pgi still exists in its infancy, currently missing many - features of PyGObject. However Matplotlib does not use any of these - missing features. - PyGObject `PyGObject `_ provides Python wrappers for the :term:`GTK` widgets library diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index 62f15254ec3b..9d8a74fb8c74 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -33,8 +33,7 @@ def _get_running_interactive_framework(): or sys.modules.get("PySide.QtGui")) if QtGui and QtGui.QApplication.instance(): return "qt4" - Gtk = (sys.modules.get("gi.repository.Gtk") - or sys.modules.get("pgi.repository.Gtk")) + Gtk = sys.modules.get("gi.repository.Gtk") if Gtk and Gtk.main_level(): return "gtk3" wx = sys.modules.get("wx") diff --git a/lib/matplotlib/backends/_gtk3_compat.py b/lib/matplotlib/backends/_gtk3_compat.py deleted file mode 100644 index 94971a6cefd8..000000000000 --- a/lib/matplotlib/backends/_gtk3_compat.py +++ /dev/null @@ -1,55 +0,0 @@ -""" -GObject compatibility loader; supports ``gi`` and ``pgi``. - -The binding selection rules are as follows: -- if ``gi`` has already been imported, use it; else -- if ``pgi`` has already been imported, use it; else -- if ``gi`` can be imported, use it; else -- if ``pgi`` can be imported, use it; else -- error out. - -Thus, to force usage of PGI when both bindings are installed, import it first. -""" - -import importlib -import sys - -if "gi" in sys.modules: - import gi -elif "pgi" in sys.modules: - import pgi as gi -else: - try: - import gi - except ImportError: - try: - import pgi as gi - except ImportError: - raise ImportError("The GTK3 backends require 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") - -if gi.__name__ == "pgi" and gi.version_info < (0, 0, 11, 2): - raise ImportError("The GTK3 backends are incompatible with pgi<0.0.11.2") -try: - # :raises ValueError: If module/version is already loaded, already - # required, or unavailable. - gi.require_version("Gtk", "3.0") -except ValueError as e: - # in this case we want to re-raise as ImportError so the - # auto-backend selection logic correctly skips. - raise ImportError from e - -globals().update( - {name: - importlib.import_module("{}.repository.{}".format(gi.__name__, name)) - for name in ["GLib", "GObject", "Gtk", "Gdk"]}) diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 7d8166451a6c..bb78b2fa5f61 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -11,8 +11,7 @@ import numpy as np -# cairocffi is more widely compatible than pycairo (in particular pgi only -# works with cairocffi) so try it first. +# cairocffi is more widely compatible than pycairo so try it first. try: import cairocffi as cairo except ImportError: diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 9e378a1e97e0..961d567c68ca 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -11,7 +11,22 @@ from matplotlib.backend_managers import ToolManager from matplotlib.figure import Figure from matplotlib.widgets import SubplotTool -from ._gtk3_compat import GLib, GObject, Gtk, Gdk + +try: + import gi +except ImportError: + raise ImportError("The GTK3 backends require PyGObject") + +try: + # :raises ValueError: If module/version is already loaded, already + # required, or unavailable. + gi.require_version("Gtk", "3.0") +except ValueError as e: + # in this case we want to re-raise as ImportError so the + # auto-backend selection logic correctly skips. + raise ImportError from e + +from gi.repository import GLib, GObject, Gtk, Gdk _log = logging.getLogger(__name__) diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index 00cbf5db91bc..6c15952e272f 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -19,9 +19,8 @@ def _get_testable_interactive_backends(): backends = [] for deps, backend in [ - # gtk3agg fails on Travis, needs to be investigated. - # (["cairocffi", "pgi"], "gtk3agg"), - (["cairocffi", "pgi"], "gtk3cairo"), + (["cairo", "gi"], "gtk3agg"), + (["cairo", "gi"], "gtk3cairo"), (["PyQt5"], "qt5agg"), (["PyQt5", "cairocffi"], "qt5cairo"), (["tkinter"], "tkagg"),