diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index 51791cf8..184a4b27 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -10,9 +10,7 @@ import contextlib from typing import TYPE_CHECKING -from packaging.version import parse - -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6 +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse from . import QT_VERSION as _qt_version from ._utils import possibly_static_exec, possibly_static_exec_ diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 3e8a4fb3..0d9b5c30 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -10,9 +10,7 @@ from functools import partialmethod -from packaging.version import parse - -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6 +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse from . import QT_VERSION as _qt_version from ._utils import ( getattr_missing_optional_dep, diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 1b225421..ec1a7c51 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -9,9 +9,7 @@ """Provides widget classes and functions.""" from functools import partialmethod -from packaging.version import parse - -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6 +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse from . import QT_VERSION as _qt_version from ._utils import ( add_action, diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 697f23ae..0c131c39 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -60,8 +60,6 @@ import sys import warnings -from packaging.version import parse - # Version of QtPy __version__ = "2.5.0.dev0" @@ -185,6 +183,20 @@ def __init__(self, *, missing_package=None, **superclass_kwargs): PYSIDE_VERSION = None QT_VERSION = None + +def _parse_int(value): + """Convert a value into an integer""" + try: + return int(value) + except ValueError: + return 0 + + +def parse(version): + """Parse a version string into a tuple of ints""" + return tuple(_parse_int(x) for x in version.split(".")) + + # Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings if not os.environ.get("FORCE_QT_API"): if "PyQt5" in sys.modules: diff --git a/qtpy/tests/test_qtconcurrent.py b/qtpy/tests/test_qtconcurrent.py index 8fc71777..d5653d3f 100644 --- a/qtpy/tests/test_qtconcurrent.py +++ b/qtpy/tests/test_qtconcurrent.py @@ -1,7 +1,6 @@ import pytest -from packaging.version import parse -from qtpy import PYSIDE2, PYSIDE_VERSION +from qtpy import PYSIDE2, PYSIDE_VERSION, parse from qtpy.tests.utils import pytest_importorskip diff --git a/qtpy/tests/test_qtcore.py b/qtpy/tests/test_qtcore.py index 9044290d..405db585 100644 --- a/qtpy/tests/test_qtcore.py +++ b/qtpy/tests/test_qtcore.py @@ -5,7 +5,6 @@ from datetime import date, datetime, time import pytest -from packaging.version import parse from qtpy import ( PYQT5, @@ -14,6 +13,7 @@ PYSIDE2, PYSIDE_VERSION, QtCore, + parse, ) _now = datetime.now() diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index 23fc0158..0938d9d5 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -3,7 +3,6 @@ import sys import pytest -from packaging.version import parse from qtpy import ( PYQT5, @@ -14,6 +13,7 @@ QtCore, QtGui, QtWidgets, + parse, ) from qtpy.tests.utils import not_using_conda diff --git a/qtpy/tests/test_qttest.py b/qtpy/tests/test_qttest.py index 2d67439f..c57f81ec 100644 --- a/qtpy/tests/test_qttest.py +++ b/qtpy/tests/test_qttest.py @@ -1,7 +1,6 @@ import pytest -from packaging import version -from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE6, QtTest +from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE6, QtTest, parse def test_qttest(): @@ -12,7 +11,7 @@ def test_qttest(): assert QtTest.QSignalSpy is not None if ( - (PYQT5 and version.parse(PYQT_VERSION) >= version.parse("5.11")) + (PYQT5 and parse(PYQT_VERSION) >= parse("5.11")) or PYQT6 or PYSIDE6 ): diff --git a/qtpy/tests/test_qttexttospeech.py b/qtpy/tests/test_qttexttospeech.py index bcb97f09..a941eeb3 100644 --- a/qtpy/tests/test_qttexttospeech.py +++ b/qtpy/tests/test_qttexttospeech.py @@ -1,14 +1,10 @@ import pytest -from packaging import version -from qtpy import PYQT5, PYQT_VERSION, PYSIDE2 +from qtpy import PYQT5, PYQT_VERSION, PYSIDE2, parse @pytest.mark.skipif( - not ( - (PYQT5 and version.parse(PYQT_VERSION) >= version.parse("5.15.1")) - or PYSIDE2 - ), + not ((PYQT5 and parse(PYQT_VERSION) >= parse("5.15.1")) or PYSIDE2), reason="Only available in Qt5 bindings (PyQt5 >= 5.15.1 or PySide2)", ) def test_qttexttospeech(): diff --git a/qtpy/tests/test_qtwebenginewidgets.py b/qtpy/tests/test_qtwebenginewidgets.py index 06339798..2743ac65 100644 --- a/qtpy/tests/test_qtwebenginewidgets.py +++ b/qtpy/tests/test_qtwebenginewidgets.py @@ -1,14 +1,21 @@ import pytest -from packaging import version -from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE2, PYSIDE6, PYSIDE_VERSION +from qtpy import ( + PYQT5, + PYQT6, + PYQT_VERSION, + PYSIDE2, + PYSIDE6, + PYSIDE_VERSION, + parse, +) from qtpy.tests.utils import pytest_importorskip @pytest.mark.skipif( not ( - (PYQT6 and version.parse(PYQT_VERSION) >= version.parse("6.2")) - or (PYSIDE6 and version.parse(PYSIDE_VERSION) >= version.parse("6.2")) + (PYQT6 and parse(PYQT_VERSION) >= parse("6.2")) + or (PYSIDE6 and parse(PYSIDE_VERSION) >= parse("6.2")) or PYQT5 or PYSIDE2 ), diff --git a/qtpy/tests/test_uic.py b/qtpy/tests/test_uic.py index 94558461..6b7d3620 100644 --- a/qtpy/tests/test_uic.py +++ b/qtpy/tests/test_uic.py @@ -4,9 +4,8 @@ import warnings import pytest -from packaging.version import parse -from qtpy import PYSIDE2, PYSIDE6, PYSIDE_VERSION, QtWidgets +from qtpy import PYSIDE2, PYSIDE6, PYSIDE_VERSION, QtWidgets, parse from qtpy.QtWidgets import QComboBox from qtpy.tests.utils import pytest_importorskip, using_conda diff --git a/qtpy/tests/utils.py b/qtpy/tests/utils.py index 68ac1668..4c069f3f 100644 --- a/qtpy/tests/utils.py +++ b/qtpy/tests/utils.py @@ -3,7 +3,8 @@ import os import pytest -from packaging.version import parse + +from qtpy import parse def using_conda():