Skip to content

Commit 875379d

Browse files
authored
Merge pull request matplotlib#30533 from QuLogic/gtk-require-version
gtk: Add more explicit version requirements
2 parents caaa636 + 996736d commit 875379d

File tree

5 files changed

+49
-74
lines changed

5 files changed

+49
-74
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ jobs:
115115
fonts-wqy-zenhei \
116116
gdb \
117117
gir1.2-gtk-3.0 \
118+
gir1.2-gtk-4.0 \
118119
graphviz \
119120
inkscape \
120121
language-pack-de \
@@ -150,7 +151,6 @@ jobs:
150151
fi
151152
if [[ "${{ matrix.os }}" = ubuntu-22.04 ]]; then
152153
sudo apt-get install -yy --no-install-recommends \
153-
gir1.2-gtk-4.0 \
154154
libgirepository1.0-dev
155155
else # ubuntu-24.04
156156
sudo apt-get install -yy --no-install-recommends \

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
# :raises ValueError: If module/version is already loaded, already
1919
# required, or unavailable.
2020
gi_require_version("Gtk", "3.0")
21-
# Also require GioUnix to avoid PyGIWarning when Gio is imported
22-
# GioUnix is platform-specific and may not be available on all systems
23-
try:
24-
gi_require_version("GioUnix", "2.0")
25-
except ValueError:
26-
# GioUnix is not available on this platform, which is fine
27-
pass
21+
gi_require_version("Gdk", "3.0")
2822
except ValueError as e:
2923
# in this case we want to re-raise as ImportError so the
3024
# auto-backend selection logic correctly skips.

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@
1717
# :raises ValueError: If module/version is already loaded, already
1818
# required, or unavailable.
1919
gi_require_version("Gtk", "4.0")
20-
# Also require GioUnix to avoid PyGIWarning when Gio is imported
21-
# GioUnix is platform-specific and may not be available on all systems
22-
try:
23-
gi_require_version("GioUnix", "2.0")
24-
except ValueError:
25-
# GioUnix is not available on this platform, which is fine
26-
pass
20+
gi_require_version("Gdk", "4.0")
21+
gi_require_version("GdkPixbuf", "2.0")
2722
except ValueError as e:
2823
# in this case we want to re-raise as ImportError so the
2924
# auto-backend selection logic correctly skips.

lib/matplotlib/tests/test_backend_gtk3.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,6 @@
55
from unittest import mock
66

77

8-
@pytest.mark.backend("gtk3agg", skip_on_importerror=True)
9-
def test_correct_key():
10-
pytest.xfail("test_widget_send_event is not triggering key_press_event")
11-
12-
from gi.repository import Gdk, Gtk # type: ignore[import]
13-
fig = plt.figure()
14-
buf = []
15-
16-
def send(event):
17-
for key, mod in [
18-
(Gdk.KEY_a, Gdk.ModifierType.SHIFT_MASK),
19-
(Gdk.KEY_a, 0),
20-
(Gdk.KEY_a, Gdk.ModifierType.CONTROL_MASK),
21-
(Gdk.KEY_agrave, 0),
22-
(Gdk.KEY_Control_L, Gdk.ModifierType.MOD1_MASK),
23-
(Gdk.KEY_Alt_L, Gdk.ModifierType.CONTROL_MASK),
24-
(Gdk.KEY_agrave,
25-
Gdk.ModifierType.CONTROL_MASK
26-
| Gdk.ModifierType.MOD1_MASK
27-
| Gdk.ModifierType.MOD4_MASK),
28-
(0xfd16, 0), # KEY_3270_Play.
29-
(Gdk.KEY_BackSpace, 0),
30-
(Gdk.KEY_BackSpace, Gdk.ModifierType.CONTROL_MASK),
31-
]:
32-
# This is not actually really the right API: it depends on the
33-
# actual keymap (e.g. on Azerty, shift+agrave -> 0).
34-
Gtk.test_widget_send_key(fig.canvas, key, mod)
35-
36-
def receive(event):
37-
buf.append(event.key)
38-
if buf == [
39-
"A", "a", "ctrl+a",
40-
"\N{LATIN SMALL LETTER A WITH GRAVE}",
41-
"alt+control", "ctrl+alt",
42-
"ctrl+alt+super+\N{LATIN SMALL LETTER A WITH GRAVE}",
43-
# (No entry for KEY_3270_Play.)
44-
"backspace", "ctrl+backspace",
45-
]:
46-
plt.close(fig)
47-
48-
fig.canvas.mpl_connect("draw_event", send)
49-
fig.canvas.mpl_connect("key_press_event", receive)
50-
plt.show()
51-
52-
538
@pytest.mark.backend("gtk3agg", skip_on_importerror=True)
549
def test_save_figure_return():
5510
from gi.repository import Gtk
Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
from importlib import import_module
22
from pkgutil import walk_packages
3+
import sys
4+
import warnings
35

