From 3999a5b63a3af13e5de7a0b1f8b668184af31997 Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Fri, 14 Jul 2023 17:41:59 +0200 Subject: [PATCH] DDSim: remove python2 legacy shim --- DDG4/python/DDSim/Helper/Action.py | 5 +---- DDG4/python/DDSim/Helper/ConfigHelper.py | 16 ++++++---------- DDG4/python/DDSim/Helper/Filter.py | 14 +++++--------- DDG4/python/DDSim/Helper/Geometry.py | 2 -- DDG4/python/DDSim/Helper/GuineaPig.py | 1 - DDG4/python/DDSim/Helper/Gun.py | 4 +--- DDG4/python/DDSim/Helper/HepMC3.py | 1 - DDG4/python/DDSim/Helper/Input.py | 4 +--- DDG4/python/DDSim/Helper/LCIO.py | 1 - DDG4/python/DDSim/Helper/MagneticField.py | 1 - DDG4/python/DDSim/Helper/Meta.py | 6 ++---- DDG4/python/DDSim/Helper/Output.py | 1 - DDG4/python/DDSim/Helper/ParticleHandler.py | 1 - DDG4/python/DDSim/Helper/Physics.py | 4 +--- DDG4/python/DDSim/Helper/Random.py | 1 - 15 files changed, 17 insertions(+), 45 deletions(-) diff --git a/DDG4/python/DDSim/Helper/Action.py b/DDG4/python/DDSim/Helper/Action.py index b046d3c3e..6f9f0bf41 100644 --- a/DDG4/python/DDSim/Helper/Action.py +++ b/DDG4/python/DDSim/Helper/Action.py @@ -1,10 +1,7 @@ """Helper object for SD Actions """ -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper -from ddsix.moves import range -import ddsix as six class Action(ConfigHelper): @@ -80,7 +77,7 @@ class Action(ConfigHelper): self._mapActions.update(val) return - if isinstance(val, six.string_types): + if isinstance(val, str): vals = val.split(" ") elif isinstance(val, list): vals = val diff --git a/DDG4/python/DDSim/Helper/ConfigHelper.py b/DDG4/python/DDSim/Helper/ConfigHelper.py index c092be31a..0d7421155 100644 --- a/DDG4/python/DDSim/Helper/ConfigHelper.py +++ b/DDG4/python/DDSim/Helper/ConfigHelper.py @@ -12,10 +12,6 @@ call for the parser object create an additional member:: """ -from __future__ import absolute_import, unicode_literals - -import ddsix as six - class ConfigHelper(object): """Base class for configuration helper""" @@ -28,7 +24,7 @@ class ConfigHelper(object): # get all direct members not starting with underscore allVars = vars(self) - for var, val in six.iteritems(allVars): + for var, val in allVars.items(): if not var.startswith('_'): extraArgumentsName = "_%s_EXTRA" % var options = getattr(self, extraArgumentsName) if hasattr(self, extraArgumentsName) else None @@ -56,7 +52,7 @@ class ConfigHelper(object): def printOptions(self): """print all parameters""" options = [] - for opt, val in six.iteritems(self.getOptions()): + for opt, val in self.getOptions().items(): options.append("\n\t'%s': '%s'" % (opt, val['default'])) return "".join(options) @@ -100,7 +96,7 @@ class ConfigHelper(object): myTuple = val if isinstance(val, list): myTuple = tuple(val) - if isinstance(val, six.string_types): + if isinstance(val, str): sep = ',' if ',' in val else ' ' myTuple = tuple([_.strip("(), ") for _ in val.split(sep)]) if myTuple is None: @@ -112,7 +108,7 @@ class ConfigHelper(object): """check if val is a bool or a string of true/false, otherwise raise exception""" if isinstance(val, bool): return val - elif isinstance(val, six.string_types): + elif isinstance(val, str): if val.lower() == 'true': return True elif val.lower() == 'false': @@ -122,9 +118,9 @@ class ConfigHelper(object): @staticmethod def addAllHelper(ddsim, parser): """all configHelper objects to commandline args""" - for name, obj in six.iteritems(vars(ddsim)): + for name, obj in vars(ddsim).items(): if isinstance(obj, ConfigHelper): - for var, optionsDict in six.iteritems(obj.getOptions()): + for var, optionsDict in obj.getOptions().items(): optionsDict['action'] = 'store_true' if var.startswith("enable") else optionsDict.get('action', 'store') parser.add_argument("--%s.%s" % (name, var), dest="%s.%s" % (name, var), diff --git a/DDG4/python/DDSim/Helper/Filter.py b/DDG4/python/DDSim/Helper/Filter.py index 327bc645d..0b967904a 100644 --- a/DDG4/python/DDSim/Helper/Filter.py +++ b/DDG4/python/DDSim/Helper/Filter.py @@ -4,13 +4,9 @@ Later the parameter dictionary is used to instantiate the filter object The default filters are a GeantinoRejector and a 1keV minimum energy cut """ - -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import keV import logging -from ddsix.moves import range -import ddsix as six logger = logging.getLogger(__name__) @@ -90,7 +86,7 @@ class Filter(ConfigHelper): self._mapDetFilter.update(val) return - if isinstance(val, six.string_types): + if isinstance(val, str): vals = val.split(" ") elif isinstance(val, list): vals = val @@ -116,7 +112,7 @@ class Filter(ConfigHelper): def __makeMapDetList(self): """ create the values of the mapDetFilters a list of filters """ - for pattern, filters in six.iteritems(self._mapDetFilter): + for pattern, filters in self._mapDetFilter.items(): self._mapDetFilter[pattern] = ConfigHelper.makeList(filters) def setupFilters(self, kernel): @@ -124,10 +120,10 @@ class Filter(ConfigHelper): import DDG4 setOfFilters = set() - for name, filt in six.iteritems(self.filters): + for name, filt in self.filters.items(): setOfFilters.add(name) ddFilt = DDG4.Filter(kernel, filt['name']) - for para, value in six.iteritems(filt['parameter']): + for para, value in filt['parameter'].items(): setattr(ddFilt, para, value) kernel.registerGlobalFilter(ddFilt) filt['filter'] = ddFilt @@ -150,7 +146,7 @@ class Filter(ConfigHelper): """ self.__makeMapDetList() foundFilter = False - for pattern, filts in six.iteritems(self.mapDetFilter): + for pattern, filts in self.mapDetFilter.items(): if pattern.lower() in det.lower(): foundFilter = True for filt in filts: diff --git a/DDG4/python/DDSim/Helper/Geometry.py b/DDG4/python/DDSim/Helper/Geometry.py index 0ec99aa07..5718e4002 100644 --- a/DDG4/python/DDSim/Helper/Geometry.py +++ b/DDG4/python/DDSim/Helper/Geometry.py @@ -1,7 +1,5 @@ """Helper object for Geant4 Geometry conversion.""" -from __future__ import absolute_import, unicode_literals - from DDSim.Helper.ConfigHelper import ConfigHelper diff --git a/DDG4/python/DDSim/Helper/GuineaPig.py b/DDG4/python/DDSim/Helper/GuineaPig.py index 6a2f37372..1e2d26976 100644 --- a/DDG4/python/DDSim/Helper/GuineaPig.py +++ b/DDG4/python/DDSim/Helper/GuineaPig.py @@ -1,6 +1,5 @@ """Helper object for GuineaPig InputFile Parameters""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.Input import Input diff --git a/DDG4/python/DDSim/Helper/Gun.py b/DDG4/python/DDSim/Helper/Gun.py index 80b42bbc6..8b21d52ea 100644 --- a/DDG4/python/DDSim/Helper/Gun.py +++ b/DDG4/python/DDSim/Helper/Gun.py @@ -1,11 +1,9 @@ """Helper object for particle gun properties""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import GeV from math import atan, exp import logging -import ddsix as six logger = logging.getLogger(__name__) @@ -66,7 +64,7 @@ class Gun(ConfigHelper): if val is None: return possibleDistributions = self._distribution_EXTRA['choices'] - if not isinstance(val, six.string_types): + if not isinstance(val, str): raise RuntimeError("malformed input '%s' for gun.distribution. Need a string : %s " % (val, ",".join(possibleDistributions))) if val not in possibleDistributions: diff --git a/DDG4/python/DDSim/Helper/HepMC3.py b/DDG4/python/DDSim/Helper/HepMC3.py index 64423df4e..95e360c74 100644 --- a/DDG4/python/DDSim/Helper/HepMC3.py +++ b/DDG4/python/DDSim/Helper/HepMC3.py @@ -1,6 +1,5 @@ """Helper object for hepmc3 input control""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.Input import Input diff --git a/DDG4/python/DDSim/Helper/Input.py b/DDG4/python/DDSim/Helper/Input.py index 5b4e23885..8154930ad 100644 --- a/DDG4/python/DDSim/Helper/Input.py +++ b/DDG4/python/DDSim/Helper/Input.py @@ -1,8 +1,6 @@ """Base class for inputfile parameters""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper -import ddsix as six class Input(ConfigHelper): @@ -23,7 +21,7 @@ class Input(ConfigHelper): @_parameters.setter def _parameters(self, newParameters): if isinstance(newParameters, dict): - for par, val in six.iteritems(newParameters): + for par, val in newParameters.items(): self.__parameters[par] = str(val) else: diff --git a/DDG4/python/DDSim/Helper/LCIO.py b/DDG4/python/DDSim/Helper/LCIO.py index 95ea8f245..7c0d6e849 100644 --- a/DDG4/python/DDSim/Helper/LCIO.py +++ b/DDG4/python/DDSim/Helper/LCIO.py @@ -1,6 +1,5 @@ """Helper object for files containing one or more MCParticle collections""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.Input import Input diff --git a/DDG4/python/DDSim/Helper/MagneticField.py b/DDG4/python/DDSim/Helper/MagneticField.py index 1597542e5..dff5d51c9 100644 --- a/DDG4/python/DDSim/Helper/MagneticField.py +++ b/DDG4/python/DDSim/Helper/MagneticField.py @@ -1,5 +1,4 @@ """Helper object for Magnetic Field properties""" -from __future__ import absolute_import, unicode_literals from g4units import mm, m from DDSim.Helper.ConfigHelper import ConfigHelper diff --git a/DDG4/python/DDSim/Helper/Meta.py b/DDG4/python/DDSim/Helper/Meta.py index 6819e6fa9..d1a367738 100644 --- a/DDG4/python/DDSim/Helper/Meta.py +++ b/DDG4/python/DDSim/Helper/Meta.py @@ -1,11 +1,9 @@ """Helper object for configuring the LCIO output file (meta)""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper import datetime import os import logging -import ddsix as six from io import open logger = logging.getLogger(__name__) @@ -67,10 +65,10 @@ class Meta(ConfigHelper): """add the parameters to the (lcio) run Header""" runHeader = {} parameters = vars(sim) - for parName, parameter in six.iteritems(parameters): + for parName, parameter in parameters.items(): if isinstance(parameter, ConfigHelper): options = parameter.getOptions() - for opt, optionsDict in six.iteritems(options): + for opt, optionsDict in options.items(): runHeader["%s.%s" % (parName, opt)] = str(optionsDict['default']) else: runHeader[parName] = str(parameter) diff --git a/DDG4/python/DDSim/Helper/Output.py b/DDG4/python/DDSim/Helper/Output.py index 3c795fac3..f0ffe32bf 100644 --- a/DDG4/python/DDSim/Helper/Output.py +++ b/DDG4/python/DDSim/Helper/Output.py @@ -1,6 +1,5 @@ """Dummy helper object for particle gun properties""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper OUTPUT_CHOICES = (1, 2, 3, 4, 5, 6, 7, 'VERBOSE', 'DEBUG', diff --git a/DDG4/python/DDSim/Helper/ParticleHandler.py b/DDG4/python/DDSim/Helper/ParticleHandler.py index 138cc7a46..fb75d450f 100644 --- a/DDG4/python/DDSim/Helper/ParticleHandler.py +++ b/DDG4/python/DDSim/Helper/ParticleHandler.py @@ -1,5 +1,4 @@ """Configuration Helper for ParticleHandler""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import MeV, mm import logging diff --git a/DDG4/python/DDSim/Helper/Physics.py b/DDG4/python/DDSim/Helper/Physics.py index db1e82e33..18bbded1e 100644 --- a/DDG4/python/DDSim/Helper/Physics.py +++ b/DDG4/python/DDSim/Helper/Physics.py @@ -1,12 +1,10 @@ """Helper object for physicslist properties""" -from __future__ import absolute_import, unicode_literals import os from DDSim.Helper.ConfigHelper import ConfigHelper from g4units import mm import logging -import ddsix as six logger = logging.getLogger(__name__) @@ -72,7 +70,7 @@ class Physics(ConfigHelper): if val is None: self._rangecut = None return - if isinstance(val, six.string_types): + if isinstance(val, str): if val == "None": self._rangecut = None return diff --git a/DDG4/python/DDSim/Helper/Random.py b/DDG4/python/DDSim/Helper/Random.py index 1ee0c101d..363388e6f 100644 --- a/DDG4/python/DDSim/Helper/Random.py +++ b/DDG4/python/DDSim/Helper/Random.py @@ -1,6 +1,5 @@ """Helper object for random number generator objects""" -from __future__ import absolute_import, unicode_literals from DDSim.Helper.ConfigHelper import ConfigHelper import random import logging -- GitLab