Skip to content

Commit

Permalink
Merge pull request #26410 from davidlange6/xrange_fwk
Browse files Browse the repository at this point in the history
xrange migration in fwk packages for python3
  • Loading branch information
cmsbuild committed Apr 11, 2019
2 parents e80f17b + 885a056 commit 9b226cd
Show file tree
Hide file tree
Showing 47 changed files with 101 additions and 54 deletions.
5 changes: 3 additions & 2 deletions DataFormats/FWLite/examples/patZpeak.py
@@ -1,5 +1,6 @@
#! /usr/bin/env python

from builtins import range
import ROOT
import sys
from DataFormats.FWLite import Events, Handle
Expand Down Expand Up @@ -39,9 +40,9 @@
# use muons to make Z peak
numMuons = len (muons)
if muons < 2: continue
for outer in xrange (numMuons - 1):
for outer in range (numMuons - 1):
outerMuon = muons[outer]
for inner in xrange (outer + 1, numMuons):
for inner in range (outer + 1, numMuons):
innerMuon = muons[inner]
if outerMuon.charge() * innerMuon.charge() >= 0:
continue
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/test/chainEvent_python.py
@@ -1,6 +1,7 @@
#! /usr/bin/env python

from __future__ import print_function
from builtins import range
from DataFormats.FWLite import Events, Handle
import optparse

Expand Down Expand Up @@ -34,7 +35,7 @@
for loop in range (thing.size()):
print(thing.at (loop).a)

for i in xrange(events.size()):
for i in range(events.size()):
if not events.to(i):
print("failed to go to index ",i)
exit(1)
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/test/pyroot_read_associationvector.py
@@ -1,5 +1,6 @@
#! /usr/bin/env python

from builtins import range
import ROOT
import sys
from DataFormats.FWLite import Events, Handle
Expand All @@ -16,7 +17,7 @@
#print "###################### ", count
event.getByLabel (label, handle)
cont = handle.product()
values = [ cont.value(i).value for i in xrange(len(cont))]
values = [ cont.value(i).value for i in range(len(cont))]
for i,v in enumerate(handle.product()):
#print v.second.value, values[i]
if v.second.value != values[i]:
Expand Down
1 change: 1 addition & 0 deletions DataFormats/PatCandidates/test/dump_parameterization.py
@@ -1,5 +1,6 @@
#!/bin/env python
from __future__ import print_function
from builtins import range
import ROOT
from ROOT import *
import sys
Expand Down
39 changes: 20 additions & 19 deletions FWCore/Concurrency/scripts/edmStreamStallGrapher.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from builtins import range
from itertools import groupby
from operator import attrgetter,itemgetter
import sys
Expand Down Expand Up @@ -317,7 +318,7 @@ def findStalledModules(processingSteps, numStreams):
streamTime = [0]*numStreams
streamState = [0]*numStreams
stalledModules = {}
modulesActiveOnStream = [{} for x in xrange(numStreams)]
modulesActiveOnStream = [{} for x in range(numStreams)]
for n,trans,s,time,isEvent in processingSteps:

waitTime = None
Expand Down Expand Up @@ -351,7 +352,7 @@ def createModuleTiming(processingSteps, numStreams):
streamTime = [0]*numStreams
streamState = [0]*numStreams
moduleTimings = defaultdict(list)
modulesActiveOnStream = [defaultdict(int) for x in xrange(numStreams)]
modulesActiveOnStream = [defaultdict(int) for x in range(numStreams)]
for n,trans,s,time,isEvent in processingSteps:
waitTime = None
modulesOnStream = modulesActiveOnStream[s]
Expand All @@ -372,7 +373,7 @@ def createModuleTiming(processingSteps, numStreams):
def createAsciiImage(processingSteps, numStreams, maxNameSize):
streamTime = [0]*numStreams
streamState = [0]*numStreams
modulesActiveOnStreams = [{} for x in xrange(numStreams)]
modulesActiveOnStreams = [{} for x in range(numStreams)]
for n,trans,s,time,isEvent in processingSteps:
waitTime = None
modulesActiveOnStream = modulesActiveOnStreams[s]
Expand Down Expand Up @@ -505,9 +506,9 @@ def unpack(self):
# drastically reduces the size of the pdf file.
def consolidateContiguousBlocks(numStreams, streamInfo):
oldStreamInfo = streamInfo
streamInfo = [[] for x in xrange(numStreams)]
streamInfo = [[] for x in range(numStreams)]

