Skip to content

Commit

Permalink
Merge pull request #38 from Carifio24/qt-optional
Browse files Browse the repository at this point in the history
Make qtpy an optional dependency
  • Loading branch information
astrofrog authored Jul 19, 2024
2 parents e2f717d + e9d189c commit dbbd206
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 12 deletions.
7 changes: 5 additions & 2 deletions echo/qt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from .connect import * # noqa
from .autoconnect import * # noqa
try:
from .connect import * # noqa
from .autoconnect import * # noqa
except ImportError:
pass
20 changes: 20 additions & 0 deletions echo/qt/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__all__ = [
"PYQT5_INSTALLED", "PYQT6_INSTALLED",
"PYSIDE2_INSTALLED", "PYSIDE6_INSTALLED",
"QTPY_INSTALLED", "QT_INSTALLED",
"SKIP_QT_TEST"
]


def package_installed(package):
from importlib.util import find_spec
return find_spec(package) is not None


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)
10 changes: 8 additions & 2 deletions echo/qt/tests/test_autoconnect.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
8 changes: 6 additions & 2 deletions echo/qt/tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions echo/qt/tests/test_connect_combo_selection.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
9 changes: 6 additions & 3 deletions echo/qt/tests/test_connect_list_selection.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -41,4 +40,5 @@ docs =
numpydoc
sphinx-rtd-theme
qt =
qtpy
PyQt5>=5.14
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down

0 comments on commit dbbd206

Please sign in to comment.