Skip to content

Commit

Permalink
Add matplotlib.backend entry points (#549)
Browse files Browse the repository at this point in the history
* Add matplotlib.backend entry points

* Use importlib_metadata not importlib.metadata
  • Loading branch information
ianthomas23 committed Mar 12, 2024
1 parent 9c02d81 commit 25a8ba1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.7.0]
additional_dependencies: [flake8-typing-imports==1.15.0]
- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.3.0
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports", "--ignore-init-module-imports", "--remove-unused-variables"]
Expand Down
3 changes: 2 additions & 1 deletion ipympl/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ def show(block=None):


def flush_figures():
if rcParams['backend'] == 'module://ipympl.backend_nbagg':
backend = matplotlib.get_backend()
if backend in ('widget', 'ipympl', 'module://ipympl.backend_nbagg'):
if not _Backend_ipympl._draw_called:
return

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies = [
"traitlets<6",
]
requires-python = ">=3.9"
version = "0.9.3"
version = "0.9.4.dev1"

[project.optional-dependencies]
docs = [
Expand All @@ -66,6 +66,10 @@ docs = [
Homepage = "http://matplotlib.org/ipympl"
Repository = "https://github.com/matplotlib/ipympl"

[project.entry-points."matplotlib.backend"]
ipympl = "ipympl.backend_nbagg"
widget = "ipympl.backend_nbagg"

[tool.hatch.build]
artifacts = [
"ipympl/nbextension/index.*",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_entry_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def test_own_entry_points():
from importlib_metadata import entry_points

entries = entry_points(group="matplotlib.backend")
for name in ["ipympl", "widget"]:
assert name in entries.names
entry = entries[name]
assert entry.name == name
assert entry.value == "ipympl.backend_nbagg"
# Check can load module.
entry.load()

0 comments on commit 25a8ba1

Please sign in to comment.