8000 Backport PR #28473: Do not lowercase module:// backends · matplotlib/matplotlib@b7423af · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7423af

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #28473: Do not lowercase module:// backends
1 parent 452626f commit b7423af

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/matplotlib/backends/registry.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def __init__(self):
9393
}
9494

9595
def _backend_module_name(self, backend):
96+
if backend.startswith("module://"):
97+
return backend[9:]
98+
9699
# Return name of module containing the specified backend.
97100
# Does not check if the backend is valid, use is_valid_backend for that.
98101
backend = backend.lower()
@@ -224,7 +227,8 @@ def is_valid_backend(self, backend):
224227
bool
225228
True if backend is valid, False otherwise.
226229
"""
227-
backend = backend.lower()
230+
if not backend.startswith("module://"):
231+
backend = backend.lower()
228232

229233
# For backward compatibility, convert ipympl and matplotlib-inline long
230234
# module:// names to their shortened forms.
@@ -342,7 +346,8 @@ def resolve_backend(self, backend):
342346
The GUI framework, which will be None for a backend that is non-interactive.
343347
"""
344348
if isinstance(backend, str):
345-
backend = backend.lower()
349+
if not backend.startswith("module://"):
350+
backend = backend.lower() 8000
346351
else: # Might be _auto_backend_sentinel or None
347352
# Use whatever is already running...
348353
from matplotlib import get_backend
@@ -395,7 +400,8 @@ def resolve_gui_or_backend(self, gui_or_backend):
395400
framework : str or None
396401
The GUI framework, which will be None for a backend that is non-interactive.
397402
"""
398-
gui_or_backend = gui_or_backend.lower()
403+
if not gui_or_backend.startswith("module://"):
404+
gui_or_backend = gui_or_backend.lower()
399405

400406
# First check if it is a gui loop name.
401407
backend = self.backend_for_gui_framework(gui_or_backend)

lib/matplotlib/tests/test_backend_registry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def test_is_valid_backend(backend, is_valid):
8686
assert backend_registry.is_valid_backend(backend) == is_valid
8787

8888

89+
@pytest.mark.parametrize("backend, normalized", [
90+
("agg", "matplotlib.backends.backend_agg"),
91+
("QtAgg", "matplotlib.backends.backend_qtagg"),
92+
("module://Anything", "Anything"),
93+
])
94+
def test_backend_normalization(backend, normalized):
95+
assert backend_registry._backend_module_name(backend) == normalized
96+
97+
8998
def test_deprecated_rcsetup_attributes():
9099
match = "was deprecated in Matplotlib 3.9"
91100
with pytest.warns(mpl.MatplotlibDeprecationWarning, match=match):

lib/matplotlib/tests/test_backend_template.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ def test_show_old_global_api(monkeypatch):
4949
mpl.use("module://mpl_test_backend")
5050
plt.show()
5151
mock_show.assert_called_with()
52+
53+
54+
def test_load_case_sensitive(monkeypatch):
55+
mpl_test_backend = SimpleNamespace(**vars(backend_template))
56+
mock_show = MagicMock()
57+
monkeypatch.setattr(
58+
mpl_test_backend.FigureManagerTemplate, "pyplot_show", mock_show)
59+
monkeypatch.setitem(sys.modules, "mpl_Test_Backend", mpl_test_backend)
60+
mpl.use("module://mpl_Test_Backend")
61+
plt.show()
62+
mock_show.assert_called_with()

0 commit comments

Comments
 (0)
0