From 4ea04b4ecc11c74ff28b5ca1300f81a4edfcf607 Mon Sep 17 00:00:00 2001 From: jwhiss Date: Mon, 21 Sep 2026 14:21:51 -0600 Subject: [PATCH 1/2] _enable_matplotlib_integration: fix version incompatibility --- matplotlib_inline/backend_inline.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matplotlib_inline/backend_inline.py b/matplotlib_inline/backend_inline.py index a798c56..a764003 100644 --- a/matplotlib_inline/backend_inline.py +++ b/matplotlib_inline/backend_inline.py @@ -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): + backend = matplotlib.get_backend() else: backend = matplotlib.rcParams._get("backend") From 00f107725e70749b4ca9eb25f105b65b41551c7c Mon Sep 17 00:00:00 2001 From: jwhiss Date: Mon, 21 Sep 2026 15:14:13 -0600 Subject: [PATCH 2/2] add tests confirming matplotlib version fix --- .github/workflows/main.yml | 18 +++++++++++++++--- tests/test_import.py | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c675715..237d89d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 diff --git a/tests/test_import.py b/tests/test_import.py index c816b29..20738c5 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -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]