8000 Don't force matplotlib backend names to be lowercase (#14475) · ipython/ipython@6bde8f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bde8f6

Browse files
authored
Don't force matplotlib backend names to be lowercase (#14475)
This is something I missed as part of moving the backend resolution to Matplotlib. Since version 3.9.0 Matplotlib handles the case-sensitivity of backend names, making them all lowercase for internal use. But since matplotlib/matplotlib#28473 uppercase letters are allowed in backend names of the form `module://soMe_moDule.sOmE_NAme`. Hence we need to not force backend names to be lowercase in IPython when passing them to Matplotlib. It is just a one line change that happens to make the code simpler, plus a new test. The Matplotlib change will be released in 3.9.1 which is due shortly, possibly today. The new test checks the Matplotlib version to know whether uppercase backend module names are allowed or not.
2 parents d5762c1 + 95b6275 commit 6bde8f6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

IPython/core/magics/pylab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def matplotlib(self, line=''):
100100
% _list_matplotlib_backends_and_gui_loops()
101101
)
102102
else:
103-
gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
103+
gui, backend = self.shell.enable_matplotlib(args.gui)
104104
self._show_matplotlib_backend(args.gui, backend)
105105

106106
@skip_doctest

IPython/core/tests/test_pylabtools.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,29 @@ def test_qt_gtk(self):
258258
assert gui == "qt"
259259
assert s.pylab_gui_select == "qt"
260260

261+
@dec.skipif(not pt._matplotlib_manages_backends())
262+
def test_backend_module_name_case_sensitive(self):
263+
# Matplotlib backend names are case insensitive unless explicitly specified using
264+
# "module://some_module.some_name" syntax which are case sensitive for mpl >= 3.9.1
265+
all_lowercase = "module://matplotlib_inline.backend_inline"
266+
some_uppercase = "module://matplotlib_inline.Backend_inline"
267+
mpl3_9_1 = matplotlib.__version_info__ >= (3, 9, 1)
268+
269+
s = self.Shell()
270+
s.enable_matplotlib(all_lowercase)
271+
if mpl3_9_1:
272+
with pytest.raises(RuntimeError):
273+
s.enable_matplotlib(some_uppercase)
274+
else:
275+
s.enable_matplotlib(some_uppercase)
276+
277+
s.run_line_magic("matplotlib", all_lowercase)
278+
if mpl3_9_1:
279+
with pytest.raises(RuntimeError):
280+
s.run_line_magic("matplotlib", some_uppercase)
281+
else:
282+
s.run_line_magic("matplotlib", some_uppercase)
283+
261284

262285
def test_no_gui_backends():
263286
for k in ['agg', 'svg', 'pdf', 'ps']:

0 commit comments

Comments
 (0)
0