Skip to content

Commit

Permalink
🏗️ QtImporter raise importError instead of returning none
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu committed Jan 31, 2023
1 parent 7739093 commit a320063
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
7 changes: 4 additions & 3 deletions python/tank/authentication/interactive_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion python/tank/authentication/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion python/tank/authentication/ui_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
13 changes: 7 additions & 6 deletions python/tank/bootstrap/async_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 16 additions & 8 deletions python/tank/platform/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down
23 changes: 12 additions & 11 deletions python/tank/util/qt_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -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):
Expand Down Expand Up @@ -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.")

0 comments on commit a320063

Please sign in to comment.