From 8f319a58fe42ef2b866d97c6742c17d31586b277 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <fwinkl@cern>
Date: Tue, 3 Nov 2020 11:57:41 +0100
Subject: [PATCH] AthenaConfiguration: remove usage of `six`

Remove usage of `six` and tidy dictionary loops and comprehensions.
---
 Control/AthenaConfiguration/CMakeLists.txt    |  7 +---
 .../python/ComponentAccumulator.py            | 40 +++++++------------
 .../python/PropSetterProxy.py                 |  9 ++---
 3 files changed, 20 insertions(+), 36 deletions(-)

diff --git a/Control/AthenaConfiguration/CMakeLists.txt b/Control/AthenaConfiguration/CMakeLists.txt
index d18df53c31d..fd94dd784b9 100644
--- a/Control/AthenaConfiguration/CMakeLists.txt
+++ b/Control/AthenaConfiguration/CMakeLists.txt
@@ -1,13 +1,8 @@
-################################################################################
-# Package: AthenaConfiguration
-################################################################################
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 # Declare the package name:
 atlas_subdir( AthenaConfiguration )
 
-# External dependencies:
-find_package( six )
-
 # Install files from the package:
 atlas_install_python_modules( python/*.py python/iconfTool 
                               POST_BUILD_CMD ${ATLAS_FLAKE8} )
diff --git a/Control/AthenaConfiguration/python/ComponentAccumulator.py b/Control/AthenaConfiguration/python/ComponentAccumulator.py
index 3dc09335320..6fb22b21d35 100644
--- a/Control/AthenaConfiguration/python/ComponentAccumulator.py
+++ b/Control/AthenaConfiguration/python/ComponentAccumulator.py
@@ -1,11 +1,9 @@
 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
-from __future__ import print_function
 from AthenaCommon.Logging import logging
 from AthenaCommon.CFElements import isSequence,findSubSequence,findAlgorithm,flatSequencers,findOwningSequence,\
     checkSequenceConsistency, findAllAlgorithmsByName
 from AthenaConfiguration.ComponentFactory import CompFactory
-#from AthenaConfiguration.AlgSequence import AthSequencer
 from AthenaCommon.Debugging import DbgStage
 from AthenaCommon.Constants import INFO
 
@@ -14,7 +12,6 @@ import GaudiConfig2
 from AthenaConfiguration.Deduplication import deduplicate, DeduplicationFailed
 
 import collections
-import six
 import copy
 import sys
 
@@ -216,8 +213,8 @@ class ComponentAccumulator(object):
                 if summariseProps:
                     printProperties(self._msg, self._privateTools, printDefaults)
         self._msg.info( "]" )
-        self._msg.info( "TheApp properties" )
-        for k,v in six.iteritems(self._theAppProps):
+        self._msg.info( "theApp properties" )
+        for k, v in self._theAppProps.items():
             self._msg.info("  {} : {}".format(k,v))
 
 
@@ -239,7 +236,7 @@ class ComponentAccumulator(object):
 
         parent.Members.append(newseq)
         algsByName = findAllAlgorithmsByName(newseq)
-        for name, existingAlgs in six.iteritems(algsByName):
+        for name, existingAlgs in algsByName.items():
             startingIndex = 0
             if name not in self._algorithms:
                 firstAlg, parent, idx = existingAlgs[0]
@@ -513,7 +510,7 @@ class ComponentAccumulator(object):
                     else:
                         self._msg.debug("  Merging sequence %s to a sequence %s", c.name, dest.name )
                         algorithmsByName = findAllAlgorithmsByName(c)
-                        for name, existingAlgs in six.iteritems(algorithmsByName):
+                        for name, existingAlgs in algorithmsByName.items():
                             startingIndex = 0
                             if name not in self._algorithms:
                                 firstAlg, parent, idx = existingAlgs[0]
@@ -566,7 +563,7 @@ class ComponentAccumulator(object):
 
             
         # Additional checking and updating other accumulator's algorithms list
-        for name, alg in six.iteritems(other._algorithms):
+        for name in other._algorithms:
             if name not in self._algorithms:
                 raise ConfigurationError('Error in merging. Algorithm {} missing in destination accumulator'.format(name))
             other._algorithms[name] = self._algorithms[name]
@@ -582,7 +579,7 @@ class ComponentAccumulator(object):
             self.addPublicTool(pt) #Profit from deduplicaton here
 
         #Merge AppMgr properties:
-        for (k,v) in six.iteritems(other._theAppProps):
+        for (k,v) in other._theAppProps.items():
             self.setAppProperty(k,v)  #Will warn about overrides
             pass
         other._wasMerged=True
@@ -657,12 +654,9 @@ class ComponentAccumulator(object):
             self.__cpp_type__, self.name
         )
 
-        appPropsToSet = {}
+        appPropsToSet = {k: str(v) for k, v in self._theAppProps.items()}
         mspPropsToSet = {}
         bshPropsToSet = []
-        for (k, v) in six.iteritems(self._theAppProps):
-            appPropsToSet[k] = str(v)
-
         svcToCreate = []
         extSvc = []
         for svc in self._services:
@@ -715,8 +709,7 @@ class ComponentAccumulator(object):
             ):  # MessageSvc will exist already! Needs special treatment
                 getCompsToBeAdded(svc)
             else:
-                for k, v in svc._properties.items():
-                    mspPropsToSet[k] = str(v)
+                mspPropsToSet.update((k,str(v)) for k,v in svc._properties.items())
         try:
             from AthenaPython import PyAthenaComps
 
@@ -724,9 +717,7 @@ class ComponentAccumulator(object):
         except ImportError:
             PyAlg = type(None)
 
-        for seqName, algoList in six.iteritems(
-            flatSequencers(self._sequence, algsCollection=self._algorithms)
-        ):
+        for seqName, algoList in flatSequencers(self._sequence, algsCollection=self._algorithms).items():
             seq = self.getSequence(seqName)
             for k, v in seq._properties.items():
                 if k != "Members":  # This property his handled separatly
@@ -839,7 +830,7 @@ def __indent( indent = ""):
 
 def __setProperties( destConfigurableInstance, sourceConf2Instance, indent="" ):
     _log = logging.getLogger( "__setProperties".ljust(30) )
-    for pname, pvalue in six.iteritems( sourceConf2Instance._properties ):
+    for pname, pvalue in sourceConf2Instance._properties.items():
         if destConfigurableInstance.__class__.__name__ == 'AlgSequence' and pname == 'Members':
             continue
         propType = sourceConf2Instance._descriptors[pname].cpp_type
@@ -906,7 +897,7 @@ def conf2toConfigurable( comp, indent="", suppressDupes=False ):
         return conf2Object
 
     def __getProperties( sourceConfigurableInstance, destConf2Instance, indent="" ):
-        for prop, value in six.iteritems( sourceConfigurableInstance.getProperties() ):
+        for prop, value in sourceConfigurableInstance.getProperties().items():
             _log.debug( "{}Dealing with class {} property {} value type {}".format( indent, sourceConfigurableInstance.getFullJobOptName(), prop,  str( type( value ) ) ) )
             if "ServiceHandle" in str( type( value ) ):
                 instance = __alreadyConfigured(value)
@@ -943,11 +934,10 @@ def conf2toConfigurable( comp, indent="", suppressDupes=False ):
 
     def __areSettingsSame( existingConfigurableInstance, newConf2Instance, indent="" ):
         _log.debug( "{}Checking if setting is the same {} {}".format( indent, existingConfigurableInstance.getFullName(), newConf2Instance.getFullJobOptName() ) )
-        alreadySetProperties = dict([ (pname, pvalue) for pname,pvalue
-                                      in six.iteritems(existingConfigurableInstance.getValuedProperties()) ])
+        alreadySetProperties = existingConfigurableInstance.getValuedProperties().copy()
         _log.debug("Existing properties: {}".format(alreadySetProperties))
         _log.debug("New properties: {}".format(newConf2Instance._properties))
-        for pname, pvalue in six.iteritems( newConf2Instance._properties ): # six.iteritems(comp._properties):
+        for pname, pvalue in newConf2Instance._properties.items():
             if __isOldConfigurable( pvalue ):
                 _log.warning( "{}New configuration object {} property {} has legacy configuration components assigned to it {}"
                               .format(indent, compName(newConf2Instance), pname, compName(pvalue) ) )
@@ -971,7 +961,7 @@ def conf2toConfigurable( comp, indent="", suppressDupes=False ):
                 _log.debug('Public tool handle array properties? {} {}'.format(toolSet, pvalue))
                 # strings?
                 for newC in pvalue:
-                    if isinstance(newC, six.string_types):
+                    if isinstance(newC, str):
                         pubtoolclass, pubtoolname = newC.split('/')
                         if pubtoolname not in toolSet:
                             klass = __findConfigurableClass( pubtoolclass )
@@ -1067,7 +1057,7 @@ def appendCAtoAthena(ca):
 
     if len( ca.getAppProps() ) != 0:
         _log.info( "Merging ApplicationMgr properties" )
-        for (propName, propValue) in six.iteritems(ca.getAppProps()):
+        for propName, propValue in ca.getAppProps().items():
             # Same logic as in ComponentAccumulator.setAppProperty()
             if not hasattr(theApp, propName):
                 setattr(theApp, propName, propValue)
diff --git a/Control/AthenaConfiguration/python/PropSetterProxy.py b/Control/AthenaConfiguration/python/PropSetterProxy.py
index a4b34ee104c..34defa948cc 100644
--- a/Control/AthenaConfiguration/python/PropSetterProxy.py
+++ b/Control/AthenaConfiguration/python/PropSetterProxy.py
@@ -1,10 +1,9 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
-from __future__ import print_function
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+
 from AthenaCommon.Logging import logging
 from AthenaCommon.CFElements import isSequence
 from AthenaCommon.Configurable import ConfigurableAlgTool
 from GaudiKernel.GaudiHandles import PrivateToolHandle, PrivateToolHandleArray
-import six
 
 msg = logging.getLogger('PropSetterProxy')
 
@@ -26,7 +25,7 @@ class PropSetterProxy(object):
 
        
       import fnmatch
-      for component_path, component in six.iteritems(PropSetterProxy.__compPaths):
+      for component_path, component in PropSetterProxy.__compPaths.items():
          if fnmatch.fnmatch( component_path, self.__path ):
             if name in component._descriptors:
                try:
@@ -60,7 +59,7 @@ class PropSetterProxy(object):
            def __nestAlg(startpath, comp): # it actually dives inside the algorithms and (sub) tools               
                if comp.getName() == "":
                    return
-               for name, value in six.iteritems(comp._descriptors):
+               for name, value in comp._descriptors.items():
                    if isinstance( value.cpp_type, ConfigurableAlgTool ) or isinstance( value.cpp_type, PrivateToolHandle ):
                        __add( startpath+"/"+name+"/"+value.getFullJobOptName(), value )
                        __nestAlg( startpath+"/"+name+"/"+value.getName(), value )
-- 
GitLab