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)

Check warning on line 49 in python/tank/authentication/interactive_authentication.py

View check run for this annotation

Codecov / codecov/patch

python/tank/authentication/interactive_authentication.py#L48-L49

Added lines #L48 - L49 were not covered by tests
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)

Check warning on line 34 in python/tank/authentication/invoker.py

View check run for this annotation

Codecov / codecov/patch

python/tank/authentication/invoker.py#L33-L34

Added lines #L33 - L34 were not covered by tests
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)

Check warning on line 36 in python/tank/authentication/ui_authentication.py

View check run for this annotation

Codecov / codecov/patch

python/tank/authentication/ui_authentication.py#L35-L36

Added lines #L35 - L36 were not covered by tests
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

Check warning on line 17 in python/tank/bootstrap/async_bootstrap.py

View check run for this annotation

Codecov / codecov/patch

python/tank/bootstrap/async_bootstrap.py#L14-L17

Added lines #L14 - L17 were not covered by tests
else:
QtCore = importer.QtCore
QtGui = importer.QtGui

Check warning on line 20 in python/tank/bootstrap/async_bootstrap.py

View check run for this annotation

Codecov / codecov/patch

python/tank/bootstrap/async_bootstrap.py#L19-L20

Added lines #L19 - L20 were not covered by tests


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

Check warning on line 188 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L186-L188

Added lines #L186 - L188 were not covered by tests

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:

Check warning on line 416 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L416

Added line #L416 was not covered by tests
# 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))

Check warning on line 422 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L422

Added line #L422 was not covered by tests

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:

Check warning on line 2152 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L2152

Added line #L2152 was not covered by tests

self.log_exception(
self.log_error(

Check warning on line 2154 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L2154

Added line #L2154 was not covered by tests
"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 {}

Check warning on line 2176 in python/tank/platform/engine.py

View check run for this annotation

Codecov / codecov/patch

python/tank/platform/engine.py#L2174-L2176

Added lines #L2174 - L2176 were not covered by tests

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

Check warning on line 54 in python/tank/util/qt_importer.py

View check run for this annotation

Codecov / codecov/patch

python/tank/util/qt_importer.py#L53-L54

Added lines #L53 - L54 were not covered by tests

@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)

Check warning on line 400 in python/tank/util/qt_importer.py

View check run for this annotation

Codecov / codecov/patch

python/tank/util/qt_importer.py#L399-L400

Added lines #L399 - L400 were not covered by tests
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.")

Check warning on line 403 in python/tank/util/qt_importer.py

View check run for this annotation

Codecov / codecov/patch

python/tank/util/qt_importer.py#L403

Added line #L403 was not covered by tests

0 comments on commit a320063

Please sign in to comment.