Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
matplotlib-version: [""]
numpy-version: [""]
include:
#- os: macos-latest
# python-version: "3.14"
- os: windows-latest
python-version: "3.14"
matplotlib-version: ""
numpy-version: ""
- os: ubuntu-latest
python-version: "3.9"
matplotlib-version: "==3.5.0"
numpy-version: "<2"
- os: ubuntu-latest
python-version: "3.12"
matplotlib-version: "<3.10.0"
numpy-version: ""

steps:
- name: Checkout
Expand All @@ -45,9 +57,9 @@ jobs:

- name: Install package with test dependencies
# matplotlib is not a dependency but tests need it
run: |
pip install .[test]
pip install matplotlib
run: >-
pip install ".[test]" "matplotlib${{ matrix.matplotlib-version }}"
"numpy${{ matrix.numpy-version }}"

- name: Test installation without nbdime
run: pytest -v
Expand Down
5 changes: 4 additions & 1 deletion matplotlib_inline/backend_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ def _enable_matplotlib_integration():

import matplotlib

if matplotlib.__version_info__ >= (3, 10):
version = matplotlib.__version_info__
if version >= (3, 10):
backend = matplotlib.get_backend(auto_select=False)
elif version >= (3, 5):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is not correct. get_backend() triggers backend resolution, which is explicitly not wanted - see #38.

Also, rcParams._get() was introduced in in matplotlib 3.7, see here.

The correct way would be

    elif version >= (3, 7):
        backend = matplotlib.rcParams._get("backend")
    else:
        backend = dict.__getitem__(matplotlib.rcParams, "backend")

backend = matplotlib.get_backend()
else:
backend = matplotlib.rcParams._get("backend")

Expand Down
24 changes: 24 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
import pytest


def test_import():
from matplotlib_inline.backend_inline import show

show()


@pytest.mark.parametrize("version", [(3, 5, 0), (3, 9, 9)])
def test_enable_matplotlib_integration_before_3_10_uses_legacy_get_backend(
monkeypatch, version
):
from matplotlib_inline import backend_inline

calls = []

def get_backend():
calls.append(None)
return "agg"

monkeypatch.setattr(backend_inline.matplotlib, "__version_info__", version)
monkeypatch.setattr(backend_inline.matplotlib, "get_backend", get_backend)
monkeypatch.setattr(backend_inline, "get_ipython", lambda: None)

backend_inline._enable_matplotlib_integration()

assert calls == [None]