From f5df331d71a675524790f6644f88214e87366ce3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 13 Aug 2018 16:57:35 +0200 Subject: [PATCH] Simpler check for whether a Framework Python build is being used. This check works even before an NSApp is started. --- lib/matplotlib/backends/backend_macosx.py | 13 +++++++++ src/_macosx.m | 35 ----------------------- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index ab7601f63bcd..180cd90b1634 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -1,4 +1,17 @@ import os +import sysconfig + +# PYTHONFRAMEWORK defined in CPython's configure.ac. +if not sysconfig.get_config_var("PYTHONFRAMEWORK"): + raise ImportError( + "Python is not installed as a framework. The MacOSX 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 MacOSX. 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.") from matplotlib._pylab_helpers import Gcf from matplotlib.backend_bases import ( diff --git a/src/_macosx.m b/src/_macosx.m index 416cf6a583e3..9f05b3b94add 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -2563,38 +2563,6 @@ static void context_cleanup(const void* info) Timer_new, /* tp_new */ }; -static bool verify_framework(void) -{ -#ifdef COMPILING_FOR_10_6 - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSRunningApplication* app = [NSRunningApplication currentApplication]; - NSApplicationActivationPolicy activationPolicy = [app activationPolicy]; - [pool release]; - switch (activationPolicy) { - case NSApplicationActivationPolicyRegular: - case NSApplicationActivationPolicyAccessory: - return true; - case NSApplicationActivationPolicyProhibited: - break; - } -#else - ProcessSerialNumber psn; - if (CGMainDisplayID()!=0 - && GetCurrentProcess(&psn)==noErr - && SetFrontProcess(&psn)==noErr) return true; -#endif - 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."); - return false; -} - static struct PyMethodDef methods[] = { {"event_loop_is_running", (PyCFunction)event_loop_is_running, @@ -2644,9 +2612,6 @@ static bool verify_framework(void) || PyType_Ready(&TimerType) < 0) return NULL; - if (!verify_framework()) - return NULL; - module = PyModule_Create(&moduledef); if (!module) return NULL;