Skip to content

Commit 4b4378d

Browse files
authored
Merge pull request #48784 from mmusich/mm_argparse_addOnTests
Switch `addOnTests.py` script from `getopt` to `argparse`
2 parents 827fb12 + 80c193a commit 4b4378d

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

Utilities/ReleaseScripts/scripts/addOnTests.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def file2Path(self,rFile):
119119
if os.path.exists(self.devPath + rFile): fullPath = self.devPath + rFile
120120
return fullPath
121121

122-
def runTests(self, testList = None):
122+
def runTests(self, testList = None, dontRun = False):
123123

124124
actDir = os.getcwd()
125125

@@ -145,9 +145,15 @@ def runTests(self, testList = None):
145145
print('Preparing to run %s' % str(command))
146146
current = testit(dirName, command)
147147
self.threadList.append(current)
148+
149+
if dontRun:
150+
continue
148151
current.start()
149152
time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
150153

154+
if dontRun:
155+
return
156+
151157
# wait until all threads are finished
152158
while self.activeThreads() > 0:
153159
time.sleep(5)
@@ -204,43 +210,44 @@ def upload(self, tgtDir):
204210

205211
return
206212

207-
208-
def main(argv) :
209-
210-
import getopt
211-
212-
try:
213-
opts, args = getopt.getopt(argv, "dj:t:", ["nproc=", 'uploadDir=', 'tests=','noRun','dump'])
214-
except getopt.GetoptError as e:
215-
print("unknown option", str(e))
216-
sys.exit(2)
217-
218-
np = 4
219-
uploadDir = None
220-
runTests = True
221-
testList = None
222-
dump = False
223-
for opt, arg in opts :
224-
if opt in ('-j', "--nproc" ):
225-
np=int(arg)
226-
if opt in ("--uploadDir", ):
227-
uploadDir = arg
228-
if opt in ('--noRun', ):
229-
runTests = False
230-
if opt in ('-d','--dump', ):
231-
dump = True
232-
if opt in ('-t','--tests', ):
233-
testList = arg.split(",")
234-
235-
tester = StandardTester(np)
236-
if dump:
213+
import argparse
214+
215+
def main(argv=None):
216+
parser = argparse.ArgumentParser(
217+
description="Run CMSSW addOnTests in parallel threads and collect reports."
218+
)
219+
220+
parser.add_argument(
221+
"-j", "--nproc", type=int, default=4,
222+
help="Number of parallel threads to run (default: 4)"
223+
)
224+
parser.add_argument(
225+
"-t", "--tests", type=lambda s: s.split(","),
226+
help="Comma-separated list of tests to run (default: all)"
227+
)
228+
parser.add_argument(
229+
"-d", "--dump", action="store_true",
230+
help="Print the list of available tests and exit"
231+
)
232+
parser.add_argument(
233+
"--noRun", action="store_true",
234+
help="Do not run tests (useful with --dump)"
235+
)
236+
parser.add_argument(
237+
"--uploadDir", metavar="DIR",
238+
help="Copy logs and reports to the given directory"
239+
)
240+
241+
args = parser.parse_args(argv)
242+
243+
tester = StandardTester(args.nproc)
244+
245+
if args.dump:
237246
tester.dumpTest()
238247
else:
239-
if runTests:
240-
tester.runTests(testList)
241-
if uploadDir:
242-
tester.upload(uploadDir)
243-
return
244-
245-
if __name__ == '__main__' :
246-
main(sys.argv[1:])
248+
tester.runTests(args.tests,args.noRun)
249+
if args.uploadDir:
250+
tester.upload(args.uploadDir)
251+
252+
if __name__ == '__main__':
253+
main()

0 commit comments

Comments
 (0)