From 43e2de56fa7ca09f79217542f00e7d7d83befabb Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Tue, 4 Jun 2024 14:20:55 -0400 Subject: [PATCH 1/4] Make qtpy an optional dependency. --- echo/qt/__init__.py | 7 +++++-- setup.cfg | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/echo/qt/__init__.py b/echo/qt/__init__.py index 21667ca76..2223cc3cd 100644 --- a/echo/qt/__init__.py +++ b/echo/qt/__init__.py @@ -1,2 +1,5 @@ -from .connect import * # noqa -from .autoconnect import * # noqa +try: + from .connect import * # noqa + from .autoconnect import * # noqa +except ImportError: + pass diff --git a/setup.cfg b/setup.cfg index f9b432589..1971a6547 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,6 @@ python_requires = >=3.8 setup_requires = setuptools_scm install_requires = numpy - qtpy importlib_metadata; python_version<'3.9' [options.extras_require] @@ -41,4 +40,5 @@ docs = numpydoc sphinx-rtd-theme qt = + qtpy PyQt5>=5.14 From 46cf9d1310fa7869b127275527bbbd73fbec8b2d Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Tue, 4 Jun 2024 14:46:41 -0400 Subject: [PATCH 2/4] Only test Qt connection functionality when environment permits. --- echo/qt/tests/helpers.py | 21 +++++++++++++++++++ echo/qt/tests/test_autoconnect.py | 10 +++++++-- echo/qt/tests/test_connect.py | 10 +++++++-- echo/qt/tests/test_connect_combo_selection.py | 7 +++++-- echo/qt/tests/test_connect_list_selection.py | 9 +++++--- tox.ini | 1 + 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 echo/qt/tests/helpers.py diff --git a/echo/qt/tests/helpers.py b/echo/qt/tests/helpers.py new file mode 100644 index 000000000..9d903a293 --- /dev/null +++ b/echo/qt/tests/helpers.py @@ -0,0 +1,21 @@ +__all__ = [ + "PYQT5_INSTALLED", "PYQT6_INSTALLED", + "PYSIDE2_INSTALLED", "PYSIDE6_INSTALLED", + "QTPY_INSTALLED", "QT_INSTALLED", + "SKIP_QT_TEST" +] + +def package_installed(package): + try: + __import__(package) + return True + except ImportError: + return False + +PYQT5_INSTALLED = package_installed("PyQt5") +PYQT6_INSTALLED = package_installed("PyQt6") +PYSIDE2_INSTALLED = package_installed("PySide2") +PYSIDE6_INSTALLED = package_installed("PySide6") +QTPY_INSTALLED = package_installed("qtpy") +QT_INSTALLED = PYQT5_INSTALLED or PYQT6_INSTALLED or PYSIDE2_INSTALLED or PYSIDE6_INSTALLED +SKIP_QT_TEST = not (QTPY_INSTALLED and QT_INSTALLED) diff --git a/echo/qt/tests/test_autoconnect.py b/echo/qt/tests/test_autoconnect.py index 691777668..4218d60ad 100644 --- a/echo/qt/tests/test_autoconnect.py +++ b/echo/qt/tests/test_autoconnect.py @@ -1,11 +1,17 @@ from datetime import datetime +import pytest from numpy import datetime64 + +from echo import CallbackProperty +from echo.qt.tests.helpers import SKIP_QT_TEST + +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + from qtpy import QtWidgets, QtGui from qtpy.QtCore import QDateTime, Qt - from echo.qt.autoconnect import autoconnect_callbacks_to_qt -from echo import CallbackProperty from echo.qt.connect import UserDataWrapper diff --git a/echo/qt/tests/test_connect.py b/echo/qt/tests/test_connect.py index d1b0f919e..ee652267f 100644 --- a/echo/qt/tests/test_connect.py +++ b/echo/qt/tests/test_connect.py @@ -4,10 +4,14 @@ from numpy import datetime64 from unittest.mock import MagicMock +from echo import CallbackProperty +from echo.qt.tests.helpers import SKIP_QT_TEST + +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + from qtpy import QtWidgets from qtpy.QtCore import QDateTime, Qt - -from echo import CallbackProperty from echo.qt.connect import (connect_checkable_button, connect_datetime, connect_text, connect_combo_data, connect_combo_text, connect_float_text, connect_value, connect_button, @@ -16,6 +20,8 @@ def test_connect_checkable_button(): + + class Test(object): a = CallbackProperty() b = CallbackProperty(True) diff --git a/echo/qt/tests/test_connect_combo_selection.py b/echo/qt/tests/test_connect_combo_selection.py index 6233151a3..37c7cb11e 100644 --- a/echo/qt/tests/test_connect_combo_selection.py +++ b/echo/qt/tests/test_connect_combo_selection.py @@ -1,10 +1,13 @@ import pytest import numpy as np -from qtpy import QtWidgets - from echo.core import CallbackProperty from echo.selection import SelectionCallbackProperty, ChoiceSeparator +from echo.qt.tests.helpers import SKIP_QT_TEST +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + +from qtpy import QtWidgets from echo.qt.connect import connect_combo_selection diff --git a/echo/qt/tests/test_connect_list_selection.py b/echo/qt/tests/test_connect_list_selection.py index b1caf7154..8c6a8f398 100644 --- a/echo/qt/tests/test_connect_list_selection.py +++ b/echo/qt/tests/test_connect_list_selection.py @@ -1,11 +1,14 @@ import pytest import numpy as np -from qtpy import QtWidgets -from qtpy.QtCore import Qt - from echo.core import CallbackProperty from echo.selection import SelectionCallbackProperty, ChoiceSeparator +from echo.qt.tests.helpers import SKIP_QT_TEST +if SKIP_QT_TEST: + pytest.skip(allow_module_level=True) + +from qtpy import QtWidgets +from qtpy.QtCore import Qt from echo.qt.connect import connect_list_selection diff --git a/tox.ini b/tox.ini index 63ec27bef..57e4dbae6 100644 --- a/tox.ini +++ b/tox.ini @@ -12,6 +12,7 @@ changedir = test: .tmp/{envname} docs: doc deps = + pyqt{510,511,512,513,514,515,63},pyside{513,514,515,63}: qtpy>=2.0 pyqt510: PyQt5==5.10.* pyqt511: PyQt5==5.11.* pyqt512: PyQt5==5.12.* From 3df767fc2b0ec28fc906a51c1d7480780472a466 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Tue, 4 Jun 2024 15:43:50 -0400 Subject: [PATCH 3/4] Codestyle updates. --- echo/qt/tests/helpers.py | 2 ++ echo/qt/tests/test_connect.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/echo/qt/tests/helpers.py b/echo/qt/tests/helpers.py index 9d903a293..0cc4f077b 100644 --- a/echo/qt/tests/helpers.py +++ b/echo/qt/tests/helpers.py @@ -5,6 +5,7 @@ "SKIP_QT_TEST" ] + def package_installed(package): try: __import__(package) @@ -12,6 +13,7 @@ def package_installed(package): except ImportError: return False + PYQT5_INSTALLED = package_installed("PyQt5") PYQT6_INSTALLED = package_installed("PyQt6") PYSIDE2_INSTALLED = package_installed("PySide2") diff --git a/echo/qt/tests/test_connect.py b/echo/qt/tests/test_connect.py index ee652267f..41b6a48e8 100644 --- a/echo/qt/tests/test_connect.py +++ b/echo/qt/tests/test_connect.py @@ -20,8 +20,6 @@ def test_connect_checkable_button(): - - class Test(object): a = CallbackProperty() b = CallbackProperty(True) From e9d189ca6b241b4d30e75a67d68b6387943bae14 Mon Sep 17 00:00:00 2001 From: Jon Carifio Date: Mon, 15 Jul 2024 09:11:07 -0400 Subject: [PATCH 4/4] Update `package_installed` per review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- echo/qt/tests/helpers.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/echo/qt/tests/helpers.py b/echo/qt/tests/helpers.py index 0cc4f077b..65fb3e8fb 100644 --- a/echo/qt/tests/helpers.py +++ b/echo/qt/tests/helpers.py @@ -7,11 +7,8 @@ def package_installed(package): - try: - __import__(package) - return True - except ImportError: - return False + from importlib.util import find_spec + return find_spec(package) is not None PYQT5_INSTALLED = package_installed("PyQt5")