Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 176c2ed

Browse files
committedDec 14, 2024·
dependencies: sever the dependency on packaging.version
Make qtpy more self-contained by implementing our own simple version parse() function instead of relying on packaging.version.
1 parent cd0b49b commit 176c2ed

12 files changed

+38
-31
lines changed
 

‎qtpy/QtCore.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import contextlib
1111
from typing import TYPE_CHECKING
1212

13-
from packaging.version import parse
14-
15-
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6
13+
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse
1614
from . import QT_VERSION as _qt_version
1715
from ._utils import possibly_static_exec, possibly_static_exec_
1816

‎qtpy/QtGui.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
from functools import partialmethod
1212

13-
from packaging.version import parse
14-
15-
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6
13+
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse
1614
from . import QT_VERSION as _qt_version
1715
from ._utils import (
1816
getattr_missing_optional_dep,

‎qtpy/QtWidgets.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"""Provides widget classes and functions."""
1010
from functools import partialmethod
1111

12-
from packaging.version import parse
13-
14-
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6
12+
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, parse
1513
from . import QT_VERSION as _qt_version
1614
from ._utils import (
1715
add_action,

‎qtpy/__init__.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
import sys
6161
import warnings
6262

63-
from packaging.version import parse
64-
6563
# Version of QtPy
6664
__version__ = "2.5.0.dev0"
6765

@@ -185,6 +183,20 @@ def __init__(self, *, missing_package=None, **superclass_kwargs):
185183
PYSIDE_VERSION = None
186184
QT_VERSION = None
187185

186+
187+
def _parse_int(value):
188+
"""Convert a value into an integer"""
189+
try:
190+
return int(value)
191+
except ValueError:
192+
return 0
193+
194+
195+
def parse(version):
196+
"""Parse a version string into a tuple of ints"""
197+
return tuple(_parse_int(x) for x in version.split("."))
198+
199+
188200
# Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings
189201
if not os.environ.get("FORCE_QT_API"):
190202
if "PyQt5" in sys.modules:

‎qtpy/tests/test_qtconcurrent.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
2-
from packaging.version import parse
32

4-
from qtpy import PYSIDE2, PYSIDE_VERSION
3+
from qtpy import PYSIDE2, PYSIDE_VERSION, parse
54
from qtpy.tests.utils import pytest_importorskip
65

76

‎qtpy/tests/test_qtcore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import date, datetime, time
66

77
import pytest
8-
from packaging.version import parse
98

109
from qtpy import (
1110
PYQT5,
@@ -14,6 +13,7 @@
1413
PYSIDE2,
1514
PYSIDE_VERSION,
1615
QtCore,
16+
parse,
1717
)
1818

1919
_now = datetime.now()

‎qtpy/tests/test_qtgui.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sys
44

55
import pytest
6-
from packaging.version import parse
76

87
from qtpy import (
98
PYQT5,
@@ -14,6 +13,7 @@
1413
QtCore,
1514
QtGui,
1615
QtWidgets,
16+
parse,
1717
)
1818
from qtpy.tests.utils import not_using_conda
1919

‎qtpy/tests/test_qttest.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
2-
from packaging import version
32

4-
from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE6, QtTest
3+
from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE6, QtTest, parse
54

65

76
def test_qttest():
@@ -12,7 +11,7 @@ def test_qttest():
1211
assert QtTest.QSignalSpy is not None
1312

1413
if (
15-
(PYQT5 and version.parse(PYQT_VERSION) >= version.parse("5.11"))
14+
(PYQT5 and parse(PYQT_VERSION) >= parse("5.11"))
1615
or PYQT6
1716
or PYSIDE6
1817
):

‎qtpy/tests/test_qttexttospeech.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import pytest
2-
from packaging import version
32

4-
from qtpy import PYQT5, PYQT_VERSION, PYSIDE2
3+
from qtpy import PYQT5, PYQT_VERSION, PYSIDE2, parse
54

65

76
@pytest.mark.skipif(
8-
not (
9-
(PYQT5 and version.parse(PYQT_VERSION) >= version.parse("5.15.1"))
10-
or PYSIDE2
11-
),
7+
not ((PYQT5 and parse(PYQT_VERSION) >= parse("5.15.1")) or PYSIDE2),
128
reason="Only available in Qt5 bindings (PyQt5 >= 5.15.1 or PySide2)",
139
)
1410
def test_qttexttospeech():

‎qtpy/tests/test_qtwebenginewidgets.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import pytest
2-
from packaging import version
32

4-
from qtpy import PYQT5, PYQT6, PYQT_VERSION, PYSIDE2, PYSIDE6, PYSIDE_VERSION
3+
from qtpy import (
4+
PYQT5,
5+
PYQT6,
6+
PYQT_VERSION,
7+
PYSIDE2,
8+
PYSIDE6,
9+
PYSIDE_VERSION,
10+
parse,
11+
)
512
from qtpy.tests.utils import pytest_importorskip
613

714

815
@pytest.mark.skipif(
916
not (
10-
(PYQT6 and version.parse(PYQT_VERSION) >= version.parse("6.2"))
11-
or (PYSIDE6 and version.parse(PYSIDE_VERSION) >= version.parse("6.2"))
17+
(PYQT6 and parse(PYQT_VERSION) >= parse("6.2"))
18+
or (PYSIDE6 and parse(PYSIDE_VERSION) >= parse("6.2"))
1219
or PYQT5
1320
or PYSIDE2
1421
),

‎qtpy/tests/test_uic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import warnings
55

66
import pytest
7-
from packaging.version import parse
87

9-
from qtpy import PYSIDE2, PYSIDE6, PYSIDE_VERSION, QtWidgets
8+
from qtpy import PYSIDE2, PYSIDE6, PYSIDE_VERSION, QtWidgets, parse
109
from qtpy.QtWidgets import QComboBox
1110
from qtpy.tests.utils import pytest_importorskip, using_conda
1211

‎qtpy/tests/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44

55
import pytest
6-
from packaging.version import parse
6+
7+
from qtpy import parse
78

89

910
def using_conda():

0 commit comments

Comments
 (0)
Please sign in to comment.