for s in xrange(numStreams):
for s in range(numStreams):
if oldStreamInfo[s]:
lastStartTime,lastTimeLength,lastColor = oldStreamInfo[s][0].unpack()
for info in oldStreamInfo[s][1:]:
Expand Down Expand Up @@ -580,23 +581,23 @@ def plotPerStreamAboveFirstAndPrepareStack(points, allStackTimes, ax, stream, he
def createPDFImage(pdfFile, shownStacks, processingSteps, numStreams, stalledModuleInfo, displayExternalWork, checkOrder):

stalledModuleNames = set([x for x in stalledModuleInfo.iterkeys()])
streamLowestRow = [[] for x in xrange(numStreams)]
modulesActiveOnStreams = [set() for x in xrange(numStreams)]
acquireActiveOnStreams = [set() for x in xrange(numStreams)]
externalWorkOnStreams = [set() for x in xrange(numStreams)]
previousFinishTime = [None for x in xrange(numStreams)]
streamRunningTimes = [[] for x in xrange(numStreams)]
streamExternalWorkRunningTimes = [[] for x in xrange(numStreams)]
streamLowestRow = [[] for x in range(numStreams)]
modulesActiveOnStreams = [set() for x in range(numStreams)]
acquireActiveOnStreams = [set() for x in range(numStreams)]
externalWorkOnStreams = [set() for x in range(numStreams)]
previousFinishTime = [None for x in range(numStreams)]
streamRunningTimes = [[] for x in range(numStreams)]
streamExternalWorkRunningTimes = [[] for x in range(numStreams)]
maxNumberOfConcurrentModulesOnAStream = 1
externalWorkModulesInJob = False
previousTime = [0 for x in xrange(numStreams)]
previousTime = [0 for x in range(numStreams)]

# The next five variables are only used to check for out of order transitions
finishBeforeStart = [set() for x in xrange(numStreams)]
finishAcquireBeforeStart = [set() for x in xrange(numStreams)]
countSource = [0 for x in xrange(numStreams)]
countDelayedSource = [0 for x in xrange(numStreams)]
countExternalWork = [defaultdict(int) for x in xrange(numStreams)]
finishBeforeStart = [set() for x in range(numStreams)]
finishAcquireBeforeStart = [set() for x in range(numStreams)]
countSource = [0 for x in range(numStreams)]
countDelayedSource = [0 for x in range(numStreams)]
countExternalWork = [defaultdict(int) for x in range(numStreams)]

timeOffset = None
for n,trans,s,time,isEvent in processingSteps:
Expand Down Expand Up @@ -730,7 +731,7 @@ def createPDFImage(pdfFile, shownStacks, processingSteps, numStreams, stalledMod
ax.set_xlabel("Time (sec)")
ax.set_ylabel("Stream ID")
ax.set_ylim(-0.5,numStreams-0.5)
ax.yaxis.set_ticks(xrange(numStreams))
ax.yaxis.set_ticks(range(numStreams))

height = 0.8/maxNumberOfConcurrentModulesOnAStream
allStackTimes={'green': [],'limegreen':[], 'red': [], 'blue': [], 'orange': [], 'darkviolet': []}
Expand Down
3 changes: 2 additions & 1 deletion FWCore/GuiBrowsers/python/EnablePSetHistory.py
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
from copy import deepcopy
import inspect
import six
Expand Down Expand Up @@ -575,7 +576,7 @@ def testPSet(self):
)
),
seven = cms.vstring('alpha','bravo','charlie'),
eight = cms.vuint32(range(10)),
eight = cms.vuint32(list(range(10))),
nine = cms.int32(0)
)
ex.zero = cms.string('hello')
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Gui/PortConnection.py
@@ -1,3 +1,4 @@
from builtins import range
import logging

