From 450e5381677aac9e9a024eca5bf2027effe54bb4 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <frank.winklmeier@cern.ch> Date: Wed, 23 Jan 2019 22:05:51 +0100 Subject: [PATCH] Fix python code style warnings After upgrade to flake8 3.6.0, fix the following additional python code style issues: - bare exception - use double-backslash for printing a backslash --- Control/AthenaCommon/CMakeLists.txt | 2 +- Control/AthenaCommon/python/CfgMergerLib.py | 4 ++-- Control/AthenaCommon/python/ConfigurationShelve.py | 4 ++-- Control/AthenaCommon/python/DumpProperties.py | 4 ++-- Control/AthenaCommon/python/Include.py | 6 +++--- Control/AthenaCommon/python/JobProperties.py | 6 +++--- Control/AthenaConfiguration/python/ComponentAccumulator.py | 6 +++--- Control/AthenaConfiguration/python/UnifyProperties.py | 2 +- HLT/Trigger/TrigControl/TrigCommon/bin/athenaHLT.py | 2 +- .../TriggerJobOpts/python/TriggerConfigGetter.py | 6 +++--- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Control/AthenaCommon/CMakeLists.txt b/Control/AthenaCommon/CMakeLists.txt index 68b6abb7516..a29b6dca8c2 100644 --- a/Control/AthenaCommon/CMakeLists.txt +++ b/Control/AthenaCommon/CMakeLists.txt @@ -33,5 +33,5 @@ atlas_add_test( CFElementsTest SCRIPT python -m unittest -v AthenaCommon.CFEleme # Check python syntax: atlas_add_test( flake8 - SCRIPT flake8 --select=F,E101,E112,E113,E7,E9,W6 --ignore=E701 ${CMAKE_CURRENT_SOURCE_DIR}/python + SCRIPT flake8 --select=F,E101,E112,E113,E7,E9,W6 --ignore=E701,E741 ${CMAKE_CURRENT_SOURCE_DIR}/python POST_EXEC_SCRIPT nopost.sh ) diff --git a/Control/AthenaCommon/python/CfgMergerLib.py b/Control/AthenaCommon/python/CfgMergerLib.py index f0d05cf7e63..4eb2394b499 100644 --- a/Control/AthenaCommon/python/CfgMergerLib.py +++ b/Control/AthenaCommon/python/CfgMergerLib.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # @file AthenaCommon/python/CfgMergerLib # @purpose a set of python tools to analyze configurables and find candidates @@ -188,7 +188,7 @@ def dump_josvc_content(fname='josvc.ascii'): cfg = dict(cfg) print >> f, "# content of the joboptions-svc" - print >> f, "josvc_catalog = \ " + print >> f, "josvc_catalog = \\ " from pprint import pprint pprint(cfg, stream=f) diff --git a/Control/AthenaCommon/python/ConfigurationShelve.py b/Control/AthenaCommon/python/ConfigurationShelve.py index e3add9820ca..4038da3a33a 100644 --- a/Control/AthenaCommon/python/ConfigurationShelve.py +++ b/Control/AthenaCommon/python/ConfigurationShelve.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # @file: AthenaCommon/python/ConfigurationShelve.py # @author: Wim Lavrijsen (WLavrijsen@lbl.gov) @@ -311,7 +311,7 @@ def loadJobOptionsCatalogue( cfg_fname ): p = gaudi.StringProperty( n, '' ) try: p.fromString(v).ignore() - except: + except Exception: print "Failed to convert",n,v if not josvc.addPropertyToCatalogue( client, p ).isSuccess(): diff --git a/Control/AthenaCommon/python/DumpProperties.py b/Control/AthenaCommon/python/DumpProperties.py index d914322c3f9..21f5805c2fa 100755 --- a/Control/AthenaCommon/python/DumpProperties.py +++ b/Control/AthenaCommon/python/DumpProperties.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # File: AthenaCommon/python/DumpProperties.py # Author: Wim Lavrijsen (WLavrijsen@lbl.gov) @@ -76,7 +76,7 @@ def pprint( obj, stream = sys.stdout ): if not obj._ip: try: value = eval( value ) - except: + except Exception: pass if value and type(value) == list: diff --git a/Control/AthenaCommon/python/Include.py b/Control/AthenaCommon/python/Include.py index 6081b56bf06..e7816b84f53 100755 --- a/Control/AthenaCommon/python/Include.py +++ b/Control/AthenaCommon/python/Include.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # File: AthenaCommon/python/Include.py # Author: Wim Lavrijsen (WLavrijsen@lbl.gov) @@ -57,7 +57,7 @@ class IncludeError( RuntimeError ): ### files locator ------------------------------------------------------------ try: optionsPathEnv = os.environ[ 'JOBOPTSEARCHPATH' ] -except: +except Exception: optionsPathEnv = os.curdir optionsPath = re.split( ',|' + os.pathsep, optionsPathEnv ) @@ -232,7 +232,7 @@ class Include( object ): try: if 'import' in _filecache[ f.f_code.co_filename ][ f.f_lineno ]: return self._trace_include - except: + except Exception: pass f = f.f_back del f diff --git a/Control/AthenaCommon/python/JobProperties.py b/Control/AthenaCommon/python/JobProperties.py index 2b19ec588ba..4afe912fc3e 100755 --- a/Control/AthenaCommon/python/JobProperties.py +++ b/Control/AthenaCommon/python/JobProperties.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration #======================================================================= # File: JobProperties/python/JobProperties.py @@ -483,13 +483,13 @@ class JobPropertyContainer (object): closestMatch=get_close_matches(name,self.__dict__.keys(),1) if len(closestMatch)>0: errString+=". Did you mean \'%s\'?" % closestMatch[0] - except: + except Exception: pass #No execption from here raise AttributeError(errString) try: protected=hasattr(self.__dict__[name],'_context_name') - except: + except Exception: protected=False if not protected: self.__dict__[name] = n_value diff --git a/Control/AthenaConfiguration/python/ComponentAccumulator.py b/Control/AthenaConfiguration/python/ComponentAccumulator.py index 15e71f94d96..a85a9ffc3d2 100644 --- a/Control/AthenaConfiguration/python/ComponentAccumulator.py +++ b/Control/AthenaConfiguration/python/ComponentAccumulator.py @@ -90,13 +90,13 @@ class ComponentAccumulator(object): return seq.getValuedProperties()[name] return seq.getDefaultProperties()[name] - self._msg.info( " "*nestLevel +"\__ "+ seq.name() +" (seq: %s %s)" %( "SEQ" if __prop("Sequential") else "PAR", "OR" if __prop("ModeOR") else "AND" ) ) + self._msg.info( " "*nestLevel +"\\__ "+ seq.name() +" (seq: %s %s)" %( "SEQ" if __prop("Sequential") else "PAR", "OR" if __prop("ModeOR") else "AND" ) ) nestLevel += 3 for c in seq.getChildren(): if isSequence(c): printSeqAndAlgs(c, nestLevel ) else: - self._msg.info( " "*nestLevel +"\__ "+ c.name() +" (alg)" ) + self._msg.info( " "*nestLevel +"\\__ "+ c.name() +" (alg)" ) if summariseProps: printProperties(c, nestLevel) printSeqAndAlgs(self._sequence) @@ -251,7 +251,7 @@ class ComponentAccumulator(object): #The following is to work with internal list of service as well as gobal svcMgr as second parameter try: compList.append(newComp) - except: + except Exception: compList+=newComp pass return True #True means something got added diff --git a/Control/AthenaConfiguration/python/UnifyProperties.py b/Control/AthenaConfiguration/python/UnifyProperties.py index dbbb6d968d1..2781f6d40a1 100644 --- a/Control/AthenaConfiguration/python/UnifyProperties.py +++ b/Control/AthenaConfiguration/python/UnifyProperties.py @@ -63,7 +63,7 @@ def getUnificationKey(propname): if matchingByObject in _propsToUnify: return matchingByObject - except: + except Exception: pass return None diff --git a/HLT/Trigger/TrigControl/TrigCommon/bin/athenaHLT.py b/HLT/Trigger/TrigControl/TrigCommon/bin/athenaHLT.py index 1a8e7bb8592..e2618adc6dd 100755 --- a/HLT/Trigger/TrigControl/TrigCommon/bin/athenaHLT.py +++ b/HLT/Trigger/TrigControl/TrigCommon/bin/athenaHLT.py @@ -76,7 +76,7 @@ def arg_ros2rob(s): if type(ros2robdict) is not dict: raise(ValueError) return ros2robdict - except: + except Exception: sys.stderr.write("ERROR! ros2rob cannot be evaluated as it is not a proper python dictionary: {}\n".format(s)) sys.stderr.write("Using empty ros2rob dictionary instead\n") return {} diff --git a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigGetter.py b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigGetter.py index 6558072e19c..7c817028a5a 100644 --- a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigGetter.py +++ b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigGetter.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration __author__ = 'J. Stelzer' @@ -248,7 +248,7 @@ class TriggerConfigGetter(Configured): ### preparations are done! try: self.svc.SetStates( self.ConfigSrcList ) - except: + except Exception as ex: log.error( 'Failed to set state of TrigConfigSvc to %r' % self.ConfigSrcList ) else: log.info('The following configuration services will be tried: %r' % self.ConfigSrcList ) @@ -256,7 +256,7 @@ class TriggerConfigGetter(Configured): try: self.svc.InitialiseSvc() - except Exception, ex: + except Exception as ex: log.error( 'Failed to activate TrigConfigSvc: %r' % ex ) if self.readTriggerDB: -- GitLab