From c8fd4b6101c2745f029160fc81f0a87da2c7c379 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Wed, 17 Nov 2021 17:52:22 -0600 Subject: [PATCH] Add a warning for users still running legacy Qt4-based APIs to fix #261 --- .github/workflows/ci.yml | 2 ++ qtpy/__init__.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b17fee8..c1ece0d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,9 +5,11 @@ on: push: branches: - master + - '*.x' pull_request: branches: - master + - '*.x' jobs: linux: diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 4393ee6d..aebaa2d7 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -101,6 +101,9 @@ class PythonQtWarning(Warning): # Names of the expected PySide2 api PYSIDE2_API = ['pyside2'] +# Names of the legacy APIs that we should warn users about +LEGACY_APIS = PYQT4_API + PYSIDE_API + # Detecting if a binding was specified by the user binding_specified = QT_API in os.environ @@ -236,4 +239,15 @@ class PythonQtWarning(Warning): # Only available for Qt5 bindings > 5.9 on Windows from . import QtDataVisualization as QtDatavisualization except (ImportError, PythonQtError): - pass \ No newline at end of file + pass + +# 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( + "A deprecated Qt4-based binding (PyQt4/PySide) was installed, " + "imported or set via the 'QT_API' environment variable. " + "To ensure your application is still supported in QtPy 2.0, " + "please make sure it doesn't depend upon, import or " + "set the 'QT_API' env var to 'pyqt', 'pyqt4' or 'pyside'.", + DeprecationWarning, + )