from PyQt4.QtCore import Qt, QPoint, QPointF, QRectF, QSizeF, SIGNAL
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Gui/ToolBoxContainer.py
@@ -1,3 +1,4 @@
from builtins import range
from PyQt4.QtCore import *
from PyQt4.QtGui import *

Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Gui/VispaWidget.py
@@ -1,3 +1,4 @@
from builtins import range
import math

from PyQt4.QtCore import *
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/Application.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from builtins import range
import os
import sys
import string
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/MainWindow.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from builtins import range
import logging
import os
import math
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/RotatingIcon.py
@@ -1,3 +1,4 @@
from builtins import range
from PyQt4.QtCore import QTimeLine,SIGNAL,Qt
from PyQt4.QtGui import QLabel,QPixmap,QMatrix,QPainter

Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/SplitterTab.py
@@ -1,3 +1,4 @@
from builtins import range
import logging

from PyQt4.QtCore import Qt, SIGNAL, QCoreApplication, QEvent, QSize
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/StartupScreen.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from builtins import range
import logging

from PyQt4.QtCore import SIGNAL,QRect,QSize,QPoint
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Main/TabController.py
@@ -1,3 +1,4 @@
from builtins import range
import os.path
import logging
import math
Expand Down
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
import sys
import os.path
import logging
Expand Down
@@ -1,3 +1,4 @@
from builtins import range
import logging
import os.path

Expand All @@ -20,7 +21,7 @@ def all(container):
if hasattr(container,'GetEntries'):
try:
entries = container.GetEntries()
for entry in xrange(entries):
for entry in range(entries):
yield entry
except:
raise cmserror("Looping of %s failed" %container)
Expand All @@ -31,7 +32,7 @@ def all(container):
container = container.ids()
try:
entries = container.size()
for entry in xrange(entries):
for entry in range(entries):
yield container[entry]
except:
pass
Expand Down Expand Up @@ -204,7 +205,7 @@ def getObjectContent(self,object):
split_typestring=typestring.split(" ")
templates=0
end_typestring=0
for i in reversed(range(len(split_typestring))):
for i in reversed(list(range(len(split_typestring)))):
templates+=split_typestring[i].count("<")
templates-=split_typestring[i].count(">")
if templates==0:
Expand Down
@@ -1,3 +1,4 @@
from builtins import range
import sys
import logging
import os.path
Expand Down
@@ -1,3 +1,4 @@
from builtins import range
import logging

from PyQt4.QtGui import *
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Views/LineDecayView.py
@@ -1,3 +1,4 @@
from builtins import range
import sys
import math

Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Views/PropertyView.py
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
import logging
import sys
import os.path
Expand Down
1 change: 1 addition & 0 deletions FWCore/GuiBrowsers/python/Vispa/Views/TableView.py
@@ -1,3 +1,4 @@
from builtins import range
import logging

from PyQt4.QtGui import *
Expand Down
3 changes: 2 additions & 1 deletion FWCore/Modules/test/emptysource_cfg.py
@@ -1,5 +1,6 @@
# Configuration file for EmptySource

from builtins import range
import FWCore.ParameterSet.Config as cms

process = cms.Process("TEST")
Expand All @@ -22,7 +23,7 @@
numberOfEventsPerRun = process.source.numberEventsInRun.value()
run = process.source.firstRun.value()
event=0
for i in xrange(process.maxEvents.input.value()):
for i in range(process.maxEvents.input.value()):
numberOfEventsInRun +=1
event += 1
if numberOfEventsInRun > numberOfEventsPerRun:
Expand Down
@@ -1,5 +1,6 @@
# Configuration file for EmptySource

from builtins import range
import FWCore.ParameterSet.Config as cms

