Skip to content
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

Add matplotlib.backend entry points #549

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is considered the correct way to determine the current Matplotlib backend, it just calls rcParams['backend'] internally.

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()
Loading