From 2c83f4832be25851cf6728f444a118f8305ccc4a Mon Sep 17 00:00:00 2001 From: John Haddon Date: Fri, 1 Dec 2023 14:30:04 +0000 Subject: [PATCH] Revert "Prefer `contextlib.suppress()` to `IECore.IgnoredExceptions`" This reverts commit b1a04bd7ed9fbebda6c47296abb54d5781f57a32, which was now clearly a bad idea because `IgnoredExceptions` clears `__traceback__` and `suppress` doesn't. See https://github.com/ImageEngine/cortex/commit/0d42ae02b0bd17e366fc59726d95b0978f50f363. --- python/Gaffer/DictPath.py | 4 +--- python/Gaffer/PythonExpressionEngine.py | 3 +-- python/Gaffer/SequencePath.py | 3 +-- python/GafferCortex/IndexedIOPath.py | 4 +--- python/GafferCortex/ObjectReader.py | 4 +--- python/GafferCortex/ObjectWriter.py | 3 +-- python/GafferCortex/OpMatcher.py | 9 ++++----- python/GafferCortex/ParameterPath.py | 4 +--- .../GafferCortexUI/ClassParameterValueWidget.py | 4 +--- .../ClassVectorParameterValueWidget.py | 8 +++----- .../CompoundParameterValueWidget.py | 8 +++----- .../CompoundVectorParameterValueWidget.py | 16 +++++++--------- .../FileSequenceParameterValueWidget.py | 6 ++---- python/GafferCortexUI/OpDialogue.py | 11 +++++------ python/GafferCortexUI/ParameterPresets.py | 3 +-- python/GafferCortexUI/ParameterValueWidget.py | 4 +--- python/GafferCortexUI/ParameterisedHolderUI.py | 3 +-- .../GafferCortexUI/PathParameterValueWidget.py | 4 +--- .../PathVectorParameterValueWidget.py | 3 +-- .../GafferCortexUI/StringParameterValueWidget.py | 8 +++----- python/GafferDispatch/PythonCommand.py | 3 +-- python/GafferImageUI/CatalogueUI.py | 3 +-- python/GafferImageUI/ImageReaderUI.py | 4 +--- python/GafferSceneUI/CryptomatteUI.py | 3 +-- python/GafferSceneUI/TransformToolUI.py | 3 +-- python/GafferTest/ComputeNodeTest.py | 3 +-- python/GafferTractorTest/__init__.py | 4 ++-- python/GafferUI/Backups.py | 3 +-- python/GafferUI/CodeWidget.py | 3 +-- python/GafferUI/DataPathPreview.py | 4 +--- python/GafferUI/DotUI.py | 3 +-- python/GafferUI/FileMenu.py | 3 +-- python/GafferUI/HeaderPathPreview.py | 5 ++--- python/GafferUI/LazyMethod.py | 5 ++--- python/GafferUI/MatchPatternPathFilterWidget.py | 11 +++++------ python/GafferUI/Menu.py | 3 +-- python/GafferUI/MultiLineTextWidget.py | 3 +-- python/GafferUI/NodeMenu.py | 3 +-- python/GafferUI/PathFilterWidget.py | 10 ++++------ python/GafferUI/PlugValueWidget.py | 5 ++--- python/GafferUI/SpreadsheetUI/_PlugTableView.py | 3 +-- python/GafferUI/TweakPlugValueWidget.py | 3 +-- python/GafferUI/VectorDataWidget.py | 3 +-- python/GafferUITest/GraphGadgetTest.py | 3 +-- startup/dispatch/gui.py | 4 +--- startup/gui/lightEditor.py | 5 ++--- startup/gui/menus.py | 3 +-- startup/gui/ocio.py | 4 +--- startup/gui/outputs.py | 7 +++---- startup/gui/project.py | 5 ++--- startup/gui/shaderPresets.py | 7 +++---- startup/gui/shaderView.py | 5 ++--- startup/gui/viewer.py | 7 +++---- 53 files changed, 93 insertions(+), 162 deletions(-) diff --git a/python/Gaffer/DictPath.py b/python/Gaffer/DictPath.py index ed5c719b0ba..5e66af0c6f0 100644 --- a/python/Gaffer/DictPath.py +++ b/python/Gaffer/DictPath.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -81,7 +79,7 @@ def propertyNames( self, canceller = None ) : def property( self, name, canceller = None ) : if name == "dict:value" : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : e = self.__dictEntry() if not isinstance( e, self.__dictTypes ) : return e diff --git a/python/Gaffer/PythonExpressionEngine.py b/python/Gaffer/PythonExpressionEngine.py index 3fd661de1c8..80a1451be55 100644 --- a/python/Gaffer/PythonExpressionEngine.py +++ b/python/Gaffer/PythonExpressionEngine.py @@ -37,7 +37,6 @@ import re import ast -import contextlib import functools import inspect import pathlib @@ -373,7 +372,7 @@ def __compoundObjectPlugValueExtractor( plug, topLevelPlug, value ) : def __defaultValueExtractor( plug, topLevelPlug, value ) : - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : value = value.value # Deal with the simple atomic plug case. diff --git a/python/Gaffer/SequencePath.py b/python/Gaffer/SequencePath.py index 01712fa1514..46252eb0aaf 100644 --- a/python/Gaffer/SequencePath.py +++ b/python/Gaffer/SequencePath.py @@ -35,7 +35,6 @@ ########################################################################## import collections -import contextlib import IECore @@ -155,7 +154,7 @@ def __basePath( self, path ) : def __basePaths( self ) : sequence = None - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : sequence = IECore.FileSequence( str( self ) ) result = [] diff --git a/python/GafferCortex/IndexedIOPath.py b/python/GafferCortex/IndexedIOPath.py index 3328f601ff5..1b9da32bd51 100644 --- a/python/GafferCortex/IndexedIOPath.py +++ b/python/GafferCortex/IndexedIOPath.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -86,7 +84,7 @@ def property( self, name, canceller = None ) : elif name == "indexedIO:dataType" : return e.dataType() if e.entryType() == IECore.IndexedIO.EntryType.File else None elif name == "indexedIO:arrayLength" : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : return e.arrayLength() return None diff --git a/python/GafferCortex/ObjectReader.py b/python/GafferCortex/ObjectReader.py index 0bc9454d6ab..01f897f702a 100644 --- a/python/GafferCortex/ObjectReader.py +++ b/python/GafferCortex/ObjectReader.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -71,7 +69,7 @@ def compute( self, plug, context ) : assert( plug.isSame( self["out"] ) ) reader = None - with contextlib.suppress( RuntimeError ) : + with IECore.IgnoredExceptions( RuntimeError ) : reader = IECore.Reader.create( self["fileName"].getValue() ) plug.setValue( reader.read() if reader else plug.defaultValue() ) diff --git a/python/GafferCortex/ObjectWriter.py b/python/GafferCortex/ObjectWriter.py index ae48ea10514..6bf7042f7d3 100644 --- a/python/GafferCortex/ObjectWriter.py +++ b/python/GafferCortex/ObjectWriter.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -112,7 +111,7 @@ def __ensureWriter( self ) : self.__writer = None self.__exposedParameters.clearParameters() - with contextlib.suppress( RuntimeError ) : + with IECore.IgnoredExceptions( RuntimeError ) : self.__writer = IECore.Writer.create( fileName ) if self.__writer is not None : diff --git a/python/GafferCortex/OpMatcher.py b/python/GafferCortex/OpMatcher.py index 78c8350805f..ce4b803ecc2 100644 --- a/python/GafferCortex/OpMatcher.py +++ b/python/GafferCortex/OpMatcher.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import threading import traceback import weakref @@ -73,10 +72,10 @@ def __init__( self, classLoader, classNamesMatchString = "*", reportErrors=True continue ignore = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : # backwards compatibility with something proprietary ignore = opInstance.userData()["UI"]["OpMatcher"]["ignore"].value - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : ignore = opInstance.userData()["OpMatcher"]["ignore"].value if ignore : continue @@ -151,10 +150,10 @@ def __findParameters( self, parameter, result, path = None ) : for child in parameter.values() : ignore = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : # backwards compatibility with something proprietary ignore = child.userData()["UI"]["OpMatcher"]["ignore"].value - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : # backwards compatibility with something proprietary ignore = child.userData()["OpMatcher"]["ignore"].value if ignore : diff --git a/python/GafferCortex/ParameterPath.py b/python/GafferCortex/ParameterPath.py index eea25cd096c..cfc1696a970 100644 --- a/python/GafferCortex/ParameterPath.py +++ b/python/GafferCortex/ParameterPath.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -75,7 +73,7 @@ def propertyNames( self, canceller = None ) : def property( self, name, canceller = None ) : if name == "parameter:parameter" : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : return self.__parameter() return None diff --git a/python/GafferCortexUI/ClassParameterValueWidget.py b/python/GafferCortexUI/ClassParameterValueWidget.py index c0ff0af10e2..f886e5717d2 100644 --- a/python/GafferCortexUI/ClassParameterValueWidget.py +++ b/python/GafferCortexUI/ClassParameterValueWidget.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import imath import IECore @@ -107,7 +105,7 @@ def __classMenu( self ) : classInfo = self._parameter().getClass( True ) classNameFilter = "*" - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : classNameFilter = self._parameter().userData()["UI"]["classNameFilter"].value menuPathStart = max( 0, classNameFilter.find( "*" ) ) diff --git a/python/GafferCortexUI/ClassVectorParameterValueWidget.py b/python/GafferCortexUI/ClassVectorParameterValueWidget.py index 4cc55f8a067..90d6e4afcaa 100644 --- a/python/GafferCortexUI/ClassVectorParameterValueWidget.py +++ b/python/GafferCortexUI/ClassVectorParameterValueWidget.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import imath import IECore @@ -157,7 +155,7 @@ def __classMenuDefinition( self ) : result = IECore.MenuDefinition() classNameFilter = "*" - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : classNameFilter = self._parameter().userData()["UI"]["classNameFilter"].value menuPathStart = max( 0, classNameFilter.find( "*" ) ) @@ -252,10 +250,10 @@ def _headerWidget( self ) : preHeaderParameters = [] headerParameters = [] for parameter in self.__parameterHandler.parameter().values() : - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : if parameter.userData()["UI"]["classVectorParameterPreHeader"].value : preHeaderParameters.append( parameter ) - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : if parameter.userData()["UI"]["classVectorParameterHeader"].value : headerParameters.append( parameter ) diff --git a/python/GafferCortexUI/CompoundParameterValueWidget.py b/python/GafferCortexUI/CompoundParameterValueWidget.py index caccb7d1263..e2158f347d2 100644 --- a/python/GafferCortexUI/CompoundParameterValueWidget.py +++ b/python/GafferCortexUI/CompoundParameterValueWidget.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import IECore import GafferUI @@ -59,13 +57,13 @@ def __init__( self, parameterHandler, collapsible=None, _plugValueWidgetClass=No if collapsible is None : collapsible = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : collapsible = parameterHandler.parameter().userData()["UI"]["collapsible"].value collapsed = None if collapsible : collapsed = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : collapsed = parameterHandler.parameter().userData()["UI"]["collapsed"].value if _plugValueWidgetClass is None : @@ -103,7 +101,7 @@ def _childPlugWidget( self, childPlug ) : childParameter = self.__parameterHandler.parameter()[childPlug.getName()] - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : if not childParameter.userData()["UI"]["visible"].value : return None diff --git a/python/GafferCortexUI/CompoundVectorParameterValueWidget.py b/python/GafferCortexUI/CompoundVectorParameterValueWidget.py index 5ce9ff87479..6777d6b2eba 100644 --- a/python/GafferCortexUI/CompoundVectorParameterValueWidget.py +++ b/python/GafferCortexUI/CompoundVectorParameterValueWidget.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import imath import IECore @@ -83,11 +81,11 @@ def _headerWidget( self ) : columnToolTips = [ self._parameterToolTip( self._parameterHandler().childParameterHandler( x ) ) for x in self._parameter().values() ] showIndices = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : showIndices = self._parameterHandler().parameter().userData()["UI"]["showIndices"].value sizeEditable = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : sizeEditable = self._parameterHandler().parameter().userData()["UI"]["sizeEditable"].value self.__vectorDataWidget = _VectorDataWidget( @@ -138,12 +136,12 @@ def _updateFromPlug( self ) : for columnIndex, childParameter in enumerate( self._parameter().values() ) : columnVisible = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : columnVisible = childParameter.userData()["UI"]["visible"].value self.__vectorDataWidget.setColumnVisible( columnIndex, columnVisible ) columnEditable = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : columnEditable = childParameter.userData()["UI"]["editable"].value self.__vectorDataWidget.setColumnEditable( columnIndex, columnEditable ) @@ -153,7 +151,7 @@ def __edit( self, vectorDataWidget, column, row ) : childParameter = self._parameter().values()[dataIndex] presetsOnly = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : presetsOnly = childParameter.userData()["UI"]["elementPresetsOnly"].value if not presetsOnly : @@ -282,12 +280,12 @@ def __parameterPopupMenu( menuDefinition, parameterValueWidget ) : parameter = parameterValueWidget.parameter() columnParameter = parameter.values()[vectorDataWidget.columnToDataIndex( column )[0]] - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : if columnParameter.userData()["UI"]["editable"].value == False : return presets = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : presets = columnParameter.userData()["UI"]["elementPresets"] if presets is None : diff --git a/python/GafferCortexUI/FileSequenceParameterValueWidget.py b/python/GafferCortexUI/FileSequenceParameterValueWidget.py index f186ce169e0..acada85c508 100644 --- a/python/GafferCortexUI/FileSequenceParameterValueWidget.py +++ b/python/GafferCortexUI/FileSequenceParameterValueWidget.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -85,7 +83,7 @@ def __isFileSequence( plug ) : return True if isinstance( parameter, IECore.PathParameter ) : - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : return parameter.userData()["UI"]["typeHint"].value == "includeSequences" return False @@ -105,7 +103,7 @@ def __includeFrameRange( plug ) : return None includeFrameRange = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : includeFrameRange = parameter.userData()["UI"]["includeFrameRange"].value return includeFrameRange diff --git a/python/GafferCortexUI/OpDialogue.py b/python/GafferCortexUI/OpDialogue.py index 7953e3bbb5b..f38b971d242 100644 --- a/python/GafferCortexUI/OpDialogue.py +++ b/python/GafferCortexUI/OpDialogue.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import enum import sys import threading @@ -128,7 +127,7 @@ def __init__( postExecuteBehaviour = self.PostExecuteBehaviour.DisplayResult d = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : d = opInstance.userData()["UI"]["postExecuteBehaviour"] if d is not None : for v in self.PostExecuteBehaviour.values() : @@ -137,7 +136,7 @@ def __init__( break else : # backwards compatibility with batata - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : d = opInstance.userData()["UI"]["closeAfterExecution"] if d is not None : postExecuteBehaviour = self.PostExecuteBehaviour.Close if d.value else self.PostExecuteBehaviour.DisplayResult @@ -266,7 +265,7 @@ def __initiateParameterEditing( self, *unused ) : self.__backButtonClickedConnection = self.__backButton.clickedSignal().connectFront( Gaffer.WeakMethod( self.__close ), scoped = True ) executeLabel = "OK" - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : executeLabel = self.__node.getParameterised()[0].userData()["UI"]["buttonLabel"].value self.__forwardButton.setText( executeLabel ) @@ -456,7 +455,7 @@ def __focusDefaultButton( self ) : if defaultButton == self.DefaultButton.FromUserData : defaultButton = self.DefaultButton.OK d = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : d = self.__node.getParameterised()[0].userData()["UI"]["defaultButton"] if d is not None : for v in self.DefaultButton.values() : @@ -485,7 +484,7 @@ def __messageCollapsibleStateChanged( self, collapsible ) : def __setUserDefaults( self, graphComponent ) : if isinstance( graphComponent, Gaffer.Plug ) and hasattr( graphComponent, "getValue" ) : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : Gaffer.Metadata.registerValue( graphComponent, "userDefault", graphComponent.getValue() ) for child in graphComponent.children() : diff --git a/python/GafferCortexUI/ParameterPresets.py b/python/GafferCortexUI/ParameterPresets.py index 99f4884644c..47ff1c9c803 100644 --- a/python/GafferCortexUI/ParameterPresets.py +++ b/python/GafferCortexUI/ParameterPresets.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import os import re import shutil @@ -108,7 +107,7 @@ def __searchPaths( self, owned, writable ) : existingPaths = [] for path in paths : if not os.path.isdir( path ) : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : os.makedirs( path ) if os.path.isdir( path ) : if owned and os.stat( path ).st_uid != os.getuid() : diff --git a/python/GafferCortexUI/ParameterValueWidget.py b/python/GafferCortexUI/ParameterValueWidget.py index da4cd74d0ba..3a5c5a716de 100644 --- a/python/GafferCortexUI/ParameterValueWidget.py +++ b/python/GafferCortexUI/ParameterValueWidget.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -89,7 +87,7 @@ def create( cls, parameterHandler ) : return GafferCortexUI.PresetsOnlyParameterValueWidget( parameterHandler ) uiTypeHint = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : uiTypeHint = parameter.userData()["UI"]["typeHint"].value parameterHierarchy = [ parameter.typeId() ] + IECore.RunTimeTyped.baseTypeIds( parameter.typeId() ) diff --git a/python/GafferCortexUI/ParameterisedHolderUI.py b/python/GafferCortexUI/ParameterisedHolderUI.py index 93b83eb94e7..d02d8e5c120 100644 --- a/python/GafferCortexUI/ParameterisedHolderUI.py +++ b/python/GafferCortexUI/ParameterisedHolderUI.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import re import pipes import fnmatch @@ -73,7 +72,7 @@ def __init__( self, node, **kw ) : headerVisible = True parameterised = self.node().getParameterised()[0] - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : headerVisible = parameterised.userData()["UI"]["headerVisible"].value with column : diff --git a/python/GafferCortexUI/PathParameterValueWidget.py b/python/GafferCortexUI/PathParameterValueWidget.py index 529c4720984..1e2d839d89d 100644 --- a/python/GafferCortexUI/PathParameterValueWidget.py +++ b/python/GafferCortexUI/PathParameterValueWidget.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -75,7 +73,7 @@ def _pathChooserDialogueKeywords( self ) : result = {} bookmarksCategory = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : bookmarksCategory = self.parameter().userData()["UI"]["bookmarksCategory"].value result["bookmarks"] = GafferUI.Bookmarks.acquire( # sometimes parameter widgets are used with nodes which are parented to an application, diff --git a/python/GafferCortexUI/PathVectorParameterValueWidget.py b/python/GafferCortexUI/PathVectorParameterValueWidget.py index 409b125928b..3482468b2d6 100644 --- a/python/GafferCortexUI/PathVectorParameterValueWidget.py +++ b/python/GafferCortexUI/PathVectorParameterValueWidget.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import re import os @@ -97,7 +96,7 @@ def __pathChooserDialogueKeywords( self ) : result = {} bookmarksCategory = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : bookmarksCategory = self.parameter().userData()["UI"]["bookmarksCategory"].value result["bookmarks"] = GafferUI.Bookmarks.acquire( diff --git a/python/GafferCortexUI/StringParameterValueWidget.py b/python/GafferCortexUI/StringParameterValueWidget.py index d3088605994..d4d1c90c3b3 100644 --- a/python/GafferCortexUI/StringParameterValueWidget.py +++ b/python/GafferCortexUI/StringParameterValueWidget.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -61,7 +59,7 @@ class StringParameterValueWidget( GafferCortexUI.ParameterValueWidget ) : def __init__( self, parameterHandler, **kw ) : multiLine = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : multiLine = parameterHandler.parameter().userData()["UI"]["multiLine"].value if multiLine : @@ -69,7 +67,7 @@ def __init__( self, parameterHandler, **kw ) : else : plugValueWidget = GafferUI.StringPlugValueWidget( parameterHandler.plug() ) - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : if parameterHandler.parameter().userData()["UI"]["password"].value : plugValueWidget.textWidget().setDisplayMode( GafferUI.TextWidget.DisplayMode.Password ) @@ -97,7 +95,7 @@ def __fixedLineHeight( plug ) : # for a brief description, for this reason we check by the user data "multiLineFixedLineHeight" which when set # forces the parameter to show an arbitrary number of lines fixedLineHeight = None - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : fixedLineHeight = parameter.userData()["UI"]["multiLineFixedLineHeight"].value return fixedLineHeight diff --git a/python/GafferDispatch/PythonCommand.py b/python/GafferDispatch/PythonCommand.py index 1a57290a80c..5478d70573e 100644 --- a/python/GafferDispatch/PythonCommand.py +++ b/python/GafferDispatch/PythonCommand.py @@ -35,7 +35,6 @@ ########################################################################## import ast -import contextlib import IECore import imath @@ -173,7 +172,7 @@ def __update( self ) : value, name = self.__variables.memberDataAndName( plug ) if value is None : continue - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : value = value.value self[name] = value diff --git a/python/GafferImageUI/CatalogueUI.py b/python/GafferImageUI/CatalogueUI.py index 1125c151573..1c84eba28ca 100644 --- a/python/GafferImageUI/CatalogueUI.py +++ b/python/GafferImageUI/CatalogueUI.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import functools import imath @@ -101,7 +100,7 @@ def cellData( self, path, canceller = None ) : # Suppress error. The GraphEditor will be displaying the # error anyway, as will the standard type column, and we're # not in a position to do anything more helpful. - with contextlib.suppress( Gaffer.ProcessException ) : + with IECore.IgnoredExceptions( Gaffer.ProcessException ) : # Call `_imageCellData()` in a context which causes the Catalogue # to output the image of interest. diff --git a/python/GafferImageUI/ImageReaderUI.py b/python/GafferImageUI/ImageReaderUI.py index 9b069e7e9d5..94dfa98481d 100644 --- a/python/GafferImageUI/ImageReaderUI.py +++ b/python/GafferImageUI/ImageReaderUI.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -309,7 +307,7 @@ def _valuesForUpdate( plugs, auxiliaryPlugs ) : automaticSpace = "" if len( colorSpacePlugs ) and preset == "Automatic" : - with contextlib.suppress( Gaffer.ProcessException ) : + with IECore.IgnoredExceptions( Gaffer.ProcessException ) : automaticSpace = colorSpacePlugs[0].getValue() or "Working Space" result.append( { diff --git a/python/GafferSceneUI/CryptomatteUI.py b/python/GafferSceneUI/CryptomatteUI.py index 15db3f93a92..d23e669944c 100644 --- a/python/GafferSceneUI/CryptomatteUI.py +++ b/python/GafferSceneUI/CryptomatteUI.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import enum import functools import imath @@ -79,7 +78,7 @@ def __getManifest( self ) : cryptomatteNode = _findCryptomatteNode( self.getPlug() ) if cryptomatteNode : with self.getContext() : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : return cryptomatteNode["__manifest"].getValue() return None diff --git a/python/GafferSceneUI/TransformToolUI.py b/python/GafferSceneUI/TransformToolUI.py index e1eee9e4fb1..4233a108421 100644 --- a/python/GafferSceneUI/TransformToolUI.py +++ b/python/GafferSceneUI/TransformToolUI.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import sys import imath @@ -86,7 +85,7 @@ def __init__( self, imageView, **kw ) : def _boldFormatter( graphComponents ) : - with contextlib.suppress( ValueError ) : + with IECore.IgnoredExceptions( ValueError ) : ## \todo Should the NameLabel ignore ScriptNodes and their ancestors automatically? scriptNodeIndex = [ isinstance( g, Gaffer.ScriptNode ) for g in graphComponents ].index( True ) graphComponents = graphComponents[scriptNodeIndex+1:] diff --git a/python/GafferTest/ComputeNodeTest.py b/python/GafferTest/ComputeNodeTest.py index 5641de71151..7a3792f3082 100644 --- a/python/GafferTest/ComputeNodeTest.py +++ b/python/GafferTest/ComputeNodeTest.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import inspect import unittest import threading @@ -445,7 +444,7 @@ def f( *unusedArgs ) : n = GafferTest.BadNode() c = n.errorSignal().connect( f, scoped = True ) - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : n["out1"].getValue() self.assertTrue( self.fRan ) diff --git a/python/GafferTractorTest/__init__.py b/python/GafferTractorTest/__init__.py index 62a08ef4181..d34da3782aa 100644 --- a/python/GafferTractorTest/__init__.py +++ b/python/GafferTractorTest/__init__.py @@ -43,11 +43,11 @@ def tractorAPI() : import types - import contextlib + import IECore # Use the real API if it is available. - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : from tractor.api.author import author return author diff --git a/python/GafferUI/Backups.py b/python/GafferUI/Backups.py index 79b7ba1a6ff..7e8ce7b3e40 100644 --- a/python/GafferUI/Backups.py +++ b/python/GafferUI/Backups.py @@ -41,7 +41,6 @@ from Qt import QtCore import collections -import contextlib import pathlib import re import stat @@ -99,7 +98,7 @@ def backup( self, script ) : # temporarily make it writable. If this fails for # any reason we leave it to `serialiseToFile()` to # throw. - with contextlib.suppress( OSError ) : + with IECore.IgnoredExceptions( OSError ) : path.chmod( stat.S_IWUSR ) script.serialiseToFile( path ) diff --git a/python/GafferUI/CodeWidget.py b/python/GafferUI/CodeWidget.py index 631bb54ccf1..7c6a32547ac 100644 --- a/python/GafferUI/CodeWidget.py +++ b/python/GafferUI/CodeWidget.py @@ -42,7 +42,6 @@ import keyword import tokenize import collections -import contextlib import io import imath @@ -534,7 +533,7 @@ def __attrAndItemCompletions( self, text ) : return [] items = [] for n in dir( rootObject ) : - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : items.append( ( n, getattr( rootObject, n ) ) ) return self.__completions( items = items, diff --git a/python/GafferUI/DataPathPreview.py b/python/GafferUI/DataPathPreview.py index 24cb8ef3813..4427974428e 100644 --- a/python/GafferUI/DataPathPreview.py +++ b/python/GafferUI/DataPathPreview.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -61,7 +59,7 @@ def isValid( self ) : def _load( self ) : data = None - with contextlib.suppress( RuntimeError ) : + with IECore.IgnoredExceptions( RuntimeError ) : data = self.getPath().data() return data diff --git a/python/GafferUI/DotUI.py b/python/GafferUI/DotUI.py index 7e71d18b70c..5e5297ebe8c 100644 --- a/python/GafferUI/DotUI.py +++ b/python/GafferUI/DotUI.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import functools import imath @@ -159,7 +158,7 @@ def __connectionContextMenu( graphEditor, destinationPlug, menuDefinition ) : applicationRoot = graphEditor.scriptNode().ancestor( Gaffer.ApplicationRoot ) connected = False - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : connected = applicationRoot.__dotUIConnected if not connected : diff --git a/python/GafferUI/FileMenu.py b/python/GafferUI/FileMenu.py index 1732cac76a0..cd1a9db1d52 100644 --- a/python/GafferUI/FileMenu.py +++ b/python/GafferUI/FileMenu.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import os import functools import imath @@ -169,7 +168,7 @@ def openRecent( menu ) : applicationRoot = currentScript.ancestor( Gaffer.ApplicationRoot ) recentFiles = [] - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : recentFiles = applicationRoot.__recentFiles result = IECore.MenuDefinition() diff --git a/python/GafferUI/HeaderPathPreview.py b/python/GafferUI/HeaderPathPreview.py index b9ce6d8d98a..0deafe4b2b1 100644 --- a/python/GafferUI/HeaderPathPreview.py +++ b/python/GafferUI/HeaderPathPreview.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -73,14 +72,14 @@ def isValid( self ) : def _load( self ) : reader = None - with contextlib.suppress( RuntimeError ) : + with IECore.IgnoredExceptions( RuntimeError ) : reader = IECore.Reader.create( str( self.getPath() ) ) if reader is None : return None header = None - with contextlib.suppress( RuntimeError ) : + with IECore.IgnoredExceptions( RuntimeError ) : header = reader.readHeader() return header diff --git a/python/GafferUI/LazyMethod.py b/python/GafferUI/LazyMethod.py index a11bc3a55eb..7a974e73e53 100644 --- a/python/GafferUI/LazyMethod.py +++ b/python/GafferUI/LazyMethod.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import weakref import functools import collections @@ -126,10 +125,10 @@ def flush( widget ) : def __playback( cls, widget ) : context = None - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : context = widget.getContext() if context is None : - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : context = widget.context() return GafferUI.Playback.acquire( context ) diff --git a/python/GafferUI/MatchPatternPathFilterWidget.py b/python/GafferUI/MatchPatternPathFilterWidget.py index a3a2437f96a..6342d26f5bb 100644 --- a/python/GafferUI/MatchPatternPathFilterWidget.py +++ b/python/GafferUI/MatchPatternPathFilterWidget.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import functools import IECore @@ -73,7 +72,7 @@ def __init__( self, pathFilter, **kw ) : def _updateFromPathFilter( self ) : editable = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : editable = self.pathFilter().userData()["UI"]["editable"].value self.__enabledWidget.setVisible( not editable ) @@ -81,7 +80,7 @@ def _updateFromPathFilter( self ) : self.__patternWidget.setVisible( editable ) label = str( self.pathFilter() ) - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : label = self.pathFilter().userData()["UI"]["label"].value if len(label) > 40: self.__enabledWidget.setToolTip( label ) @@ -90,7 +89,7 @@ def _updateFromPathFilter( self ) : self.__enabledWidget.setText( label ) invertEnabled = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : invertEnabled = self.pathFilter().userData()["UI"]["invertEnabled"].value self.__enabledWidget.setState( self.pathFilter().getEnabled() is not invertEnabled ) @@ -101,7 +100,7 @@ def __enabledStateChanged( self, widget ) : assert( widget is self.__enabledWidget ) invertEnabled = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : invertEnabled = self.pathFilter().userData()["UI"]["invertEnabled"].value with Gaffer.Signals.BlockedConnection( self._pathFilterChangedConnection() ) : @@ -167,7 +166,7 @@ def __propertyFilters( self ) : result = { "name": IECore.StringData( "Name" ), "filesystem:owner": IECore.StringData( "Owner" ) } - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : result = self.pathFilter().userData()["UI"]["propertyFilters"] return result diff --git a/python/GafferUI/Menu.py b/python/GafferUI/Menu.py index 630327bd0c8..7a74ed18bc6 100644 --- a/python/GafferUI/Menu.py +++ b/python/GafferUI/Menu.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import inspect import enum import functools @@ -366,7 +365,7 @@ def __build( self, qtMenu, recurse=False, forShortCuts=False ) : def __buildAction( self, item, name, parent ) : label = name - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : label = item.label if item.divider : diff --git a/python/GafferUI/MultiLineTextWidget.py b/python/GafferUI/MultiLineTextWidget.py index 97499efac5c..9c598c44649 100644 --- a/python/GafferUI/MultiLineTextWidget.py +++ b/python/GafferUI/MultiLineTextWidget.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import enum import imath @@ -336,7 +335,7 @@ def __buttonPress( self, widget, event ) : def __dropText( self, dragData ) : signal = None - with contextlib.suppress( AttributeError ) : + with IECore.IgnoredExceptions( AttributeError ) : signal = self.__dropTextSignal text = None diff --git a/python/GafferUI/NodeMenu.py b/python/GafferUI/NodeMenu.py index 3e6ad02c17f..c70e31fcb77 100644 --- a/python/GafferUI/NodeMenu.py +++ b/python/GafferUI/NodeMenu.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import inspect import imath @@ -104,7 +103,7 @@ def f( menu ) : script = graphEditor.scriptNode() commandArgs = [] - with contextlib.suppress( TypeError ) : + with IECore.IgnoredExceptions( TypeError ) : commandArgs = inspect.getfullargspec( nodeCreator ).args with Gaffer.UndoScope( script ) : diff --git a/python/GafferUI/PathFilterWidget.py b/python/GafferUI/PathFilterWidget.py index e0f34e8c3e3..482a59ba7be 100644 --- a/python/GafferUI/PathFilterWidget.py +++ b/python/GafferUI/PathFilterWidget.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -80,7 +78,7 @@ def __pathFilterChanged( self, pathFilter ) : def create( cls, pathFilter ) : visible = True - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : visible = pathFilter.userData()["UI"]["visible"].value if not visible : @@ -120,19 +118,19 @@ def __init__( self, pathFilter ) : def _updateFromPathFilter( self ) : label = str( self.pathFilter() ) - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : label = self.pathFilter().userData()["UI"]["label"].value self.__checkBox.setText( label ) invertEnabled = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : invertEnabled = self.pathFilter().userData()["UI"]["invertEnabled"].value self.__checkBox.setState( self.pathFilter().getEnabled() is not invertEnabled ) def __stateChanged( self, checkBox ) : invertEnabled = False - with contextlib.suppress( KeyError ) : + with IECore.IgnoredExceptions( KeyError ) : invertEnabled = self.pathFilter().userData()["UI"]["invertEnabled"].value self.pathFilter().setEnabled( checkBox.getState() is not invertEnabled ) diff --git a/python/GafferUI/PlugValueWidget.py b/python/GafferUI/PlugValueWidget.py index dfae0c4220a..d8e58c4a2a7 100644 --- a/python/GafferUI/PlugValueWidget.py +++ b/python/GafferUI/PlugValueWidget.py @@ -36,7 +36,6 @@ ########################################################################## import collections -import contextlib import functools import inspect import itertools @@ -415,7 +414,7 @@ def _convertValue( self, value ) : if hasattr( value, "value" ) : dataValue = value.value else : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : if len( value ) == 1 : dataValue = value[0] @@ -424,7 +423,7 @@ def _convertValue( self, value ) : elif isinstance( dataValue, plugValueType ) : return dataValue else : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : return plugValueType( dataValue ) return None diff --git a/python/GafferUI/SpreadsheetUI/_PlugTableView.py b/python/GafferUI/SpreadsheetUI/_PlugTableView.py index e1f11410983..3049aaa30fc 100755 --- a/python/GafferUI/SpreadsheetUI/_PlugTableView.py +++ b/python/GafferUI/SpreadsheetUI/_PlugTableView.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import enum import functools @@ -1250,7 +1249,7 @@ def __canChangeEnabledState( self, enabledPlugs ) : enabled = True with self.ancestor( GafferUI.PlugValueWidget ).getContext() : - with contextlib.suppress( Gaffer.ProcessException ) : + with IECore.IgnoredExceptions( Gaffer.ProcessException ) : enabled = all( [ plug.getValue() for plug in enabledPlugs ] ) return ( allSettable and not anyReadOnly, enabled ) diff --git a/python/GafferUI/TweakPlugValueWidget.py b/python/GafferUI/TweakPlugValueWidget.py index e40591d970c..4c7d08f8686 100644 --- a/python/GafferUI/TweakPlugValueWidget.py +++ b/python/GafferUI/TweakPlugValueWidget.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import functools import re @@ -219,7 +218,7 @@ def __noduleLabel( plug ) : plug = plug.parent() name = None - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : name = plug["name"].getValue() return name or plug.getName() diff --git a/python/GafferUI/VectorDataWidget.py b/python/GafferUI/VectorDataWidget.py index c4939c163b6..7bc8bb57653 100644 --- a/python/GafferUI/VectorDataWidget.py +++ b/python/GafferUI/VectorDataWidget.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import functools import imath @@ -503,7 +502,7 @@ def __modelDataChanged( self, topLeft, bottomRight, roles ) : continue # we have to ignore exceptions, as the items we're setting might # have a different data type than the value we're passing. - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : self.__model.setData( index, valueToPropagate, QtCore.Qt.EditRole ) self.__propagatingDataChangesToSelection = False diff --git a/python/GafferUITest/GraphGadgetTest.py b/python/GafferUITest/GraphGadgetTest.py index 82e06044865..7f887d5d316 100644 --- a/python/GafferUITest/GraphGadgetTest.py +++ b/python/GafferUITest/GraphGadgetTest.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import unittest import threading import imath @@ -1049,7 +1048,7 @@ def testErrorAndDelete( self ) : # a background thread. def f() : - with contextlib.suppress( Exception ) : + with IECore.IgnoredExceptions( Exception ) : script["n"]["out1"].getValue() r = threading.Thread( target = f ) diff --git a/startup/dispatch/gui.py b/startup/dispatch/gui.py index a8db5eab6f4..b344148fbec 100644 --- a/startup/dispatch/gui.py +++ b/startup/dispatch/gui.py @@ -34,8 +34,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -58,7 +56,7 @@ "GafferDelightUI", "GafferTractorUI", ) : - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : __import__( module ) menu = GafferDispatchUI.DispatchDialogue.menuDefinition() diff --git a/startup/gui/lightEditor.py b/startup/gui/lightEditor.py index f12753fc7c5..77eab5bab0f 100644 --- a/startup/gui/lightEditor.py +++ b/startup/gui/lightEditor.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -65,7 +64,7 @@ Gaffer.Metadata.registerValue( GafferSceneUI.LightEditor.Settings, "attribute", "userDefault", "cycles:light" ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : # This import appears unused, but it is intentional; it prevents us from # adding the OSL lights when 3Delight isn't available. @@ -91,7 +90,7 @@ # If 3Delight is available, then assume it will be used in preference to Cycles. Gaffer.Metadata.registerValue( GafferSceneUI.LightEditor.Settings, "attribute", "userDefault", "osl:light" ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold # Register Light Editor sections for Arnold before the generic "Visualisation" section diff --git a/startup/gui/menus.py b/startup/gui/menus.py index e4cab947a41..d5dfeb2ea8b 100644 --- a/startup/gui/menus.py +++ b/startup/gui/menus.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import os import re import traceback @@ -568,7 +567,7 @@ def __usdLightCreator( lightType ) : GafferUI.DotUI.connect( application.root() ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : # Raises if Tractor not available, thus avoiding registering the # TractorDispatcher. diff --git a/startup/gui/ocio.py b/startup/gui/ocio.py index c2278bce809..37232b9d52b 100644 --- a/startup/gui/ocio.py +++ b/startup/gui/ocio.py @@ -35,8 +35,6 @@ # ########################################################################## -import contextlib - import IECore import Gaffer @@ -72,7 +70,7 @@ def __scriptAdded( container, script ) : # Set up Arnold colour manager with metadata that integrates with our OCIO configs. -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold diff --git a/startup/gui/outputs.py b/startup/gui/outputs.py index 0d2333b86c8..2efa44f38f6 100644 --- a/startup/gui/outputs.py +++ b/startup/gui/outputs.py @@ -35,7 +35,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -79,7 +78,7 @@ # Add standard AOVs as they are defined in the aiStandard and alSurface shaders -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : # If Arnold isn't available for any reason, this will fail # and we won't add any unnecessary output definitions. @@ -164,7 +163,7 @@ # Add standard AOVs as they are defined in the 3Delight shaders -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : # If 3Delight isn't available for any reason, this will fail # and we won't add any unnecessary output definitions. @@ -242,7 +241,7 @@ if os.environ.get( "CYCLES_ROOT" ) and os.environ.get( "GAFFERCYCLES_HIDE_UI", "" ) != "1" : - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : # If cycles isn't available for any reason, this will fail # and we won't add any unnecessary output definitions. diff --git a/startup/gui/project.py b/startup/gui/project.py index 501490f8d0b..7d78ed61be2 100644 --- a/startup/gui/project.py +++ b/startup/gui/project.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import functools import os import sys @@ -109,7 +108,7 @@ def __projectBookmark( widget, location ) : ########################################################################## dispatchers = [ GafferDispatch.LocalDispatcher ] -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import tractor.api.author # Raises if Tractor not available import GafferTractor dispatchers.append( GafferTractor.TractorDispatcher ) @@ -124,7 +123,7 @@ def __projectBookmark( widget, location ) : # Renderers ########################################################################## -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold Gaffer.Metadata.registerValue( GafferArnold.ArnoldRender, "fileName", "userDefault", "${project:rootDirectory}/asses/${script:name}/${renderPass}/${script:name}.####.ass" ) Gaffer.Metadata.registerValue( GafferArnold.ArnoldTextureBake, "bakeDirectory", "userDefault", "${project:rootDirectory}/bakedTextures/${script:name}/" ) diff --git a/startup/gui/shaderPresets.py b/startup/gui/shaderPresets.py index fa84246e767..df0e3c674a7 100644 --- a/startup/gui/shaderPresets.py +++ b/startup/gui/shaderPresets.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -47,7 +46,7 @@ def __registerShaderPresets( presets ) : Gaffer.Metadata.registerValue( GafferScene.ShaderTweaks, "shader", "preset:" + name, value ) Gaffer.Metadata.registerValue( GafferScene.ShaderQuery, "shader", "preset:" + name, value ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold @@ -65,7 +64,7 @@ def __registerShaderPresets( presets ) : if os.environ.get( "CYCLES_ROOT" ) and os.environ.get( "GAFFERCYCLES_HIDE_UI", "" ) != "1" : - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : import GafferCycles @@ -74,7 +73,7 @@ def __registerShaderPresets( presets ) : ( "Cycles Light", "cycles:light" ), ] ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferOSL diff --git a/startup/gui/shaderView.py b/startup/gui/shaderView.py index 1d0074e4427..9fb370077d8 100644 --- a/startup/gui/shaderView.py +++ b/startup/gui/shaderView.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import os import IECore @@ -43,7 +42,7 @@ if os.environ.get( "CYCLES_ROOT" ) : - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : import GafferCycles @@ -68,7 +67,7 @@ def __cyclesShaderBall() : GafferSceneUI.ShaderView.registerRenderer( "osl", GafferCycles.InteractiveCyclesRender ) GafferSceneUI.ShaderView.registerScene( "osl", "Default", __cyclesShaderBall ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold GafferSceneUI.ShaderView.registerRenderer( "ai", GafferArnold.InteractiveArnoldRender ) diff --git a/startup/gui/viewer.py b/startup/gui/viewer.py index 9a441066d33..7639548175d 100644 --- a/startup/gui/viewer.py +++ b/startup/gui/viewer.py @@ -34,7 +34,6 @@ # ########################################################################## -import contextlib import functools import imath import inspect @@ -155,7 +154,7 @@ def __loadRendererSettings( fileName ) : return script["Processor"] -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferArnold @@ -180,7 +179,7 @@ def __loadRendererSettings( fileName ) : functools.partial( __loadRendererSettings, os.path.join( os.path.dirname( __file__ ), "arnoldViewerSettings.gfr" ) ) ) -with contextlib.suppress( ImportError ) : +with IECore.IgnoredExceptions( ImportError ) : import GafferDelight @@ -199,7 +198,7 @@ def __loadRendererSettings( fileName ) : if os.environ.get( "CYCLES_ROOT" ) and os.environ.get( "GAFFERCYCLES_HIDE_UI", "" ) != "1" : - with contextlib.suppress( ImportError ) : + with IECore.IgnoredExceptions( ImportError ) : import GafferCycles