From aa44fea99120e6c793c2fdbff9df99be951b074a Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Mon, 29 Nov 2021 15:02:46 -0600 Subject: [PATCH] Add warning for deprecated/EoL Qt5 & PyQt5/PySide2 versions to fix #284 --- qtpy/__init__.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/qtpy/__init__.py b/qtpy/__init__.py index aebaa2d7..6d978ae3 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -104,6 +104,11 @@ class PythonQtWarning(Warning): # Names of the legacy APIs that we should warn users about LEGACY_APIS = PYQT4_API + PYSIDE_API +# Minimum fully supported versions of Qt and the bindings +PYQT_VERSION_MIN = '5.9.0' +PYSIDE_VERSION_MIN = '5.12.0' +QT_VERSION_MIN = '5.9.0' + # Detecting if a binding was specified by the user binding_specified = QT_API in os.environ @@ -241,6 +246,17 @@ class PythonQtWarning(Warning): except (ImportError, PythonQtError): pass + +def _warn_old_minor_version(name, old_version, min_version): + warning_message = ( + "{name} version {old_version} is unsupported upstream and " + "deprecated by QtPy. To ensure your application is still supported " + "in QtPy 2.0, please make sure it doesn't depend upon {name} versions " + "older than {min_version}.".format( + name=name, old_version=old_version, min_version=min_version)) + warnings.warn(warning_message, DeprecationWarning) + + # Warn if using a legacy, soon to be unsupported Qt API/binding if API in LEGACY_APIS or initial_api in LEGACY_APIS: warnings.warn( @@ -251,3 +267,12 @@ class PythonQtWarning(Warning): "set the 'QT_API' env var to 'pyqt', 'pyqt4' or 'pyside'.", DeprecationWarning, ) +else: + if LooseVersion(QT_VERSION) < LooseVersion(QT_VERSION_MIN): + _warn_old_minor_version('Qt', QT_VERSION, QT_VERSION_MIN) + if PYQT_VERSION and (LooseVersion(PYQT_VERSION) + < LooseVersion(PYQT_VERSION_MIN)): + _warn_old_minor_version('PyQt', PYQT_VERSION, PYQT_VERSION_MIN) + elif PYSIDE_VERSION and (LooseVersion(PYSIDE_VERSION) + < LooseVersion(PYSIDE_VERSION_MIN)): + _warn_old_minor_version('PySide', PYSIDE_VERSION, PYSIDE_VERSION_MIN)