Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit e259b79

Browse files
Make Python scripts portable across Python 2/3
Mostly: - harmonize print function - harmonize item iteration - explicitly force list creation when needed Differential Revision: https://reviews.llvm.org/D55829 git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@350382 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b7deeca commit e259b79

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

CompareDebugInfo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
from __future__ import print_function
23

34
import os
45
import sys
@@ -45,14 +46,14 @@ def recordArgument(self, arg_name, value):
4546
self.values[arg_name] = value
4647

4748
def __repr__(self):
48-
print self.name
49+
print(self.name)
4950
for k, v in self.values.items():
50-
print k, "=", v
51+
print(k, "=", v)
5152
return ''
5253

5354
def compare_args(self, other, file):
5455
myitems = self.values.items()
55-
otheritems = other.values.items()
56+
otheritems = list(other.values.items())
5657
match = False
5758
for i, my_item in enumerate(my_items):
5859
if i >= len(otheritems):

litsupport/modules/stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _mergeStats(global_stats, statsfilename):
1414
except Exception as e:
1515
logging.warning("Could not read '%s'", statsfilename, exc_info=e)
1616
return
17-
for name, value in stats.iteritems():
17+
for name, value in stats.items():
1818
global_stats[name] += value
1919

2020

@@ -37,7 +37,7 @@ def _getStats(context):
3737
logging.warning("No stats for '%s'", context.test.getFullName())
3838

3939
result = dict()
40-
for key, value in stats.iteritems():
40+
for key, value in stats.items():
4141
result[key] = value
4242
return result
4343

utils/compare.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#!/usr/bin/env python2.7
1+
#!/usr/bin/env python
22
"""Tool to filter, organize, compare and display benchmarking results. Usefull
33
for smaller datasets. It works great with a few dozen runs it is not designed to
44
deal with hundreds.
55
Requires the pandas library to be installed."""
6+
from __future__ import print_function
7+
68
import pandas as pd
79
import sys
810
import os.path
@@ -19,7 +21,7 @@ def read_lit_json(filename):
1921
info_columns = ['hash']
2022
# Pass1: Figure out metrics (= the column index)
2123
if 'tests' not in jsondata:
22-
print "%s: Could not find toplevel 'tests' key"
24+
print("%s: Could not find toplevel 'tests' key")
2325
sys.exit(1)
2426
for test in jsondata['tests']:
2527
name = test.get("name")
@@ -31,7 +33,7 @@ def read_lit_json(filename):
3133
sys.exit(1)
3234
names.add(name)
3335
if "metrics" not in test:
34-
print "Warning: '%s' has No metrics!" % test['name']
36+
print("Warning: '%s' has No metrics!" % test['name'])
3537
continue
3638
for name in test["metrics"].keys():
3739
if name not in columnindexes:
@@ -54,9 +56,9 @@ def read_lit_json(filename):
5456

5557
datarow = [nan] * len(columns)
5658
if "metrics" in test:
57-
for (metricname, value) in test['metrics'].iteritems():
59+
for (metricname, value) in test['metrics'].items():
5860
datarow[columnindexes[metricname]] = value
59-
for (name, value) in test.iteritems():
61+
for (name, value) in test.items():
6062
index = columnindexes.get(name)
6163
if index is not None:
6264
datarow[index] = test[name]
@@ -148,7 +150,7 @@ def print_filter_stats(reason, before, after):
148150
n_after = len(after.groupby(level=1))
149151
n_filtered = n_before - n_after
150152
if n_filtered != 0:
151-
print "%s: %s (filtered out)" % (reason, n_filtered)
153+
print("%s: %s (filtered out)" % (reason, n_filtered))
152154

153155
# Truncate a string to a maximum length by keeping a prefix, a suffix and ...
154156
# in the middle
@@ -222,8 +224,8 @@ def format_name(name, common_prefix, common_suffix):
222224
pd.set_option("display.max_colwidth", 0)
223225
out = dataout.to_string(index=False, justify='left',
224226
float_format=float_format, formatters=formatters)
225-
print out
226-
print d.describe()
227+
print(out)
228+
print(d.describe())
227229

228230
if __name__ == "__main__":
229231
parser = argparse.ArgumentParser(prog='compare.py')
@@ -303,7 +305,7 @@ def format_name(name, common_prefix, common_suffix):
303305
# Filter data
304306
proggroup = data.groupby(level=1)
305307
initial_size = len(proggroup.indices)
306-
print "Tests: %s" % (initial_size,)
308+
print("Tests: %s" % (initial_size,))
307309
if config.filter_failed and hasattr(data, 'Exec'):
308310
newdata = filter_failed(data)
309311
print_filter_stats("Failed", data, newdata)
@@ -326,10 +328,10 @@ def format_name(name, common_prefix, common_suffix):
326328
data = newdata
327329
final_size = len(data.groupby(level=1))
328330
if final_size != initial_size:
329-
print "Remaining: %d" % (final_size,)
331+
print("Remaining: %d" % (final_size,))
330332

331333
# Reduce / add columns
332-
print "Metric: %s" % (",".join(metrics),)
334+
print("Metric: %s" % (",".join(metrics),))
333335
if len(metrics) > 0:
334336
data = data[metrics]
335337
data = add_diff_column(data)
@@ -339,7 +341,7 @@ def format_name(name, common_prefix, common_suffix):
339341
sortkey = data.columns[0]
340342

341343
# Print data
342-
print ""
344+
print("")
343345
shorten_names = not config.full
344346
limit_output = (not config.all) and (not config.full)
345347
print_result(data, limit_output, shorten_names, config.show_diff, sortkey)

utils/tdiff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def determine_max_commandline_len():
9595
if sc_arg_max <= 0:
9696
return 10000 # wild guess
9797
env_len = 0
98-
for key,val in os.environ.iteritems():
98+
for key,val in os.environ.items():
9999
env_len += len(key) + len(val) + 10
100100
return sc_arg_max - env_len
101101

@@ -140,12 +140,12 @@ def filelist(mode, target, cwd, config):
140140

141141
if config.mode == 'sources':
142142
# Take leafs in the dependency tree
143-
for target, depnode in tree.iteritems():
143+
for target, depnode in tree.items():
144144
if len(depnode.inputs) == 0:
145145
yield target
146146
else:
147147
# Take files ending in '.o'
148-
for target, depnode in tree.iteritems():
148+
for target, depnode in tree.items():
149149
if target.endswith(".o"):
150150
# Determine .s/.stats ending used by -save-temps=obj or
151151
# -save-stats=obj

0 commit comments

Comments
 (0)