diff --git a/python/tank/authentication/interactive_authentication.py b/python/tank/authentication/interactive_authentication.py index 3207fd923..8ff9406d5 100644 --- a/python/tank/authentication/interactive_authentication.py +++ b/python/tank/authentication/interactive_authentication.py @@ -41,13 +41,14 @@ # something usually done by the Toolkit. The worry is that the import may fail # in the context of a DCC, but occur too early for the Toolkit logging to be # fully in place to record it. +logger = LogManager.get_logger(__name__) + try: from .ui.qt_abstraction import QtGui -except Exception: +except ImportError as e: + logger.debug("Cant import QtGui: %s" %e) QtGui = None -logger = LogManager.get_logger(__name__) - ############################################################################################### # internal classes and methods diff --git a/python/tank/authentication/invoker.py b/python/tank/authentication/invoker.py index 09b2f8532..de24b1ca6 100644 --- a/python/tank/authentication/invoker.py +++ b/python/tank/authentication/invoker.py @@ -30,7 +30,8 @@ # fully in place to record it. try: from .ui.qt_abstraction import QtCore, QtGui -except Exception: +except ImportError as e: + logger.debug("Cant import QtCore/QtGui: %s" % e) QtCore, QtGui = None, None diff --git a/python/tank/authentication/sso_saml2/core/username_password_dialog.py b/python/tank/authentication/sso_saml2/core/username_password_dialog.py index ef2856942..86029e0f9 100644 --- a/python/tank/authentication/sso_saml2/core/username_password_dialog.py +++ b/python/tank/authentication/sso_saml2/core/username_password_dialog.py @@ -13,12 +13,10 @@ from __future__ import print_function -# pylint: disable=import-error -from ...ui.qt_abstraction import QtCore, QtGui - -# No point in proceeding if QtGui is None. -if QtGui is None: - raise ImportError("Unable to import QtGui") +try: + from ...ui.qt_abstraction import QtCore, QtGui +except ImportError: + raise class UsernamePasswordDialog(QtGui.QDialog): diff --git a/python/tank/authentication/ui_authentication.py b/python/tank/authentication/ui_authentication.py index 486262e6a..6f68effff 100644 --- a/python/tank/authentication/ui_authentication.py +++ b/python/tank/authentication/ui_authentication.py @@ -32,7 +32,8 @@ # fully in place to record it. try: from .login_dialog import LoginDialog -except Exception: +except ImportError as e: + logger.debug("Cant import LoginDialog: %s" % e) LoginDialog = None diff --git a/python/tank/bootstrap/async_bootstrap.py b/python/tank/bootstrap/async_bootstrap.py index 39abebb9d..22bd12377 100644 --- a/python/tank/bootstrap/async_bootstrap.py +++ b/python/tank/bootstrap/async_bootstrap.py @@ -11,12 +11,13 @@ # Import Qt without having to worry about the version to use. from ..util.qt_importer import QtImporter -importer = QtImporter() -QtCore = importer.QtCore -QtGui = importer.QtGui -if QtCore is None: - # Raise an exception when Qt is not available. - raise ImportError +try: + importer = QtImporter() +except ImportError: + raise +else: + QtCore = importer.QtCore + QtGui = importer.QtGui class AsyncBootstrapWrapper(QtCore.QObject): diff --git a/python/tank/platform/engine.py b/python/tank/platform/engine.py index b7d9ad4cf..f5e79c14f 100644 --- a/python/tank/platform/engine.py +++ b/python/tank/platform/engine.py @@ -181,7 +181,11 @@ def __init__(self, tk, context, engine_instance_name, env): # Update the authentication module to use the engine's Qt. # @todo: can this import be untangled? Code references internal part of the auth module - from ..authentication.ui import qt_abstraction + try: + from ..authentication.ui import qt_abstraction + except ImportError: + class qt_abstraction: + pass qt_abstraction.QtCore = qt.QtCore qt_abstraction.QtGui = qt.QtGui @@ -409,13 +413,13 @@ def __show_busy(self, title, details): from .qt.busy_dialog import BusyDialog from .qt import QtGui, QtCore - except: + except ImportError as e: # QT import failed. This may be because someone has upgraded the core # to the latest but are still running a earlier version of the # Shotgun or Shell engine where the self.has_ui method is not # correctly implemented. In that case, absorb the error and # emit a log message - self.log_info("[%s] %s" % (title, details)) + self.log_info("[%s] %s: %s" % (title, details, e)) else: # our qt import worked! @@ -2135,7 +2139,7 @@ def _define_qt_base(self): :returns: dict """ - base = {"qt_core": None, "qt_gui": None, "dialog_base": None} + base = {"qt_core": None, "qt_gui": None, "dialog_base": None, "wrapper": None} try: importer = QtImporter() base["qt_core"] = importer.QtCore @@ -2145,11 +2149,11 @@ def _define_qt_base(self): else: base["dialog_base"] = None base["wrapper"] = importer.binding - except: + except ImportError: - self.log_exception( + self.log_error( "Default engine QT definition failed to find QT. " - "This may need to be subclassed." + "This may need to be subclassed" ) return base @@ -2165,7 +2169,11 @@ def __define_qt5_base(self): :returns: A dictionary with all the modules, __version__ and __name__. """ - return QtImporter(interface_version_requested=QtImporter.QT5).base + try: + return QtImporter(interface_version_requested=QtImporter.QT5).base + except ImportError as e: + self.log_debug(e) + return {} def _initialize_dark_look_and_feel(self): """ diff --git a/python/tank/util/qt_importer.py b/python/tank/util/qt_importer.py index b03c443ed..2151bc239 100644 --- a/python/tank/util/qt_importer.py +++ b/python/tank/util/qt_importer.py @@ -26,7 +26,7 @@ class QtImporter(object): .. code-block:: python try: importer = QtImporter() - except Exception as e: + except ImportError as e: print "Couldn't import a Qt Wrapper: " % (e,) else: importer.QtGui.QApplication([]) @@ -42,13 +42,16 @@ def __init__(self, interface_version_requested=QT4): :param interface_version_request: Indicates which version of the Qt API is requested. """ - ( - self._binding_name, - self._binding_version, - self._binding, - self._modules, - self._qt_version_tuple, - ) = self._import_modules(interface_version_requested) + try: + ( + self._binding_name, + self._binding_version, + self._binding, + self._modules, + self._qt_version_tuple, + ) = self._import_modules(interface_version_requested) + except ImportError: + raise @property def QtCore(self): @@ -397,6 +400,4 @@ def _import_modules(self, interface_version_requested): logger.debug("Cant import PyQt4: %s" % e) pass - logger.debug("No Qt matching that interface was found.") - - return (None, None, None, None, None) + raise ImportError("No Qt matching that interface was found.")