diff --git a/GaudiKernel/python/GaudiConfig/ControlFlow.py b/GaudiKernel/python/GaudiConfig/ControlFlow.py index 30e7d58b50ba1fce92cedc4ffee1a103f11e0a83..178090fac6cdde31a21e625c47d98d2bbc4cf840 100644 --- a/GaudiKernel/python/GaudiConfig/ControlFlow.py +++ b/GaudiKernel/python/GaudiConfig/ControlFlow.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -295,7 +295,6 @@ class DotVisitor(object): If AND nodes are inside AND nodes, the graph could be simplified to not contain those (same true for OR and ordered) """ - counter = 0 if len(self.stack) != 0: mother = self.stack[-1][1] for entry in self.stack[::-1]: diff --git a/GaudiKernel/python/GaudiKernel/Configurable.py b/GaudiKernel/python/GaudiKernel/Configurable.py index d3a11ecd335687c94c1d59fbce49353b8a3c53f8..a3aa4b9bf265b5bb0208c40b726b50ae92b9335b 100644 --- a/GaudiKernel/python/GaudiKernel/Configurable.py +++ b/GaudiKernel/python/GaudiKernel/Configurable.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2021 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -15,7 +15,6 @@ from __future__ import absolute_import import copy import os -import string import sys import types from inspect import isclass @@ -42,8 +41,14 @@ from GaudiKernel.Constants import ( WARNING, error_explanation, ) -from GaudiKernel.DataHandle import * -from GaudiKernel.GaudiHandles import * +from GaudiKernel.DataHandle import DataHandle +from GaudiKernel.GaudiHandles import ( + GaudiHandle, + GaudiHandleArray, + PrivateToolHandle, + PublicToolHandle, + ServiceHandle, +) from GaudiKernel.PropertyProxy import PropertyProxy # data --------------------------------------------------------------------- @@ -238,7 +243,7 @@ class Configurable(six.with_metaclass(ConfigurableMeta.ConfigurableMeta, object) setattr(conf, n, v) if ( not cls._configurationLocked - and not "_enabled" in kwargs + and "_enabled" not in kwargs and isinstance(conf, ConfigurableUser) ): # Ensure that the ConfigurableUser gets enabled if nothing is @@ -551,7 +556,7 @@ class Configurable(six.with_metaclass(ConfigurableMeta.ConfigurableMeta, object) if type(items) != list and type(items) != tuple: items = [items] - self.__children = [e for e in self.__children if not e in items] + self.__children = [e for e in self.__children if e not in items] def removeAll(self): self.remove(self.__children) @@ -743,7 +748,7 @@ class Configurable(six.with_metaclass(ConfigurableMeta.ConfigurableMeta, object) # defaults from C++ for k, v in cls._properties.items(): - if not k in c.__dict__ and hasattr(v, "default"): + if k not in c.__dict__ and hasattr(v, "default"): c.__dict__[k] = v.default return c.__dict__ @@ -920,7 +925,7 @@ class Configurable(six.with_metaclass(ConfigurableMeta.ConfigurableMeta, object) import __main__ for svc in svcs: - handle = __main__.Service(svc) + handle = __main__.Service(svc) # noqa: F841 (used in eval below) # services should be configurables as well, but aren't for now # handle.setup() @@ -932,7 +937,7 @@ class Configurable(six.with_metaclass(ConfigurableMeta.ConfigurableMeta, object) dlls = self.getDlls() if not dlls: dlls = [] - elif type(dlls) == types.StringType: + elif isinstance(dlls, types.StringType): dlls = [dlls] from __main__ import theApp @@ -1113,7 +1118,7 @@ class ConfigurableGeneric(Configurable): return # assume all the rest are properties - if not name in self._properties: + if name not in self._properties: self._properties[name] = PropertyProxy(DummyDescriptor(name)) self._properties[name].__set__(self, value) @@ -1145,7 +1150,9 @@ class ConfigurableAlgorithm(Configurable): return self # algorithms are always shared def getHandle(self): - return iAlgorithm(self.getJobOptName()) + return iAlgorithm( # noqa: F821 (to avoid circular dependeny) + self.getJobOptName() + ) @classmethod def getGaudiType(cls): @@ -1197,6 +1204,7 @@ class ConfigurableAlgorithm(Configurable): class ConfigurableService(Configurable): + __slots__ = { "OutputLevel": 0, "AuditServices": 0, @@ -1215,7 +1223,7 @@ class ConfigurableService(Configurable): return child def getHandle(self): - return iService(self._name) + return iService(self._name) # noqa: F821 (to avoid circular dependeny) @classmethod def getGaudiType(cls): @@ -1249,7 +1257,9 @@ class ConfigurableAlgTool(Configurable): def getHandle(self): # iAlgTool isn't useful, unless one knows for sure that the tool exists - return iProperty(self.getJobOptName()) + return iProperty( # noqa: F821 (to avoid circular dependeny) + self.getJobOptName() + ) @classmethod def getGaudiType(cls): @@ -1330,7 +1340,9 @@ class ConfigurableAuditor(Configurable): def getHandle(self): # iAlgTool isn't useful, unless one knows for sure that the tool exists - return iProperty(self.getJobOptName()) + return iProperty( # noqa: F821 (to avoid circular dependeny) + self.getJobOptName() + ) @classmethod def getGaudiType(cls): @@ -1572,7 +1584,7 @@ def appendPostConfigAction(function): """ try: postConfigActions.remove(function) - except: + except Exception: pass postConfigActions.append(function) diff --git a/GaudiKernel/python/GaudiKernel/ConfigurableDb.py b/GaudiKernel/python/GaudiKernel/ConfigurableDb.py index 2399de65ca0c6b238a3645fd0ec487148debacd3..6b5ec4ff2129d16cda17b0db67ba71023728b4bf 100644 --- a/GaudiKernel/python/GaudiKernel/ConfigurableDb.py +++ b/GaudiKernel/python/GaudiKernel/ConfigurableDb.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -122,8 +122,6 @@ def loadConfigurableDb(): informations about Configurables """ import os - import sys - from glob import glob from os.path import join as path_join log.debug("loading confDb files...") diff --git a/GaudiKernel/python/GaudiKernel/GaudiHandles.py b/GaudiKernel/python/GaudiKernel/GaudiHandles.py index 26fbac55e4130213c09e6dc86b20e876591750a1..4b064497a10dea4c73479466fcd961308dee491f 100644 --- a/GaudiKernel/python/GaudiKernel/GaudiHandles.py +++ b/GaudiKernel/python/GaudiKernel/GaudiHandles.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2022 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -23,8 +23,6 @@ __all__ = [ ] __doc__ = """The python module holding python bindings to XyzHandles""" -from os import linesep - class GaudiHandle(object): componentType = "Unspecified" # must be overridden by derived class diff --git a/GaudiKernel/python/GaudiKernel/PhysicalConstants.py b/GaudiKernel/python/GaudiKernel/PhysicalConstants.py index 3f901d91e0f286794caf7ffe6470a073a586859f..af30d8a699b26c3a1fbb276f081350c3d93dd449 100644 --- a/GaudiKernel/python/GaudiKernel/PhysicalConstants.py +++ b/GaudiKernel/python/GaudiKernel/PhysicalConstants.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -50,7 +50,7 @@ # 08.07.20 Updated # ----- -from GaudiKernel.SystemOfUnits import * +import GaudiKernel.SystemOfUnits as Units # # @@ -63,13 +63,13 @@ pi2 = pi * pi # # # -Avogadro = 6.0221367e23 / mole +Avogadro = 6.0221367e23 / Units.mole # # c = 299.792458 mm/ns # c^2 = 898.7404 (mm/ns)^2 # -c_light = 2.99792458e8 * m / s +c_light = 2.99792458e8 * Units.m / Units.s c_squared = c_light * c_light # @@ -77,7 +77,7 @@ c_squared = c_light * c_light # hbar = 6.58212e-13 MeV*ns # hbarc = 197.32705e-12 MeV*mm # -h_Planck = 6.62606896e-34 * joule * s +h_Planck = 6.62606896e-34 * Units.joule * Units.s hbar_Planck = h_Planck / twopi hbarc = hbar_Planck * c_light hbarc_squared = hbarc * hbarc @@ -85,24 +85,24 @@ hbarc_squared = hbarc * hbarc # # # -electron_charge = -eplus # see SystemOfUnits.h -e_squared = eplus * eplus +electron_charge = -Units.eplus # see SystemOfUnits.h +e_squared = Units.eplus * Units.eplus # # amu_c2 - atomic equivalent mass unit # amu - atomic mass unit # -electron_mass_c2 = 0.510998910 * MeV -proton_mass_c2 = 938.272013 * MeV -neutron_mass_c2 = 939.56536 * MeV -amu_c2 = 931.494028 * MeV +electron_mass_c2 = 0.510998910 * Units.MeV +proton_mass_c2 = 938.272013 * Units.MeV +neutron_mass_c2 = 939.56536 * Units.MeV +amu_c2 = 931.494028 * Units.MeV amu = amu_c2 / c_squared # # permeability of free space mu0 = 2.01334e-16 Mev*(ns*eplus)^2/mm # permittivity of free space epsil0 = 5.52636e+10 eplus^2/(MeV*mm) # -mu0 = 4 * pi * 1.0e-7 * henry / m +mu0 = 4 * pi * 1.0e-7 * Units.henry / Units.m epsilon0 = 1.0 / (c_squared * mu0) # @@ -122,16 +122,16 @@ twopi_mc2_rcl2 = ( # # # -k_Boltzmann = 8.617343e-11 * MeV / kelvin +k_Boltzmann = 8.617343e-11 * Units.MeV / Units.kelvin # # # -STP_Temperature = 273.15 * kelvin -STP_Pressure = 1.0 * atmosphere -kGasThreshold = 10.0 * mg / cm3 +STP_Temperature = 273.15 * Units.kelvin +STP_Pressure = 1.0 * Units.atmosphere +kGasThreshold = 10.0 * Units.mg / Units.cm3 # # # -universe_mean_density = 1.0e-25 * g / cm3 +universe_mean_density = 1.0e-25 * Units.g / Units.cm3 diff --git a/GaudiKernel/python/GaudiKernel/PropertyProxy.py b/GaudiKernel/python/GaudiKernel/PropertyProxy.py index 719637375c0755380195931c0ac8d9c5b3d44339..54cb1aaaba48b40121e0d3c56864e24689daa957 100644 --- a/GaudiKernel/python/GaudiKernel/PropertyProxy.py +++ b/GaudiKernel/python/GaudiKernel/PropertyProxy.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -19,7 +19,7 @@ import logging import os from GaudiKernel.DataHandle import DataHandle -from GaudiKernel.GaudiHandles import * +from GaudiKernel.GaudiHandles import GaudiHandle, GaudiHandleArray from GaudiKernel import ConfigurableDb @@ -137,7 +137,7 @@ class PropertyProxy(object): # binding (if ever done) if ( proptype - and proptype != type(None) + and not isinstance(None, proptype) and not derives_from(value, "PropertyReference") ): try: @@ -166,9 +166,9 @@ class PropertyProxy(object): # allow a property to be set if we're in non-default mode, or if it # simply hasn't been set before - if not obj._isInSetDefaults() or not obj in self.history: + if not obj._isInSetDefaults() or obj not in self.history: # by convention, 'None' for default is used to designate objects setting - if hasattr(self, "default") and self.default == None: + if hasattr(self, "default") and self.default is None: obj.__iadd__(value, self.descr) # to establish hierarchy else: self.descr.__set__(obj, value) @@ -226,7 +226,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy): def __set__(self, obj, value): # allow a property to be set if we're in non-default mode, or if it # simply hasn't been set before - if not obj._isInSetDefaults() or not obj in self.history: + if not obj._isInSetDefaults() or obj not in self.history: value = self.convertValueToBeSet(obj, value) # assign the value self.descr.__set__(obj, value) @@ -442,7 +442,7 @@ class DataHandlePropertyProxy(PropertyProxy): return self.descr.__get__(obj, type) def __set__(self, obj, value): - if not obj._isInSetDefaults() or not obj in self.history: + if not obj._isInSetDefaults() or obj not in self.history: value = self.convertValueToBeSet(obj, value) # assign the value self.descr.__set__(obj, value) diff --git a/GaudiKernel/python/GaudiKernel/Proxy.py b/GaudiKernel/python/GaudiKernel/Proxy.py index 80bc01262b1961a705bf372dd45a6061e596ffa7..31e025391d8db1f4827d069cfcd65c43562dd65e 100644 --- a/GaudiKernel/python/GaudiKernel/Proxy.py +++ b/GaudiKernel/python/GaudiKernel/Proxy.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -39,6 +39,6 @@ import sys sys.modules["GaudiKernel.Proxy.Configurable"] = Configurable sys.modules["GaudiKernel.Proxy.ConfigurableDb"] = ConfigurableDb import GaudiKernel.Proxy.Configurable -import GaudiKernel.Proxy.ConfigurableDb +import GaudiKernel.Proxy.ConfigurableDb # noqa: F401 del sys diff --git a/GaudiKernel/python/GaudiKernel/RootMap.py b/GaudiKernel/python/GaudiKernel/RootMap.py index 9ccb16772e3efa5507418eb5fa4d37079688bee5..9a9d992eb06e4787167922c20044e40e5e19f1e0 100644 --- a/GaudiKernel/python/GaudiKernel/RootMap.py +++ b/GaudiKernel/python/GaudiKernel/RootMap.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -98,7 +98,7 @@ def getMaps(pathstring="", sysrtmap=False): rtmpfile = os.path.join(p, f) if os.path.exists(rtmpfile): _procRootMap(rtmpfile, rtmapdict) - except: + except Exception: pass return rtmapdict diff --git a/GaudiKernel/scripts/genconfuser.py b/GaudiKernel/scripts/genconfuser.py index 81e492ebca1952119c15467b7b13c192331f7571..8f0c3d0c25fd9e25c2c6bb954664b4be463417a7 100755 --- a/GaudiKernel/scripts/genconfuser.py +++ b/GaudiKernel/scripts/genconfuser.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 ##################################################################################### -# (c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -244,7 +244,7 @@ def main(): import Gaudi.Configurables Gaudi.Configurables.ignoreMissingConfigurables = True - except: + except ImportError: pass # load configurables database to avoid fake duplicates loadConfigurableDb(opts.build_dir, opts.project_name) @@ -260,7 +260,7 @@ def main(): # Extend the search path of the package module to find the configurables package_module = __import__(package_name) package_module.__path__.insert(0, os.path.join(genConfDir, package_name)) - except: + except Exception: pass # ignore failures (not important) # Collecting ConfigurableUser specializations diff --git a/GaudiKernel/scripts/make_patch.py b/GaudiKernel/scripts/make_patch.py index 2088fd5873318c7472ecae83ca743a069c3063f1..3661f553e9a62ad232c5554d120b48929e835b53 100755 --- a/GaudiKernel/scripts/make_patch.py +++ b/GaudiKernel/scripts/make_patch.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -15,7 +15,7 @@ import os import re import sys from fnmatch import fnmatch -from subprocess import PIPE, STDOUT, Popen +from subprocess import PIPE, Popen def command(cmd, *args, **kwargs): @@ -30,9 +30,16 @@ def command(cmd, *args, **kwargs): return proc.communicate() -cmt = lambda *args, **kwargs: command("cmt", *args, **kwargs) -cvs = lambda *args, **kwargs: command("cvs", *args, **kwargs) -svn = lambda *args, **kwargs: command("svn", *args, **kwargs) +def cmt(*args, **kwargs): + return command("cmt", *args, **kwargs) + + +def cvs(*args, **kwargs): + return command("cvs", *args, **kwargs) + + +def svn(*args, **kwargs): + return command("svn", *args, **kwargs) def broadcast_packages(): diff --git a/GaudiKernel/tests/nose/test_ControlFlow.py b/GaudiKernel/tests/nose/test_ControlFlow.py index 0b93f8afb330c6730757034d3fcbfbc4e206eb44..d0a83d03c6326cc06d5629a16184cb26ebe4441a 100644 --- a/GaudiKernel/tests/nose/test_ControlFlow.py +++ b/GaudiKernel/tests/nose/test_ControlFlow.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -8,7 +8,6 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ##################################################################################### -from GaudiConfig.ControlFlow import * from GaudiKernel.Configurable import Configurable from test_Configurables import MyAlg diff --git a/GaudiKernel/tests/nose/test_instructionsetLevel.py b/GaudiKernel/tests/nose/test_instructionsetLevel.py index a162f3d9129889927598a02d3cca7e9c0fcf35bd..21f1736ab48383c776391aa3821779c4ff0db0dc 100644 --- a/GaudiKernel/tests/nose/test_instructionsetLevel.py +++ b/GaudiKernel/tests/nose/test_instructionsetLevel.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -8,7 +8,6 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ##################################################################################### -import os from platform import processor from subprocess import PIPE, Popen