Skip to content

Raise ImportError on failure to import backends. #11519

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
Jun 28, 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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2018-06-27-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Changes to backend loading
``````````````````````````

Failure to load backend modules (``macosx`` on non-framework builds and
``gtk3`` when running headless) now raises `ImportError` (instead of
`RuntimeError` and `TypeError`, respectively.
17 changes: 11 additions & 6 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
PIXELS_PER_INCH = 96

cursord = {
cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
cursors.HAND : Gdk.Cursor.new(Gdk.CursorType.HAND2),
cursors.POINTER : Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR),
cursors.SELECT_REGION : Gdk.Cursor.new(Gdk.CursorType.TCROSS),
cursors.WAIT : Gdk.Cursor.new(Gdk.CursorType.WATCH),
try:
cursord = {
cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
cursors.HAND : Gdk.Cursor.new(Gdk.CursorType.HAND2),
cursors.POINTER : Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR),
cursors.SELECT_REGION : Gdk.Cursor.new(Gdk.CursorType.TCROSS),
cursors.WAIT : Gdk.Cursor.new(Gdk.CursorType.WATCH),
}
except TypeError as exc:
# Happens when running headless. Convert to ImportError to cooperate with
# backend switching.
raise ImportError(exc)


class TimerGTK3(TimerBase):
Expand Down
15 changes: 9 additions & 6 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -3025,23 +3025,26 @@ static bool verify_framework(void)
&& GetCurrentProcess(&psn)==noErr
&& SetFrontProcess(&psn)==noErr) return true;
#endif
PyErr_SetString(PyExc_RuntimeError,
PyErr_SetString(PyExc_ImportError,
"Python is not installed as a framework. The Mac OS X backend will "
"not be able to function correctly if Python is not installed as a "
"framework. See the Python documentation for more information on "
"installing Python as a framework on Mac OS X. Please either reinstall "
"Python as a framework, or try one of the other backends. If you are "
"using (Ana)Conda please install python.app and replace the use of 'python' "
"with 'pythonw'. See 'Working with Matplotlib on OSX' "
"in the Matplotlib FAQ for more information.");
"using (Ana)Conda please install python.app and replace the use of "
"'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the "
"Matplotlib FAQ for more information.");
return false;
}

static struct PyMethodDef methods[] = {
{"show",
(PyCFunction)show,
METH_NOARGS,
"Show all the figures and enter the main loop.\nThis function does not return until all Matplotlib windows are closed,\nand is normally not needed in interactive sessions."
"Show all the figures and enter the main loop.\n"
"\n"
"This function does not return until all Matplotlib windows are closed,\n"
"and is normally not needed in interactive sessions."
},
{"choose_save_file",
(PyCFunction)choose_save_file,
Expand All @@ -3053,7 +3056,7 @@ static bool verify_framework(void)
METH_VARARGS,
"Sets the active cursor."
},
{NULL, NULL, 0, NULL}/* sentinel */
{NULL, NULL, 0, NULL} /* sentinel */
};

static struct PyModuleDef moduledef = {
Expand Down