ipython
ipython copied to clipboard
Move backend mapping to Matplotlib
I wanted to draw your attention to matplotlib/matplotlib#27663, about moving the Matplotlib backend mappings out of IPython and into Matplotlib.
The primary use case it so support Matplotlib widgets (ipympl and matplotlib-inline) registering themselves as Matplotlib backends without requiring additional code in IPython and/or Matplotlib. The secondary use case is to support backends in IPython using Matplotlib's module://name.of.the.backend syntax, e.g.
%matplotlib module://mplcairo.backend
which one can already do using matplotlib.use(...) but not directly via the %matplotlib magic.
Whilst doing this it seems sensible to bring all of the backend registering and mapping together in one place, and that should be Matplotlib rather than IPython. I am not sure how easy (or even possible!) it will be to remove all the related hard-coded stuff in IPython, but I am willing to start and see how it goes.
Thanks for opening this up for awareness, @ianthomas23 ! This sounds like a good plan to me. I think the only modification we'd want is to keep the current hardcoded functionality to support older versions of Matplotlib that will not have the list_backends, as there are users who update some packages while pinning others, so we would not want to break them by assuming that when they get a newer IPython they will also get a recent Matplotlib.
+1, I have no issue hardcoding a matplotlib version check in IPython to either fall to the hardcoded path or assuming things get registered.
Thanks both. Yes, I'll put in a check on matplotlib.__version__ and use the existing code for "old" Matplotlib.
I have a concern about backend2gui. It won't be needed in future (apart from the above fallback) but I wonder if other downstream libraries might be using it such that it cannot just be removed. Maybe I need to add a shim so that use of backend2gui does the right thing by calling Matplotlib as necessary.
We can add a getattr to the module level that warns about pending deprecation on access.