Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make qtpy an optional dependency #38

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading