Skip to content

Commit

Permalink
Merge pull request #289 from CAM-Gerlach/add-depr-warning-qt5
Browse files Browse the repository at this point in the history
PR: Add warning for deprecated/EoL Qt5 & PyQt5/PySide2 versions to fix #284
  • Loading branch information
dalthviz authored Dec 1, 2021
2 parents 519ac9c + aa44fea commit 1e380ae
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions qtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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)

0 comments on commit 1e380ae

Please sign in to comment.