From 1fbf09511c99ed8ef62898c6afd13f8950f5fad8 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Sun, 29 Mar 2020 18:20:29 +0200 Subject: [PATCH] VP1Algs: Python 3 / flake8 fixes Updates for python 3 compatibility. Enable flake8 checking and fix warnings. --- graphics/VP1/VP1Algs/CMakeLists.txt | 2 +- graphics/VP1/VP1Algs/python/VP1EvtFilter.py | 15 +++--- graphics/VP1/VP1Algs/share/vp1.py | 18 ++++---- .../share/vp1FragmentConstructVP1ATLREL.py | 2 +- .../VP1Algs/share/vp1FragmentFixDBReplica.py | 46 +++++++++---------- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/graphics/VP1/VP1Algs/CMakeLists.txt b/graphics/VP1/VP1Algs/CMakeLists.txt index fd39e831faa..12161cc57f2 100644 --- a/graphics/VP1/VP1Algs/CMakeLists.txt +++ b/graphics/VP1/VP1Algs/CMakeLists.txt @@ -29,7 +29,7 @@ atlas_add_component( VP1Algs # Install files from the package: atlas_install_headers( VP1Algs ) -atlas_install_python_modules( python/*.py ) +atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) atlas_install_joboptions( share/*.py ) atlas_install_scripts( share/vp1 ) atlas_install_scripts( share/clear-bash-hash-table-vp1 ) diff --git a/graphics/VP1/VP1Algs/python/VP1EvtFilter.py b/graphics/VP1/VP1Algs/python/VP1EvtFilter.py index e18a0abffcf..de06d49baba 100644 --- a/graphics/VP1/VP1Algs/python/VP1EvtFilter.py +++ b/graphics/VP1/VP1Algs/python/VP1EvtFilter.py @@ -1,5 +1,6 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +from __future__ import print_function def readFileSimplified(filename): import os.path @@ -16,12 +17,12 @@ def filterEntry(parts): assert len(parts) in [1,2] filter_run = int(parts[0]) if len(parts)==2 else None filter_evt = int(parts[1]) if len(parts)==2 else int(parts[0]) - assert (filter_run==None or filter_run>=0) and filter_evt>=0 + assert (filter_run is None or filter_run>=0) and filter_evt>=0 return (filter_run,filter_evt) def readFiltersFromFile(filename): lines = readFileSimplified(filename) - if lines==None: return None + if lines is None: return None filts=[] for l in lines: filts+=[filterEntry(l.replace(':',' ').split())] @@ -43,18 +44,18 @@ def parseFilterString(s): filters += [filefilt] continue filters += [filterEntry(filt.split(':'))] - except: + except Exception: filters=[] - def vp1CfgErr(s): print "VP1 CONFIGURATION ERROR: %s" % s#fixme: should go in common utils module + def vp1CfgErr(s): print ("VP1 CONFIGURATION ERROR: %s" % s)#fixme: should go in common utils module vp1CfgErr("Badly formatted filter string '%s'" % str(s)) raise return (excludemode,filters) def installEventFilter(filters): def vp1filter(run,evt): - print "vp1filter(%i,%i) called" %(run,evt) + print ("vp1filter(%i,%i) called" %(run,evt)) for filter in filters[1]: - if evt==filter[1] and (filter[0]==None or filter[0]==run): return not filters[0] + if evt==filter[1] and (filter[0] is None or filter[0]==run): return not filters[0] return filters[0] from AthenaCommon.AlgSequence import AthSequencer seq = AthSequencer('AthMasterSeq') diff --git a/graphics/VP1/VP1Algs/share/vp1.py b/graphics/VP1/VP1Algs/share/vp1.py index cbde61703ff..963213d5890 100644 --- a/graphics/VP1/VP1Algs/share/vp1.py +++ b/graphics/VP1/VP1Algs/share/vp1.py @@ -38,7 +38,7 @@ if not 'vp1Trig' in dir(): vp1Trig=False if not 'vp1NSWAGDDFiles' in dir(): vp1NSWAGDDFiles=[] if not 'vp1MuonLayout' in dir(): vp1MuonLayout="" -def vp1CfgErr(s): print "VP1 CONFIGURATION ERROR: %s" % s +def vp1CfgErr(s): printfunc ("VP1 CONFIGURATION ERROR: %s" % s) if (vp1Fatras and not vp1ID): vp1CfgErr("Fatras can not be enabled without inner detector. Turning off Fatras.") @@ -59,8 +59,8 @@ if ( vp1FatrasTruthKey != "" and not vp1Fatras ): vp1CfgErr("FatrasTruthKey set but Fatras not enabled. Unsetting FatrasTruthKey.") vp1FatrasTruthKey="" -print "*** VP1 NOTE *** setting COIN_GLXGLUE env vars to make screenshots working remotely..." -print "*** VP1 NOTE *** COIN_GLXGLUE_NO_GLX13_PBUFFERS=1 - " + "COIN_GLXGLUE_NO_PBUFFERS=1" +printfunc ("*** VP1 NOTE *** setting COIN_GLXGLUE env vars to make screenshots working remotely...") +printfunc ("*** VP1 NOTE *** COIN_GLXGLUE_NO_GLX13_PBUFFERS=1 - " + "COIN_GLXGLUE_NO_PBUFFERS=1") os.putenv("COIN_GLXGLUE_NO_GLX13_PBUFFERS","1") os.putenv("COIN_GLXGLUE_NO_PBUFFERS","1") @@ -263,7 +263,7 @@ from AtlasGeoModel import GeoModelInit from AthenaCommon.AppMgr import ToolSvc if vp1Muon and len(vp1NSWAGDDFiles)>0: - print "*** VP1 NOTE *** You specified custom vp1NSWAGDDFiles, creating NSWAGDDTool to read NSWAGDD information from custom file(s) instead from built-in geometry" + printfunc ("*** VP1 NOTE *** You specified custom vp1NSWAGDDFiles, creating NSWAGDDTool to read NSWAGDD information from custom file(s) instead from built-in geometry") from AthenaCommon.AppMgr import theApp from AGDD2GeoSvc.AGDD2GeoSvcConf import AGDDtoGeoSvc AGDD2Geo = AGDDtoGeoSvc() @@ -274,7 +274,7 @@ if vp1Muon and len(vp1NSWAGDDFiles)>0: NSWAGDDTool = CfgMgr.NSWAGDDTool("NewSmallWheel", DefaultDetector="Muon", ReadAGDD=False, XMLFiles=vp1NSWAGDDFiles, Volumes=["NewSmallWheel"]) AGDD2Geo.Builders += [ NSWAGDDTool ] if vp1Muon and vp1MuonLayout!="": - print "*** VP1 NOTE *** You specified custom vp1MuonLayout, using %s as muon geometry"%vp1MuonLayout + printfunc ("*** VP1 NOTE *** You specified custom vp1MuonLayout, using %s as muon geometry"%vp1MuonLayout) from GeoModelSvc.GeoModelSvcConf import GeoModelSvc GeoModelSvc = GeoModelSvc() GeoModelSvc.MuonVersionOverride=vp1MuonLayout @@ -456,8 +456,8 @@ if vp1Extrapolator and (vp1ID or vp1Muon): # ToolMuonDriftCircle = MdtTubeHitOnTrackCreator , # Mode = 'all') # ToolSvc += VP1RotCreator -# print VP1RotCreator -# print MdtTubeHitOnTrackCreator +# printfunc (VP1RotCreator) +# printfunc (MdtTubeHitOnTrackCreator) # # from TrkKalmanFitter.TrkKalmanFitterConf import Trk__KalmanFitter as ConfiguredKalmanFitter # VP1KalmanFitter = ConfiguredKalmanFitter(name = 'VP1KalmanFitter', @@ -472,7 +472,7 @@ if vp1Extrapolator and (vp1ID or vp1Muon): # # ToolSvc += VP1KalmanFitter # -# print VP1KalmanFitter +# printfunc (VP1KalmanFitter) # os.putenv("VP1_JOBCFG_EXTRA_VP1_FITTERS",VP1KalmanFitter.name()) # # @@ -502,7 +502,7 @@ if vp1Extrapolator and (vp1ID or vp1Muon): # SignedDriftRadius = True, # RecalculateDerivatives= True # ) -# print VP1GlobalChi2Fitter +# printfunc (VP1GlobalChi2Fitter) # ToolSvc += VP1GlobalChi2Fitter # # VP1GlobalChi2Fitter.OutputLevel=DEBUG diff --git a/graphics/VP1/VP1Algs/share/vp1FragmentConstructVP1ATLREL.py b/graphics/VP1/VP1Algs/share/vp1FragmentConstructVP1ATLREL.py index e0eb714e0fc..f3d2e48f737 100644 --- a/graphics/VP1/VP1Algs/share/vp1FragmentConstructVP1ATLREL.py +++ b/graphics/VP1/VP1Algs/share/vp1FragmentConstructVP1ATLREL.py @@ -17,4 +17,4 @@ if not 'VP1ATLREL' in dir(): if versionMinor>99: versionMinor=99 if versionMinor==99 or versionPatch>99: versionPatch=99 VP1ATLREL=10000*versionMajor+100*versionMinor+versionPatch - print "VP1ATLREL: "+str(VP1ATLREL) + printfunc ("VP1ATLREL: "+str(VP1ATLREL)) diff --git a/graphics/VP1/VP1Algs/share/vp1FragmentFixDBReplica.py b/graphics/VP1/VP1Algs/share/vp1FragmentFixDBReplica.py index c25b574f134..a0cbe94d0ae 100644 --- a/graphics/VP1/VP1Algs/share/vp1FragmentFixDBReplica.py +++ b/graphics/VP1/VP1Algs/share/vp1FragmentFixDBReplica.py @@ -4,42 +4,42 @@ import os if globalflags.DataSource() == 'data' and os.getenv("FRONTIER_SERVER") == None : # Patch dblookup.xml to avoid any attempt to use sqlite replicas - print "VP1 Info: real data mode and Frontier environment not set - need to patch dblookup.xml to avoid using local sqlite replicas." + printfunc ("VP1 Info: real data mode and Frontier environment not set - need to patch dblookup.xml to avoid using local sqlite replicas.") if os.path.exists("dblookup.xml"): - print "VP1 Warning: dblookup.xml already found in run directory. Will not attempt to created patched copy." + printfunc ("VP1 Warning: dblookup.xml already found in run directory. Will not attempt to created patched copy.") os.putenv("CORAL_DBLOOKUP_PATH",".") else: if os.getenv("CORAL_AUTH_PATH") == None or not os.path.isdir(os.getenv("CORAL_AUTH_PATH")): - print "VP1 Warning: CORAL_AUTH_PATH is not set or does not point to directory. Can't create patched dblookup.xml." + printfunc ("VP1 Warning: CORAL_AUTH_PATH is not set or does not point to directory. Can't create patched dblookup.xml.") else: dblookupFileLocation=os.getenv("CORAL_AUTH_PATH")+"/dblookup.xml" if not os.path.exists(dblookupFileLocation) or not os.path.isfile(dblookupFileLocation): - print "VP1 Warning: Did not find CORAL_AUTH_PATH/dblookup.xml. Can't create patched dblookup.xml." + printfunc ("VP1 Warning: Did not find CORAL_AUTH_PATH/dblookup.xml. Can't create patched dblookup.xml.") else: - print "VP1 Warning: Attempting to create patched dblookup.xml in current directory" + printfunc ("VP1 Warning: Attempting to create patched dblookup.xml in current directory") os.system("cat $CORAL_AUTH_PATH/dblookup.xml |grep -v 'ALLP200.db'> dblookup.xml") os.putenv("CORAL_DBLOOKUP_PATH",".") if os.getenv("ATLAS_CONDDB")==None and (os.getenv("HOSTNAME") == None or os.getenv("HOSTNAME").find('.')<=0): - print "VP1 Warning: Unable to determine domain from runtime environment. Disabling attempt to find nearest replica." + printfunc ("VP1 Warning: Unable to determine domain from runtime environment. Disabling attempt to find nearest replica.") PoolSvc = Service( "PoolSvc" ) PoolSvc.SortReplicas = False - print "" - print " ==========>" - print " ========>" - print " ======>" - print " ====>" - print " ====> VP1 Warning: Can't find nearest Oracle replica and you are running on real data." - print " ====> Thus conditions data will have to come from the default, CERN (or you might crash!)." - print " ====>" - print " ====> Notice that this might SIGNIFICANTLY slow down (or even time-out) your job depending" - print " ====> on your location and connection! You can avoid the issue (and this warning) by fixing" - print " ====> your environment: either ATLAS_CONDDB or HOSTNAME. Alternatively you can edit a dblookup.xml file in your2" - print " ====> directory to only leave in references to a closer replica in sections where such a replica is available." - print " ====>" - print " ======>" - print " ========>" - print " ==========>" - print "" + printfunc ("") + printfunc (" ==========>") + printfunc (" ========>") + printfunc (" ======>") + printfunc (" ====>") + printfunc (" ====> VP1 Warning: Can't find nearest Oracle replica and you are running on real data.") + printfunc (" ====> Thus conditions data will have to come from the default, CERN (or you might crash!).") + printfunc (" ====>") + printfunc (" ====> Notice that this might SIGNIFICANTLY slow down (or even time-out) your job depending") + printfunc (" ====> on your location and connection! You can avoid the issue (and this warning) by fixing") + printfunc (" ====> your environment: either ATLAS_CONDDB or HOSTNAME. Alternatively you can edit a dblookup.xml file in your") + printfunc (" ====> directory to only leave in references to a closer replica in sections where such a replica is available.") + printfunc (" ====>") + printfunc (" ======>") + printfunc (" ========>") + printfunc (" ==========>") + printfunc ("") -- GitLab