Skip to content

Commit 25a8ba1

Browse files
authored
Add matplotlib.backend entry points (#549)
* Add matplotlib.backend entry points * Use importlib_metadata not importlib.metadata
1 parent 9c02d81 commit 25a8ba1

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ repos:
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010
- repo: https://github.com/PyCQA/flake8
11-
rev: 4.0.1
11+
rev: 7.0.0
1212
hooks:
1313
- id: flake8
14-
additional_dependencies: [flake8-typing-imports==1.7.0]
14+
additional_dependencies: [flake8-typing-imports==1.15.0]
1515
- repo: https://github.com/myint/autoflake
16-
rev: v1.4
16+
rev: v2.3.0
1717
hooks:
1818
- id: autoflake
1919
args: ["--in-place", "--remove-all-unused-imports", "--ignore-init-module-imports", "--remove-unused-variables"]

ipympl/backend_nbagg.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ def show(block=None):
540540

541541

542542
def flush_figures():
543-
if rcParams['backend'] == 'module://ipympl.backend_nbagg':
543+
backend = matplotlib.get_backend()
544+
if backend in ('widget', 'ipympl', 'module://ipympl.backend_nbagg'):
544545
if not _Backend_ipympl._draw_called:
545546
return
546547

pyproject.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dependencies = [
5050
"traitlets<6",
5151
]
5252
requires-python = ">=3.9"
53-
version = "0.9.3"
53+
version = "0.9.4.dev1"
5454

5555
[project.optional-dependencies]
5656
docs = [
@@ -66,6 +66,10 @@ docs = [
6666
Homepage = "http://matplotlib.org/ipympl"
6767
Repository = "https://github.com/matplotlib/ipympl"
6868

69+
[project.entry-points."matplotlib.backend"]
70+
ipympl = "ipympl.backend_nbagg"
71+
widget = "ipympl.backend_nbagg"
72+
6973
[tool.hatch.build]
7074
artifacts = [
7175
"ipympl/nbextension/index.*",

tests/test_entry_points.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def test_own_entry_points():
2+
from importlib_metadata import entry_points
3+
4+
entries = entry_points(group="matplotlib.backend")
5+
for name in ["ipympl", "widget"]:
6+
assert name in entries.names
7+
entry = entries[name]
8+
assert entry.name == name
9+
assert entry.value == "ipympl.backend_nbagg"
10+
# Check can load module.
11+
entry.load()

0 commit comments

Comments
 (0)