Skip to content

Commit

Permalink
dependencies: sever the dependency on packaging.version
Browse files Browse the repository at this point in the history
Make qtpy more self-contained by implementing our own simple version parse()
function instead of relying on packaging.version.
  • Loading branch information
davvid committed Dec 14, 2024
1 parent cd0b49b commit 176c2ed
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 31 deletions.
4 changes: 1 addition & 3 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
4 changes: 1 addition & 3 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions qtpy/QtWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions qtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
import sys
import warnings

from packaging.version import parse

# Version of QtPy
__version__ = "2.5.0.dev0"

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions qtpy/tests/test_qtconcurrent.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion qtpy/tests/test_qtcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from datetime import date, datetime, time

import pytest
from packaging.version import parse

from qtpy import (
PYQT5,
Expand All @@ -14,6 +13,7 @@
PYSIDE2,
PYSIDE_VERSION,
QtCore,
parse,
)

_now = datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys

import pytest
from packaging.version import parse

from qtpy import (
PYQT5,
Expand All @@ -14,6 +13,7 @@
QtCore,
QtGui,
QtWidgets,
parse,
)
from qtpy.tests.utils import not_using_conda

Expand Down
5 changes: 2 additions & 3 deletions qtpy/tests/test_qttest.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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
):
Expand Down
8 changes: 2 additions & 6 deletions qtpy/tests/test_qttexttospeech.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
15 changes: 11 additions & 4 deletions qtpy/tests/test_qtwebenginewidgets.py
Original file line number Diff line number Diff line change
@@ -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
),
Expand Down
3 changes: 1 addition & 2 deletions qtpy/tests/test_uic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion qtpy/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os

import pytest
from packaging.version import parse

from qtpy import parse


def using_conda():
Expand Down

0 comments on commit 176c2ed

Please sign in to comment.