From 1fe2e9f868b53b259309214bab6e03fb22773f16 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 18 Dec 2024 12:26:32 -0800 Subject: [PATCH] qtpy: use our internal parse() as a fallback when packaging.version.parse() is not installed Continue relying on packaging.version.parse() when it is installed. Our internal parsing code is now used as a fallback instead. Suggested-by: @dalthviz in #508 --- qtpy/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 8119c26e..14360e18 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -194,7 +194,12 @@ def _parse_int(value): def _parse_version(version): """Parse a version string into a tuple of ints""" - return tuple(_parse_int(x) for x in version.split(".")) + try: + from packaging.version import parse as _packaging_version_parse + except ImportError: + return tuple(_parse_int(x) for x in version.split(".")) + else: + return _packaging_version_parse(version) # Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings