From 7e6e720d29d0aa07f2f002059519a2ed19bf5b7d Mon Sep 17 00:00:00 2001 From: Elizaveta Shashkova Date: Thu, 9 Feb 2017 17:18:13 +0300 Subject: [PATCH] Disable matplotlib support if display isn't available (PY-16100) --- python/helpers/pydev/_pydevd_bundle/pydevd_constants.py | 3 +++ python/helpers/pydev/pydevconsole.py | 5 ++++- python/helpers/pydev/pydevd.py | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py b/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py index e48d28889039..80e6e8014f37 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_constants.py @@ -103,6 +103,9 @@ USE_LIB_COPY = SUPPORT_GEVENT and \ (IS_PY3K and sys.version_info[1] >= 3)) +INTERACTIVE_MODE_AVAILABLE = os.getenv('DISPLAY') is not None + + def protect_libraries_from_patching(): """ In this function we delete some modules from `sys.modules` dictionary and import them again inside diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index 0aa01eefe604..44a5f6331a66 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -16,7 +16,7 @@ import os import sys from _pydev_imps._pydev_saved_modules import threading -from _pydevd_bundle.pydevd_constants import dict_iter_items +from _pydevd_bundle.pydevd_constants import INTERACTIVE_MODE_AVAILABLE import traceback from _pydev_bundle import fix_getpass @@ -178,6 +178,9 @@ def init_mpl_in_console(interpreter): set_return_control_callback(return_control) + if not INTERACTIVE_MODE_AVAILABLE: + return + from _pydev_bundle.pydev_import_hook import import_hook_manager from pydev_ipython.matplotlibtools import activate_matplotlib, activate_pylab, activate_pyplot import_hook_manager.add_module_name("matplotlib", lambda: activate_matplotlib(interpreter.enableGui)) diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 5562d53a4689..bd390986603f 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -12,7 +12,7 @@ import traceback from _pydevd_bundle.pydevd_constants import IS_JYTH_LESS25, IS_PY3K, IS_PY34_OLDER, get_thread_id, dict_keys, dict_pop, dict_contains, \ dict_iter_items, DebugInfoHolder, PYTHON_SUSPEND, STATE_SUSPEND, STATE_RUN, get_frame, xrange, \ - clear_cached_thread_id + clear_cached_thread_id, INTERACTIVE_MODE_AVAILABLE from _pydev_bundle import fix_getpass from _pydev_bundle import pydev_imports, pydev_log from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding @@ -993,7 +993,8 @@ class PyDB: send_message("asyncio_event", 0, "Task", "Task", "thread", "stop", file, 1, frame=None, parent=None) try: - self.init_matplotlib_support() + if INTERACTIVE_MODE_AVAILABLE: + self.init_matplotlib_support() except: sys.stderr.write("Matplotlib support in debugger failed\n") traceback.print_exc()