4-
import matplotlib
56
import pytest
67

8+
import matplotlib
9+
from matplotlib.testing import is_ci_environment, subprocess_run_helper
10+
711
# Get the names of all matplotlib submodules,
812
# except for the unit tests and private modules.
9-
module_names = [
10-
m.name
11-
for m in walk_packages(
12-
path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'
13-
)
14-
if not m.name.startswith(__package__)
15-
and not any(x.startswith('_') for x in m.name.split('.'))
16-
]
13+
module_names = []
14+
backend_module_names = []
15+
for m in walk_packages(path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'):
16+
if m.name.startswith(__package__):
17+
continue
18+
if any(x.startswith('_') for x in m.name.split('.')):
19+
continue
20+
if 'backends.backend_' in m.name:
21+
backend_module_names.append(m.name)
22+
else:
23+
module_names.append(m.name)
1724

1825

19-
@pytest.mark.parametrize('module_name', module_names)
20-
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
21-
@pytest.mark.filterwarnings('ignore::ImportWarning')
22-
def test_getattr(module_name):
26+
def _test_getattr(module_name, use_pytest=True):
2327
"""
2428
Test that __getattr__ methods raise AttributeError for unknown keys.
2529
See #20822, #20855.
@@ -28,8 +32,35 @@ def test_getattr(module_name):
2832
module = import_module(module_name)
2933
except (ImportError, RuntimeError, OSError) as e:
3034
# Skip modules that cannot be imported due to missing dependencies
31-
pytest.skip(f'Cannot import {module_name} due to {e}')
35+
if use_pytest:
36+
pytest.skip(f'Cannot import {module_name} due to {e}')
37+
else:
38+
print(f'SKIP: Cannot import {module_name} due to {e}')
39+
return
3240

3341
key = 'THIS_SYMBOL_SHOULD_NOT_EXIST'
3442
if hasattr(module, key):
3543
delattr(module, key)
44+
45+
46+
@pytest.mark.parametrize('module_name', module_names)
47+
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
48+
@pytest.mark.filterwarnings('ignore::ImportWarning')
49+
def test_getattr(module_name):
50+
_test_getattr(module_name)
51+
52+
53+
def _test_module_getattr():
54+
warnings.filterwarnings('ignore', category=DeprecationWarning)
55+
warnings.filterwarnings('ignore', category=ImportWarning)
56+
module_name = sys.argv[1]
57+
_test_getattr(module_name, use_pytest=False)
58+
59+
60+
@pytest.mark.parametrize('module_name', backend_module_names)
61+
def test_backend_getattr(module_name):
62+
proc = subprocess_run_helper(_test_module_getattr, module_name,
63+
timeout=120 if is_ci_environment() else 20)
64+
if 'SKIP: ' in proc.stdout:
65+
pytest.skip(proc.stdout.removeprefix('SKIP: '))
66+
print(proc.stdout)

0 commit comments

Comments
 (0)