Skip to content
Snippets Groups Projects
Commit b0f15ff3 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

AthenaConfiguration: Fix code problems discovered by flake8

Fix style and syntax errors discovered by the flake8 unit test.


Former-commit-id: 2bd5db6c
parent 0c76f069
No related branches found
No related tags found
8 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3,!28528Revert 63f845ae,!27054Atr20369 210,!26342Monopole: Handle fractionally charged particles
...@@ -46,8 +46,8 @@ class AthConfigFlags(object): ...@@ -46,8 +46,8 @@ class AthConfigFlags(object):
if (self._locked): if (self._locked):
raise RuntimeError("Attempt to add a flag to an already-locked container") raise RuntimeError("Attempt to add a flag to an already-locked container")
if self._flagdict.has_key(name): if name in self._flagdict:
raise KeyError("Duplicated flag name: %s" % name); raise KeyError("Duplicated flag name: %s" % name)
self._flagdict[name]=CfgFlag(setDef) self._flagdict[name]=CfgFlag(setDef)
return return
...@@ -106,7 +106,7 @@ class AthConfigFlags(object): ...@@ -106,7 +106,7 @@ class AthConfigFlags(object):
#Sanity check: Don't replace a by a #Sanity check: Don't replace a by a
if (subsetToReplace == replacementSubset): if (subsetToReplace == replacementSubset):
raise RunTimeError("Called cloneAndReplace with identical strings") raise RuntimeError("Called cloneAndReplace with identical strings")
replacedNames=set() replacedNames=set()
replacementNames=set() replacementNames=set()
...@@ -145,8 +145,8 @@ class AthConfigFlags(object): ...@@ -145,8 +145,8 @@ class AthConfigFlags(object):
if (self._locked): if (self._locked):
raise RuntimeError("Attempt to join with and already-locked container") raise RuntimeError("Attempt to join with and already-locked container")
for (name,flag) in other._flagdict: for (name,flag) in other._flagdict:
if self._flagdict.has_key(name): if name in self._flagdict:
raise KeyError("Duplicated flag name: %s" % name); raise KeyError("Duplicated flag name: %s" % name)
self._flagdict[name]=flag self._flagdict[name]=flag
return return
......
# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
from AthenaCommon.Logging import log from AthenaCommon.Logging import log
from FilePeeker.FilePeeker import PeekFiles from FilePeeker.FilePeeker import PeekFiles
...@@ -7,7 +9,7 @@ _fileMetaData=dict() ...@@ -7,7 +9,7 @@ _fileMetaData=dict()
def GetFileMD(filenames): def GetFileMD(filenames):
filename=filenames[0] filename=filenames[0]
if not filename in _fileMetaData: if filename not in _fileMetaData:
if len(filenames)>1: if len(filenames)>1:
log.info("Multiple input files. Use the first one for auto-configuration") log.info("Multiple input files. Use the first one for auto-configuration")
log.info("Obtaining metadata of auto-configuration by peeking into %s" % filename) log.info("Obtaining metadata of auto-configuration by peeking into %s" % filename)
......
...@@ -9,8 +9,7 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags ...@@ -9,8 +9,7 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags
import GaudiKernel.GaudiHandles as GaudiHandles import GaudiKernel.GaudiHandles as GaudiHandles
import ast import ast
class DeduplicationFailed(RuntimeError):
class DeduplicatonFailed(RuntimeError):
pass pass
class ConfigurationError(RuntimeError): class ConfigurationError(RuntimeError):
...@@ -60,7 +59,7 @@ class ComponentAccumulator(object): ...@@ -60,7 +59,7 @@ class ComponentAccumulator(object):
else: else:
def printSeqAndAlgs(seq, nestLevel = 0): def printSeqAndAlgs(seq, nestLevel = 0):
def __prop(name): def __prop(name):
if seq.getValuedProperties().has_key(name): if name in seq.getValuedProperties():
return seq.getValuedProperties()[name] return seq.getValuedProperties()[name]
return seq.getDefaultProperties()[name] return seq.getDefaultProperties()[name]
...@@ -88,7 +87,7 @@ class ComponentAccumulator(object): ...@@ -88,7 +87,7 @@ class ComponentAccumulator(object):
seq = CurrentSequence.get() seq = CurrentSequence.get()
if sequence: if sequence:
seq = findSubSequence(seq, sequence ) seq = findSubSequence(seq, sequence )
if seq == None: if seq is None:
raise ConfigurationError("Missing sequence %s to add new sequence to" % sequence ) raise ConfigurationError("Missing sequence %s to add new sequence to" % sequence )
if findSubSequence( self._sequence, newseq.name() ): if findSubSequence( self._sequence, newseq.name() ):
...@@ -101,9 +100,9 @@ class ComponentAccumulator(object): ...@@ -101,9 +100,9 @@ class ComponentAccumulator(object):
raise TypeError("Attempt to add wrong type: %s as event algorithm" % type( algo ).__name__) raise TypeError("Attempt to add wrong type: %s as event algorithm" % type( algo ).__name__)
pass pass
seq = CurrentSequence.get() seq = CurrentSequence.get()
if sequence != None: if sequence is not None:
seq = findSubSequence( seq, sequence ) seq = findSubSequence( seq, sequence )
if seq == None: if seq is None:
raise ConfigurationError("Unable to add %s to sequence %s as it is missing", algo.getFullName(), seq.name() ) raise ConfigurationError("Unable to add %s to sequence %s as it is missing", algo.getFullName(), seq.name() )
self._msg.debug("Adding %s to sequence %s", algo.getFullName(), seq.name() ) self._msg.debug("Adding %s to sequence %s", algo.getFullName(), seq.name() )
...@@ -118,7 +117,7 @@ class ComponentAccumulator(object): ...@@ -118,7 +117,7 @@ class ComponentAccumulator(object):
Limiting to the current scope reduces risk of cross talk. Will see in real life and make adjustments. Limiting to the current scope reduces risk of cross talk. Will see in real life and make adjustments.
""" """
algo = findAlgorithm( CurrentSequence.get(), name ) algo = findAlgorithm( CurrentSequence.get(), name )
if algo == None: if algo is None:
raise ConfigurationError("Can not find an algorithm of name %s "% name) raise ConfigurationError("Can not find an algorithm of name %s "% name)
return algo return algo
...@@ -133,7 +132,7 @@ class ComponentAccumulator(object): ...@@ -133,7 +132,7 @@ class ComponentAccumulator(object):
def getCondAlgo(self,name): def getCondAlgo(self,name):
hits=[a for a in self._conditionsAlgs if a.getName()==name] hits=[a for a in self._conditionsAlgs if a.getName()==name]
if (len(hits)>1): if (len(hits)>1):
raise ConfigurationError("More than one Algorithm with name %s found in sequence %s" %(name,sequence)) raise ConfigurationError("More than one conditions algorithm with name %s found" % name)
return hits[0] return hits[0]
def addService(self,newSvc): def addService(self,newSvc):
...@@ -233,23 +232,17 @@ class ComponentAccumulator(object): ...@@ -233,23 +232,17 @@ class ComponentAccumulator(object):
def addConditionsInput(self,condObj): def addConditionsInput(self,condObj):
#That's a string, should do some sanity checks on formatting #That's a string, should do some sanity checks on formatting
self._conditionsInput.add(condObj); self._conditionsInput.add(condObj)
pass pass
def addEventInput(self,condObj): def addEventInput(self,condObj):
#That's a string, should do some sanity checks on formatting #That's a string, should do some sanity checks on formatting
self._eventInput.add(condObj); self._eventInput.add(condObj)
pass pass
def addOutputToStream(self,streamName,outputs): def addOutputToStream(self,streamName,outputs):
if hasattr(outputs,'__iter__'):
toAdd=list(outputs)
else:
toAdd=[outputs,]
if streamName in self._outputsPerStream: if streamName in self._outputsPerStream:
self._outputsPerStream[streamName].update(set(outputs)) self._outputsPerStream[streamName].update(set(outputs))
else: else:
...@@ -259,7 +252,7 @@ class ComponentAccumulator(object): ...@@ -259,7 +252,7 @@ class ComponentAccumulator(object):
def setAppProperty(self,key,value): def setAppProperty(self,key,value):
if self._theAppProps.has_key(key) and self._theAppProps[key]!=value: if key in self._theAppProps and self._theAppProps[key]!=value:
#Not sure if we should allow that ... #Not sure if we should allow that ...
self._msg.info("ApplicationMgr property '%s' already set to '%s'. Overwriting with %s", key, self._theAppProps[key], value) self._msg.info("ApplicationMgr property '%s' already set to '%s'. Overwriting with %s", key, self._theAppProps[key], value)
self._theAppProps[key]=value self._theAppProps[key]=value
...@@ -299,8 +292,7 @@ class ComponentAccumulator(object): ...@@ -299,8 +292,7 @@ class ComponentAccumulator(object):
#self._conditionsAlgs+=other._conditionsAlgs #self._conditionsAlgs+=other._conditionsAlgs
for condAlg in other._conditionsAlgs: for condAlg in other._conditionsAlgs:
self.addCondAlgo(condAlgo) #Profit from deduplicaton here self.addCondAlgo(condAlg) #Profit from deduplicaton here
for svc in other._services: for svc in other._services:
self.addService(svc) #Profit from deduplicaton here self.addService(svc) #Profit from deduplicaton here
...@@ -338,9 +330,9 @@ class ComponentAccumulator(object): ...@@ -338,9 +330,9 @@ class ComponentAccumulator(object):
currentSeq = seq = CurrentSequence.get() currentSeq = seq = CurrentSequence.get()
if kwargs.has_key('sequence'): if 'sequence' in kwargs:
seq = findSubSequence(seq, kwargs['sequence'] ) seq = findSubSequence(seq, kwargs['sequence'] )
if seq == None: if seq is None:
raise ConfigurationError("Can not add algorithms to sequence %s as it does not exist" % kwargs['sequence'] ) raise ConfigurationError("Can not add algorithms to sequence %s as it does not exist" % kwargs['sequence'] )
else: else:
del kwargs['sequence'] del kwargs['sequence']
...@@ -474,7 +466,7 @@ class ComponentAccumulator(object): ...@@ -474,7 +466,7 @@ class ComponentAccumulator(object):
if __name__ == "__main__": if __name__ == "__main__":
# trivial case without any nested sequences # trivial case without any nested sequences
from AthenaCommon.Configurable import ConfigurablePyAlgorithm # guinea pig algorithms from AthenaCommon.Configurable import ConfigurablePyAlgorithm # guinea pig algorithms
from AthenaCommon.CFElements import * from AthenaCommon.CFElements import seqAND, seqOR, parOR
from AthenaCommon.Logging import log from AthenaCommon.Logging import log
from AthenaCommon.Constants import DEBUG from AthenaCommon.Constants import DEBUG
...@@ -537,7 +529,7 @@ if __name__ == "__main__": ...@@ -537,7 +529,7 @@ if __name__ == "__main__":
acc.addConfig( AlgsConf4, dummyCfgFlags, sequence="sub2Sequence1" ) acc.addConfig( AlgsConf4, dummyCfgFlags, sequence="sub2Sequence1" )
assert findAlgorithm(AlgSequence("AthAlgSeq"), "NestedAlgo1" ), "Algorithm added to nested sequence" assert findAlgorithm(AlgSequence("AthAlgSeq"), "NestedAlgo1" ), "Algorithm added to nested sequence"
assert findAlgorithm(AlgSequence("AthAlgSeq"), "NestedAlgo1", 1 ) == None, "Algorithm mistakenly in top sequence" assert findAlgorithm(AlgSequence("AthAlgSeq"), "NestedAlgo1", 1 ) is None, "Algorithm mistakenly in top sequence"
assert findAlgorithm( findSubSequence(AlgSequence("AthAlgSeq"), "sub2Sequence1"), "NestedAlgo1", 1 ), "Algorithm not in right sequence" assert findAlgorithm( findSubSequence(AlgSequence("AthAlgSeq"), "sub2Sequence1"), "NestedAlgo1", 1 ), "Algorithm not in right sequence"
print( "Complex sequences construction also OK ") print( "Complex sequences construction also OK ")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment