From 0fd64c53252032033c39685c01c00ac5fa5fc4a6 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <fwinkl@cern>
Date: Tue, 3 Nov 2020 16:29:34 +0100
Subject: [PATCH] TriggerMenuMT: remove usage of `six` module

Py2 compatibility is no longer needed.
---
 Trigger/TriggerCommon/TriggerMenuMT/CMakeLists.txt     |  3 ---
 .../python/HLTMenuConfig/MET/ConfigHelpers.py          |  4 ++--
 .../python/HLTMenuConfig/Menu/GenerateMenuMT.py        |  4 +---
 .../python/HLTMenuConfig/Menu/LS2_v1_newJO.py          |  4 +---
 .../python/HLTMenuConfig/Menu/SignatureDicts.py        |  3 +--
 .../python/HLTMenuConfig/Menu/TriggerConfigHLT.py      |  7 +++----
 .../python/HLTMenuConfig/Test/ViewCFTest.py            |  3 ---
 .../TriggerMenuMT/python/L1/Base/L1MenuFlags.py        |  7 +++----
 .../TriggerMenuMT/python/L1/Base/Limits.py             |  6 ++----
 .../python/L1/Config/TypeWideThresholdConfig.py        |  5 ++---
 .../TriggerMenuMT/python/LVL1MenuConfig/LVL1/Limits.py |  6 ++----
 .../python/LVL1MenuConfig/LVL1/Lvl1Thresholds.py       | 10 +++-------
 12 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/Trigger/TriggerCommon/TriggerMenuMT/CMakeLists.txt b/Trigger/TriggerCommon/TriggerMenuMT/CMakeLists.txt
index 978d8f60314..8a58635cbda 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/CMakeLists.txt
+++ b/Trigger/TriggerCommon/TriggerMenuMT/CMakeLists.txt
@@ -3,9 +3,6 @@
 # Declare the package name:
 atlas_subdir( TriggerMenuMT )
 
-# External dependencies:
-find_package( six )
-
 atlas_add_test( flake8
    SCRIPT flake8 --select=ATL,F,E7,E9,W6,E101 --enable-extension=ATL900,ATL901,ATL902
    ${CMAKE_CURRENT_SOURCE_DIR}/python ${CMAKE_CURRENT_SOURCE_DIR}/scripts
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
index 683dbad2d43..a502306913d 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 """ Helper functions for configuring MET chains
 """
@@ -124,7 +124,7 @@ class AlgConfig(ABC):
 
         inputMakers = self.inputMakers()
         # Retrieve the inputss
-        log.verbose(f"Create inputs for {self._suffix}")
+        log.verbose("Create inputs for %s", self._suffix)
         steps, inputs = self.inputRegistry.build_steps(
             self._inputs, metFSRoIs, self.recoDict
         )
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
index e67017394db..4e30ed524ad 100755
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
@@ -1,7 +1,6 @@
 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 from PyUtils.Decorators import memoize
-from six import add_metaclass
 
 # Configure the scheduler
 from AthenaCommon.AlgScheduler import AlgScheduler
@@ -33,8 +32,7 @@ class Singleton(type):
 
 
 # for now we make this a singleton because calling menu generation twice leads to problems
-@add_metaclass(Singleton)
-class GenerateMenuMT(object):
+class GenerateMenuMT(object, metaclass=Singleton):
 
     @staticmethod
     def overwriteSignaturesWith(f):
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1_newJO.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1_newJO.py
index 1e95b4e6f70..0e814f98b5b 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1_newJO.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1_newJO.py
@@ -1,8 +1,6 @@
 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 from TriggerMenuMT.HLTMenuConfig.Menu.ChainDefInMenu import ChainProp
 
-import six
-
 # def get_flag_item(chainName, L1itemsChainParts, groups):
 #     PhysicsStream = 'Main'
 
@@ -109,7 +107,7 @@ if __name__ == "__main__":
     # print all hypo algs and their hypo tools for debugging
     from AthenaCommon.CFElements import flatAlgorithmSequences    
     fs = flatAlgorithmSequences( menu.getSequence('HLTAllSteps') )
-    for seq, algs in six.iteritems (fs):
+    for seq, algs in fs.items():
         for alg in algs:
             if 'HypoTools' in alg._properties:
                 log.verbose("%s %s", alg.name, [ t.getFullJobOptName() for t in alg.HypoTools ])
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
index dad431596e8..8ea012e8f2e 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
@@ -4,7 +4,6 @@ log = logging.getLogger( __name__ )
 log.info("Importing %s",__name__)
 
 from copy import deepcopy
-import six
 
 #==========================================================
 # This is stored in chainDict['Signature']
@@ -894,7 +893,7 @@ AllowedTopos = AllowedTopos_e + AllowedTopos_mu + AllowedTopos_Bphysics + Allowe
 #==========================================================
 def getSignatureNameFromToken(chainpart):
     theMatchingTokens = []
-    reverseSliceIDDict = dict([(value, key) for key, value in six.iteritems (SliceIDDict)]) #reversed SliceIDDict
+    reverseSliceIDDict = { value: key for key, value in SliceIDDict.items() } #reversed SliceIDDict
     for sig,token in SliceIDDict.items():
         if (token in chainpart):
             theMatchingTokens += [token]
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/TriggerConfigHLT.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/TriggerConfigHLT.py
index d55b693e617..688b27cbcb7 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/TriggerConfigHLT.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/TriggerConfigHLT.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 #########################################################################################
 #
@@ -7,7 +7,6 @@
 #########################################################################################
 
 import sys
-from six import itervalues
 from AthenaCommon.Logging import logging
 log = logging.getLogger(__name__)
 
@@ -51,11 +50,11 @@ class TriggerConfigHLT(object):
     @classmethod
     def dictsList(cls):
 
-        return list(itervalues(cls.__allChainDicts))
+        return list(cls.__allChainDicts.values())
 
     @classmethod
     def configsList(cls):
-        return list(itervalues(cls.__allChainConfigs))
+        return list(cls.__allChainConfigs.values())
 
     @classmethod
     def getChainDictFromChainName(cls, chainName):
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Test/ViewCFTest.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Test/ViewCFTest.py
index 4721965a9c2..8aad0a9da32 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Test/ViewCFTest.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Test/ViewCFTest.py
@@ -4,13 +4,10 @@ from TriggerMenuMT.HLTMenuConfig.Menu.CFValidation import findViewAlgs, checkVDV
 from AthenaCommon.AlgSequence import AlgSequence
 from AthenaCommon.CFElements import seqOR
 import AthenaCommon.CfgMgr as CfgMgr
-import six
 
 import unittest
 
 class ViewCFTest( unittest.TestCase ):
-    if six.PY2:
-        assertRaisesRegex = unittest.TestCase.assertRaisesRegexp        
 
     def runTest( self ):
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/L1MenuFlags.py b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/L1MenuFlags.py
index 521644ecc20..8d50cb2ac75 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/L1MenuFlags.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/L1MenuFlags.py
@@ -4,7 +4,6 @@ __doc__="Level 1 specific configuration for L1 Run 3"
 
 from .Limits import Limits
 from collections import Iterable, OrderedDict
-import six
 
 
 class FlagWrapper:
@@ -37,12 +36,12 @@ class L1MenuFlagsCont(object):
     statusOn = set()
 
     __slots__ = {
-        "MenuSetup"               :  FlagArgs( six.string_types ),
+        "MenuSetup"               :  FlagArgs( str ),
         "CTPVersion"              :  FlagArgs( int, 4,   val_check = lambda x: x in range(5), action = lambda x: Limits.setLimits(x) ),
         "BunchGroupPartitioning"  :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: y not in range(16), x)))==0 ),
