Skip to content

Commit 987a061

Browse files
Import optional imports from relative module rather than toolkit (#1240)
This fixes an issue seen in TraitsUI bleeding-edge tests. It also fixes CI for PySide 6.5 and also for EDM on MacOS.
1 parent e45b1e8 commit 987a061

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

.github/actions/install-qt-support/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ runs:
2020
sudo apt-get install libxcb-render-util0
2121
sudo apt-get install libxcb-xinerama0
2222
sudo apt-get install libxcb-shape0
23+
sudo apt-get install libxcb-cursor0
2324
sudo apt-get install pulseaudio
2425
sudo apt-get install libpulse-mainloop-glib0
2526
# Needed to work around https://bugreports.qt.io/browse/PYSIDE-1547

etstool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
"importlib_resources>=1.1.0",
9696
"traits" + TRAITS_VERSION_REQUIRES,
9797
"traitsui",
98-
"numpy",
9998
"pygments",
10099
"coverage",
101100
"flake8",
@@ -112,8 +111,10 @@
112111
)
113112
if b'AVX2' in result.stdout.split():
114113
dependencies.add('pillow_simd')
114+
dependencies.add('numpy')
115115
else:
116116
dependencies.add('pillow_simd')
117+
dependencies.add('numpy')
117118

118119

119120
source_dependencies = {

pyface/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,17 @@ def __getattr__(name):
259259
result = toolkit_object(f"{source}:{name}")
260260

261261
elif name in _optional_imports:
262+
from importlib import import_module
262263
import logging
263-
from pyface.toolkit import toolkit_object
264264
from pyface.util._optional_dependencies import optional_import
265265
dependency, source = _optional_imports[name]
266266
with optional_import(
267267
dependency,
268268
msg=f"{name} is not available due to missing {dependency}.",
269269
logger=logging.getLogger(__name__),
270270
):
271-
result = toolkit_object(f"{source}:{name}")
271+
module = import_module(f"pyface.{source}")
272+
result = getattr(module, name)
272273

273274
if result is not_found:
274275
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

pyface/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_public_attrs(self):
3333
attrs = [
3434
name
3535
for name in dir(api)
36-
if not name.startswith('_') or name in api._optional_imports
36+
if not (name.startswith('_') or name in api._optional_imports)
3737
]
3838
for attr in attrs:
3939
with self.subTest(attr=attr):

pyface/tests/test_array_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from traits.testing.optional_dependencies import numpy as np, requires_numpy
1515

16-
from ..array_image import ArrayImage
16+
if np is not None:
17+
from ..array_image import ArrayImage
1718

1819

1920
@requires_numpy

0 commit comments

Comments
 (0)