Skip to content

Commit

Permalink
Merge pull request #5573 from johnhaddon/revertSuppress
Browse files Browse the repository at this point in the history
Revert "Prefer `contextlib.suppress()` to `IECore.IgnoredExceptions`"
  • Loading branch information
ericmehl authored Dec 5, 2023
2 parents 7a12686 + 2c83f48 commit 77b4094
Show file tree
Hide file tree
Showing 53 changed files with 93 additions and 162 deletions.
4 changes: 1 addition & 3 deletions python/Gaffer/DictPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#
##########################################################################

import contextlib

import IECore

import Gaffer
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions python/Gaffer/PythonExpressionEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import re
import ast
import contextlib
import functools
import inspect
import pathlib
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions python/Gaffer/SequencePath.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
##########################################################################

import collections
import contextlib

import IECore

Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 1 addition & 3 deletions python/GafferCortex/IndexedIOPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#
##########################################################################

import contextlib

import IECore

import Gaffer
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions python/GafferCortex/ObjectReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import contextlib

import IECore

import Gaffer
Expand Down Expand Up @@ -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() )
Expand Down
3 changes: 1 addition & 2 deletions python/GafferCortex/ObjectWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#
##########################################################################

import contextlib
import os

import IECore
Expand Down Expand Up @@ -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 :
Expand Down
9 changes: 4 additions & 5 deletions python/GafferCortex/OpMatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#
##########################################################################

import contextlib
import threading
import traceback
import weakref
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down
4 changes: 1 addition & 3 deletions python/GafferCortex/ParameterPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#
##########################################################################

import contextlib

import IECore

import Gaffer
Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions python/GafferCortexUI/ClassParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import contextlib

import imath

import IECore
Expand Down Expand Up @@ -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( "*" ) )

Expand Down
8 changes: 3 additions & 5 deletions python/GafferCortexUI/ClassVectorParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import contextlib

import imath

import IECore
Expand Down Expand Up @@ -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( "*" ) )

Expand Down Expand Up @@ -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 )

Expand Down
8 changes: 3 additions & 5 deletions python/GafferCortexUI/CompoundParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import contextlib

import IECore

import GafferUI
Expand All @@ -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 :
Expand Down Expand Up @@ -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

Expand Down
16 changes: 7 additions & 9 deletions python/GafferCortexUI/CompoundVectorParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import contextlib

import imath

import IECore
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 )

Expand All @@ -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 :
Expand Down Expand Up @@ -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 :
Expand Down
6 changes: 2 additions & 4 deletions python/GafferCortexUI/FileSequenceParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#
##########################################################################

import contextlib

import IECore

import Gaffer
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions python/GafferCortexUI/OpDialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#
##########################################################################

import contextlib
import enum
import sys
import threading
Expand Down Expand Up @@ -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() :
Expand All @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() :
Expand Down Expand Up @@ -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() :
Expand Down
3 changes: 1 addition & 2 deletions python/GafferCortexUI/ParameterPresets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#
##########################################################################

import contextlib
import os
import re
import shutil
Expand Down Expand Up @@ -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() :
Expand Down
Loading

0 comments on commit 77b4094

Please sign in to comment.