[LNT] r372816 - [LNT] Python 3 support: adapt to dict method returning views
Thomas Preud'homme via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 00:33:29 PDT 2019
Author: thopre
Date: Wed Sep 25 00:33:29 2019
New Revision: 372816
URL: http://llvm.org/viewvc/llvm-project?rev=372816&view=rev
Log:
[LNT] Python 3 support: adapt to dict method returning views
Adapt calls to dictionary's keys(), items() and values() to them
returning a view in Python 3 when necessary, undoing unneeded changes
in lnt/testing/__init__.py. Also replace calls to their iter relatives
to use iter() instead and calls to the their views relatives to use the
plains .keys(), .items() and .values(). This was produced by running
futurize's stage2 lib2to3.fixes.fix_dict with manual intervention to
clean up code and remove unnecessary list() wrapping.
Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls
Reviewed By: hubert.reinterpretcast
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D67814
Modified:
lnt/trunk/examples/run_to_csv.py
lnt/trunk/lnt/server/config.py
lnt/trunk/lnt/server/reporting/summaryreport.py
lnt/trunk/lnt/server/ui/regression_views.py
lnt/trunk/lnt/server/ui/views.py
lnt/trunk/lnt/testing/__init__.py
lnt/trunk/lnt/testing/profile/profilev2impl.py
lnt/trunk/lnt/tests/nt.py
lnt/trunk/tests/server/ui/V4Pages.py
lnt/trunk/tests/server/ui/test_roundtrip.py
Modified: lnt/trunk/examples/run_to_csv.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/examples/run_to_csv.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/examples/run_to_csv.py (original)
+++ lnt/trunk/examples/run_to_csv.py Wed Sep 25 00:33:29 2019
@@ -7,7 +7,7 @@ import sys
data = json.load(sys.stdin)
-titles = data['tests'].itervalues().next().keys()
+titles = list(next(iter(data['tests'].values())).keys())
titles.insert(0, titles.pop(titles.index("name")))
print(", ".join(titles))
Modified: lnt/trunk/lnt/server/config.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/config.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/server/config.py (original)
+++ lnt/trunk/lnt/server/config.py Wed Sep 25 00:33:29 2019
@@ -191,4 +191,4 @@ class Config:
db_entry.baseline_revision)
def get_database_names(self):
- return self.databases.keys()
+ return list(self.databases.keys())
Modified: lnt/trunk/lnt/server/reporting/summaryreport.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/reporting/summaryreport.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/server/reporting/summaryreport.py (original)
+++ lnt/trunk/lnt/server/reporting/summaryreport.py Wed Sep 25 00:33:29 2019
@@ -342,7 +342,7 @@ class SummaryReport(object):
columns = [ts.Sample.run_id, ts.Sample.test_id]
columns.extend(f.column for f in ts.sample_fields)
samples = session.query(*columns).filter(
- ts.Sample.run_id.in_(run_id_map.keys()))
+ ts.Sample.run_id.in_(list(run_id_map.keys())))
for sample in samples:
run = run_id_map[sample[0]]
datapoints = list()
Modified: lnt/trunk/lnt/server/ui/regression_views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/regression_views.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/regression_views.py (original)
+++ lnt/trunk/lnt/server/ui/regression_views.py Wed Sep 25 00:33:29 2019
@@ -256,7 +256,7 @@ class EditRegressionForm(Form):
title = StringField(u'Title', validators=[DataRequired()])
bug = StringField(u'Bug', validators=[DataRequired()])
field_changes = MultiCheckboxField("Changes", coerce=int)
- choices = RegressionState.names.items()
+ choices = list(RegressionState.names.items())
state = SelectField(u'State', choices=choices)
edit_state = HiddenField(u'EditState', validators=[DataRequired()])
Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Wed Sep 25 00:33:29 2019
@@ -951,8 +951,9 @@ def v4_graph():
(field.status_field.column.is_(None)))
# Aggregate by revision.
- data = multidict.multidict((rev, (val, date, run_id))
- for val, rev, date, run_id in q).items()
+ data = list(multidict.multidict((rev, (val, date, run_id))
+ for val, rev, date, run_id in q)
+ .items())
data.sort(key=lambda sample: convert_revision(sample[0], cache=revision_cache))
Modified: lnt/trunk/lnt/testing/__init__.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/__init__.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/__init__.py (original)
+++ lnt/trunk/lnt/testing/__init__.py Wed Sep 25 00:33:29 2019
@@ -257,7 +257,7 @@ class Test:
self.samples = samples
self.info = dict()
# Convert keys/values that are not json encodable to strings.
- for key, value in list(info.items()):
+ for key, value in info.items():
key = str(key)
value = str(value)
self.info[key] = value
Modified: lnt/trunk/lnt/testing/profile/profilev2impl.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/profile/profilev2impl.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/profile/profilev2impl.py (original)
+++ lnt/trunk/lnt/testing/profile/profilev2impl.py Wed Sep 25 00:33:29 2019
@@ -266,9 +266,9 @@ class CounterNamePool(Section):
def upgrade(self, impl):
self.idx_to_name = {}
- keys = impl.getTopLevelCounters().keys()
+ keys = list(impl.getTopLevelCounters().keys())
for f in impl.getFunctions().values():
- keys += f['counters'].keys()
+ keys.extend(f['counters'].keys())
keys = sorted(set(keys))
self.idx_to_name = {k: v for k, v in enumerate(keys)}
@@ -313,9 +313,9 @@ class LineCounters(CompressedSection):
start = fobj.tell()
for fname, f in sorted(self.impl.getFunctions().items()):
self.function_offsets[fname] = fobj.tell() - start
- all_counters = f['counters'].keys()
+ all_counters = sorted(f['counters'].keys())
for counters, address, text in self.impl.getCodeForFunction(fname):
- for k in sorted(all_counters):
+ for k in all_counters:
writeFloat(fobj, counters.get(k, 0))
def deserialize(self, fobj):
@@ -537,7 +537,7 @@ class Functions(Section):
def getCodeForFunction(self, fname):
f = self.functions[fname]
counter_gen = self.line_counters \
- .extractForFunction(fname, f['counters'].keys())
+ .extractForFunction(fname, list(f['counters'].keys()))
address_gen = self.line_addresses.extractForFunction(fname)
text_gen = self.line_text.extractForFunction(fname)
for n in xrange(f['length']):
Modified: lnt/trunk/lnt/tests/nt.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/nt.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/nt.py (original)
+++ lnt/trunk/lnt/tests/nt.py Wed Sep 25 00:33:29 2019
@@ -1479,14 +1479,14 @@ def _process_reruns(config, server_reply
for test in collated_results.values():
test.check()
- rerunable_benches = [x for x in collated_results.values()
- if x.is_rerunable()]
+ rerunable_benches = list(filter(lambda bench: bench.is_rerunable(),
+ collated_results.values()))
rerunable_benches.sort(key=lambda x: x.name)
# Now lets do the reruns.
rerun_results = []
summary = "Rerunning {} of {} benchmarks."
logger.info(summary.format(len(rerunable_benches),
- len(collated_results.values())))
+ len(collated_results)))
for i, bench in enumerate(rerunable_benches):
logger.info("Rerunning: {} [{}/{}]".format(bench.name,
Modified: lnt/trunk/tests/server/ui/V4Pages.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/V4Pages.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/V4Pages.py (original)
+++ lnt/trunk/tests/server/ui/V4Pages.py Wed Sep 25 00:33:29 2019
@@ -111,7 +111,7 @@ def get_xml_tree(html_string):
try:
parser = ET.XMLParser()
parser.parser.UseForeignDTD(True)
- parser.entity.update((x, unichr(i)) for x, i in name2codepoint.iteritems())
+ parser.entity.update((x, unichr(i)) for x, i in name2codepoint.items())
tree = ET.fromstring(html_string, parser=parser)
except: # noqa FIXME: figure out what we expect this to throw.
dump_html(html_string)
Modified: lnt/trunk/tests/server/ui/test_roundtrip.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_roundtrip.py?rev=372816&r1=372815&r2=372816&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_roundtrip.py (original)
+++ lnt/trunk/tests/server/ui/test_roundtrip.py Wed Sep 25 00:33:29 2019
@@ -89,7 +89,7 @@ class JSONAPIRoundTripTester(unittest.Te
before_submit_run['run']['order_id'] = an_id
after_submit_run['run']['order_id'] = an_id
- self.assertEqual(before_submit_run.keys(), after_submit_run.keys())
+ self.assertEqual(list(before_submit_run.keys()), list(after_submit_run.keys()))
# Machine and run will be dicts, compare them directly.
for k in ['machine', 'run']:
self.assertEqual(before_submit_run[k], after_submit_run[k])
More information about the llvm-commits
mailing list