8000 Allow duplicate (name, value) entry points for backends by ianthomas23 · Pull Request #28388 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Allow duplicate (name, value) entry points for backends #28388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to 8000
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/matplotlib/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ def backward_compatible_entry_points(
def _validate_and_store_entry_points(self, entries):
# Validate and store entry points so that they can be used via matplotlib.use()
# in the normal manner. Entry point names cannot be of module:// format, cannot
# shadow a built-in backend name, and cannot be duplicated.
for name, module in entries:
# shadow a built-in backend name, and there cannot be multiple entry points
# with the same name but different modules. Multiple entry points with the same
# name and value are permitted (it can sometimes happen outside of our control,
# see https://github.com/matplotlib/matplotlib/issues/28367).
for name, module in set(entries):
name = name.lower()
if name.startswith("module://"):
raise RuntimeError(
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_backend_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def test_entry_point_name_duplicate(clear_backend_registry):
[('some_name', 'module1'), ('some_name', 'module2')])


def test_entry_point_identical(clear_backend_registry):
# Issue https://github.com/matplotlib/matplotlib/issues/28367
# Multiple entry points with the same name and value (value is the module)
# are acceptable.
n = len(backend_registry._name_to_module)
backend_registry._validate_and_store_entry_points(
[('some_name', 'some.module'), ('some_name', 'some.module')])
assert len(backend_registry._name_to_module) == n+1
assert backend_registry._name_to_module['some_name'] == 'module://some.module'


def test_entry_point_name_is_module(clear_backend_registry):
with pytest.raises(RuntimeError):
backend_registry._validate_and_store_entry_points(
Expand Down
Loading
0