-        "BunchGroupNames"         :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, six.string_types), x)))==0),
+        "BunchGroupNames"         :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
         "MenuPartitioning"        :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: y not in range(512), x)))==0 ),
-        "items"                   :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, six.string_types), x)))==0),
+        "items"                   :  FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
         "boards"                  :  FlagArgs( OrderedDict, OrderedDict() ),
         "legacyBoards"            :  FlagArgs( OrderedDict, OrderedDict() ),
         "prescales"               :  FlagArgs( dict, dict() ),
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/Limits.py b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/Limits.py
index b930e16df61..d263cda51dc 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/Limits.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Base/Limits.py
@@ -1,9 +1,8 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 """
 This temporarily holds CTP sizes
 """
-import six
 
 from AthenaCommon.Logging import logging
 log = logging.getLogger('Menu.L1.Base.Limits')
@@ -40,8 +39,7 @@ class Access(type):
 
 
 
-@six.add_metaclass(Access)
-class Limits(object):
+class Limits(object, metaclass=Access):
 
     CTPVersion      = None
     L1CommonVersion = None
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Config/TypeWideThresholdConfig.py b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Config/TypeWideThresholdConfig.py
index 0fe451494a0..844bb1e48f0 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Config/TypeWideThresholdConfig.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/L1/Config/TypeWideThresholdConfig.py
@@ -1,6 +1,5 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
-import six
 from collections import OrderedDict as odict
 
 from AthenaCommon.Logging import logging
@@ -9,7 +8,7 @@ log = logging.getLogger('Menu.L1.Config.TypeWideThresholdConfig')
 from ..Base.ThresholdType import ThrType
 
 def getTypeWideThresholdConfig(ttype):
-    if isinstance(ttype,six.string_types):
+    if isinstance(ttype, str):
         ttype = ThrType[ttype]
 
     if ttype == ThrType.MU:
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Limits.py b/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Limits.py
index 333ce939ed8..f371bb7b725 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Limits.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Limits.py
@@ -1,9 +1,8 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 """
 This temporarily holds CTP sizes
 """
-import six
 
 from AthenaCommon.Logging import logging
 log = logging.getLogger('LVL1.Limits')
@@ -40,8 +39,7 @@ class Access(type):
 
 
 
-@six.add_metaclass(Access)
-class Limits(object):
+class Limits(object, metaclass=Access):
 
     CTPVersion      = None
     L1CommonVersion = None
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Lvl1Thresholds.py b/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Lvl1Thresholds.py
index 2b7849f1b70..d74fe35b8cf 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Lvl1Thresholds.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/LVL1MenuConfig/LVL1/Lvl1Thresholds.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 from .Limits import CaloLimits as CL
 IsolationOff = CL.IsolationOff
@@ -6,7 +6,6 @@ IsolationOff = CL.IsolationOff
 from copy import deepcopy
 
 from past.builtins import cmp
-import six
 
 class ThresholdValue(object):
 
@@ -385,11 +384,8 @@ class LVL1Thresholds(object):
         return None
 
     def xml(self, ind=1, step=2):
-        if six.PY2:
-            self.thresholds.sort(LVL1Thresholds.compThreshold)
-        else:
-            import functools
-            self.thresholds.sort(key=functools.cmp_to_key(LVL1Thresholds.compThreshold))
+        import functools
+        self.thresholds.sort(key=functools.cmp_to_key(LVL1Thresholds.compThreshold))
         s = ind * step * ' ' + '<TriggerThresholdList>\n'
         for thr in self.thresholds:
             s += thr.xml(ind+1,step)
-- 
GitLab