From 45b10fd2684d79e0cb9f48db8773a5aa5ae03d04 Mon Sep 17 00:00:00 2001 From: Gary Miguel Date: Sat, 21 Dec 2024 13:45:11 -0800 Subject: [PATCH] Handle new matplotlib versions Fixes: https://github.com/microsoft/debugpy/issues/1623 --- .../pydevd/pydev_ipython/matplotlibtools.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py b/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py index ef185b798..d10f85b37 100644 --- a/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py +++ b/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py @@ -53,10 +53,30 @@ def find_gui_and_backend(): return gui, backend +def _get_major_version(module): + return int(module.__version__.split('.')[0]) + + +def _get_minor_version(module): + return int(module.__version__.split('.')[1]) + + def is_interactive_backend(backend): """Check if backend is interactive""" matplotlib = sys.modules["matplotlib"] - from matplotlib.rcsetup import interactive_bk, non_interactive_bk # @UnresolvedImport + new_api_version = (3, 9) + installed_version = ( + _get_major_version(matplotlib), + _get_minor_version(matplotlib) + ) + + if installed_version >= new_api_version: + interactive_bk = matplotlib.backends.backend_registry.list_builtin( + matplotlib.backends.BackendFilter.INTERACTIVE) + non_interactive_bk = matplotlib.backends.backend_registry.list_builtin( + matplotlib.backends.BackendFilter.NON_INTERACTIVE) + else: + from matplotlib.rcsetup import interactive_bk, non_interactive_bk # @UnresolvedImport if backend in interactive_bk: return True