process = cms.Process("TEST")
Expand Down Expand Up @@ -34,7 +35,7 @@ def findRunForLumi( lumi) :
lumi = process.source.firstLuminosityBlock.value()
event=0
oldRun = 2
for i in xrange(process.maxEvents.input.value()):
for i in range(process.maxEvents.input.value()):
numberOfEventsInLumi +=1
event += 1
run = findRunForLumi(lumi)
Expand Down
5 changes: 3 additions & 2 deletions FWCore/Modules/test/testBunchCrossingFilter.py
Expand Up @@ -22,6 +22,7 @@
# 3275-3322, 3330-3377, 3385-3432
# (see https://lpc.web.cern.ch/fillingSchemes/2018/25ns_2556b_2544_2215_2332_144bpi_20injV2.csv)

from builtins import range
import FWCore.ParameterSet.Config as cms
from FWCore.ParameterSet.pfnInPath import *

Expand Down Expand Up @@ -51,7 +52,7 @@

# full range of possible bunch crossings [1,3564]
process.selectAll = _bunchCrossingFilter.clone(
bunches = cms.vuint32(range(1,3565))
bunches = cms.vuint32(list(range(1,3565)))
)

# select bx 536
Expand All @@ -61,7 +62,7 @@

# select the whole train 514-561
process.selectTrain = _bunchCrossingFilter.clone(
bunches = cms.vuint32(range(514,562))
bunches = cms.vuint32(list(range(514,562)))
)

# inverted to veto (non-colliding) bx 1
Expand Down
5 changes: 3 additions & 2 deletions FWCore/ParameterSet/python/Mixins.py
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
import inspect
import six

Expand Down Expand Up @@ -744,7 +745,7 @@ def testListConstruction(self):
def testLargeList(self):
#lists larger than 255 entries can not be initialized
#using the constructor
args = [i for i in xrange(0,300)]
args = [i for i in range(0,300)]

t = TestList(*args)
pdump= t.dumpPython()
Expand Down Expand Up @@ -826,7 +827,7 @@ class __DummyModule(object):
def __init__(self):
self.tLPTest = tLPTest
self.tLPTestType = tLPTestType
p = tLPTest("MyType",** dict( [ ("a"+str(x), tLPTestType(x)) for x in xrange(0,300) ] ) )
p = tLPTest("MyType",** dict( [ ("a"+str(x), tLPTestType(x)) for x in range(0,300) ] ) )
#check they are the same
self.assertEqual(p.dumpPython(), eval(p.dumpPython(),{"cms": __DummyModule()}).dumpPython())
def testSpecialImportRegistry(self):
Expand Down
3 changes: 2 additions & 1 deletion FWCore/ParameterSet/python/SequenceTypes.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import

from builtins import range
from .Mixins import _ConfigureComponent, PrintOptions
from .Mixins import _Labelable, _Unlabelable
from .Mixins import _ValidatingParameterListBase
Expand Down Expand Up @@ -195,7 +196,7 @@ def __init__(self,*arg, **argv):
typename = format_typename(self)
msg = format_outerframe(2)
msg += "The %s constructor takes zero or one sequenceable argument followed by zero or more arguments of type Task. But the following types are given:\n" %typename
for item,i in zip(arg, xrange(1,20)):
for item,i in zip(arg, range(1,20)):
try:
msg += " %i) %s \n" %(i, item._errorstr())
except:
Expand Down
3 changes: 2 additions & 1 deletion FWCore/ParameterSet/python/TreeCrawler.py
Expand Up @@ -24,6 +24,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from builtins import range
import sys, os, inspect, copy, struct, dis, imp
import modulefinder
import six
Expand Down Expand Up @@ -252,7 +253,7 @@ def removeRecursiveLoops( node, verbose=False, currentStack=None ) :
duplicateIndex=currentStack.index( node ) # If there isn't a recursive loop this will raise a ValueError
if verbose :
print("Removing recursive loop in:")
for index in xrange(duplicateIndex,len(currentStack)) :
for index in range(duplicateIndex,len(currentStack)) :
print(" ",currentStack[index].name,"-->")
print(" ",node.name)
currentStack[-1].dependencies.remove(node)
Expand Down

0 comments on commit 9b226cd

Please sign in to comment.