10000 Improve use of importlib.metadata.entry_points · matplotlib/matplotlib@540f8d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 540f8d3

Browse files
committed
Improve use of importlib.metadata.entry_points
1 parent c457c55 commit 540f8d3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/matplotlib/backends/registry.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@ def _read_entry_points(self):
132132
# format):
133133
# [project.entry-points."matplotlib.backend"]
134134
# inline = "matplotlib_inline.backend_inline"
135-
import importlib_metadata as im
135+
import importlib.metadata as im
136+
import sys
137+
138+
# entry_points group keyword not available before Python 3.10
136139
group = "matplotlib.backend"
137-
entries = [(entry.name, entry.value) for entry in im.entry_points(group=group)]
140+
if sys.version_info >= (3, 10):
141+
entry_points = im.entry_points(group=group)
142+
else:
143+
entry_points = im.entry_points().get(group, {})
144+
entries = [(entry.name, entry.value) for entry in entry_points]
138145

139146
# For backward compatibility, if matplotlib-inline and/or ipympl are installed
140147
# but too old to include entry points, create them. Do not import ipympl

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def draw_if_interactive() -> None:
413413
if newbackend in ("ipympl", "widget"):
414414
# ipympl < 0.9.4 expects rcParams["backend"] to be the fully-qualified backend
415415
# name "module://ipympl.backend_nbagg" not short names "ipympl" or "widget".
416-
import importlib_metadata as im
416+
import importlib.metadata as im
417417
from matplotlib import _parse_to_version_info # type: ignore[attr-defined]
418418
try:
419419
module_version = im.version("ipympl")

0 commit comments

Comments
 (0)
0