Fix tidiness errors for Python3 compatibility across whole repo

This commit is contained in:
marmeladema 2019-12-10 23:56:12 +00:00
parent 9d04f231f4
commit 7b5fabe855
10 changed files with 51 additions and 41 deletions

View file

@ -3943,8 +3943,8 @@ class CGMemberJITInfo(CGThing):
depth=self.descriptor.interface.inheritanceDepth(), depth=self.descriptor.interface.inheritanceDepth(),
opType=opType, opType=opType,
aliasSet=aliasSet, aliasSet=aliasSet,
returnType=reduce(CGMemberJITInfo.getSingleReturnType, returnTypes, returnType=functools.reduce(CGMemberJITInfo.getSingleReturnType, returnTypes,
""), ""),
isInfallible=toStringBool(infallible), isInfallible=toStringBool(infallible),
isMovable=toStringBool(movable), isMovable=toStringBool(movable),
# FIXME(nox): https://github.com/servo/servo/issues/10991 # FIXME(nox): https://github.com/servo/servo/issues/10991
@ -4131,8 +4131,8 @@ class CGMemberJITInfo(CGThing):
if u.hasNullableType: if u.hasNullableType:
# Might be null or not # Might be null or not
return "JSVAL_TYPE_UNKNOWN" return "JSVAL_TYPE_UNKNOWN"
return reduce(CGMemberJITInfo.getSingleReturnType, return functools.reduce(CGMemberJITInfo.getSingleReturnType,
u.flatMemberTypes, "") u.flatMemberTypes, "")
if t.isDictionary(): if t.isDictionary():
return "JSVAL_TYPE_OBJECT" return "JSVAL_TYPE_OBJECT"
if t.isDate(): if t.isDate():
@ -4202,8 +4202,8 @@ class CGMemberJITInfo(CGThing):
if t.isUnion(): if t.isUnion():
u = t.unroll() u = t.unroll()
type = "JSJitInfo::Null as i32" if u.hasNullableType else "" type = "JSJitInfo::Null as i32" if u.hasNullableType else ""
return reduce(CGMemberJITInfo.getSingleArgType, return functools.reduce(CGMemberJITInfo.getSingleArgType,
u.flatMemberTypes, type) u.flatMemberTypes, type)
if t.isDictionary(): if t.isDictionary():
return "JSJitInfo_ArgType::Object as i32" return "JSJitInfo_ArgType::Object as i32"
if t.isDate(): if t.isDate():
@ -5858,7 +5858,7 @@ class CGInterfaceTrait(CGThing):
def contains_unsafe_arg(arguments): def contains_unsafe_arg(arguments):
if not arguments or len(arguments) == 0: if not arguments or len(arguments) == 0:
return False return False
return reduce((lambda x, y: x or y[1] == '*mut JSContext'), arguments, False) return functools.reduce((lambda x, y: x or y[1] == '*mut JSContext'), arguments, False)
methods = [] methods = []
for name, arguments, rettype in members(): for name, arguments, rettype in members():

View file

@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
import functools
import os import os
from WebIDL import IDLExternalInterface, IDLSequenceType, IDLWrapperType, WebIDLError from WebIDL import IDLExternalInterface, IDLSequenceType, IDLWrapperType, WebIDLError
@ -15,7 +16,7 @@ class Configuration:
def __init__(self, filename, parseData): def __init__(self, filename, parseData):
# Read the configuration file. # Read the configuration file.
glbl = {} glbl = {}
execfile(filename, glbl) exec(compile(open(filename).read(), filename, 'exec'), glbl)
config = glbl['DOMInterfaces'] config = glbl['DOMInterfaces']
# Build descriptors for all the interfaces we have in the parse data. # Build descriptors for all the interfaces we have in the parse data.
@ -62,7 +63,8 @@ class Configuration:
c.isCallback() and not c.isInterface()] c.isCallback() and not c.isInterface()]
# Keep the descriptor list sorted for determinism. # Keep the descriptor list sorted for determinism.
self.descriptors.sort(lambda x, y: cmp(x.name, y.name)) cmp = lambda x, y: (x > y) - (x < y)
self.descriptors.sort(key=functools.cmp_to_key(lambda x, y: cmp(x.name, y.name)))
def getInterface(self, ifname): def getInterface(self, ifname):
return self.interfaces[ifname] return self.interfaces[ifname]

View file

@ -54,9 +54,9 @@ for key in keys:
value1 = data1.get(key) value1 = data1.get(key)
value2 = data2.get(key) value2 = data2.get(key)
if value1 and not(value2): if value1 and not(value2):
print ("{}Test {}: missing from {}.{}".format(WARNING, key, args.file2, END)) print("{}Test {}: missing from {}.{}".format(WARNING, key, args.file2, END))
elif value2 and not(value1): elif value2 and not(value1):
print ("{}Test {}: missing from {}.{}".format(WARNING, key, args.file1, END)) print("{}Test {}: missing from {}.{}".format(WARNING, key, args.file1, END))
elif value1 and value2: elif value1 and value2:
total1 += value1 total1 += value1
total2 += value2 total2 += value2

View file

@ -69,7 +69,7 @@ def transform_report_for_test(report):
while remaining: while remaining:
(name, value) = remaining.pop() (name, value) = remaining.pop()
transformed[name] = '%s %s' % (value['amount'], value['unit']) transformed[name] = '%s %s' % (value['amount'], value['unit'])
remaining += map(lambda (k, v): (name + '/' + k, v), list(value['children'].items())) remaining += map(lambda k_v: (name + '/' + k_v[0], k_v[1]), list(value['children'].items()))
return transformed return transformed

View file

@ -635,7 +635,7 @@ class MachCommands(CommandBase):
opts = ["-Ztimings=info"] + opts opts = ["-Ztimings=info"] + opts
if very_verbose: if very_verbose:
print (["Calling", "cargo", "build"] + opts) print(["Calling", "cargo", "build"] + opts)
for key in env: for key in env:
print((key, env[key])) print((key, env[key]))

View file

@ -627,7 +627,7 @@ install them, let us know by filing a bug!")
def build_env(self, hosts_file_path=None, target=None, is_build=False, test_unit=False, uwp=False, features=None): def build_env(self, hosts_file_path=None, target=None, is_build=False, test_unit=False, uwp=False, features=None):
"""Return an extended environment dictionary.""" """Return an extended environment dictionary."""
env = os.environ.copy() env = os.environ.copy()
if sys.platform == "win32" and type(env['PATH']) == unicode: if sys.platform == "win32" and type(env['PATH']) == six.text_type:
# On win32, the virtualenv's activate_this.py script sometimes ends up # On win32, the virtualenv's activate_this.py script sometimes ends up
# turning os.environ['PATH'] into a unicode string. This doesn't work # turning os.environ['PATH'] into a unicode string. This doesn't work
# for passing env vars in to a process, so we force it back to ascii. # for passing env vars in to a process, so we force it back to ascii.

View file

@ -700,20 +700,20 @@ class MachCommands(CommandBase):
width_col4 = max([len(str(x)) for x in result['Difference(%)']]) width_col4 = max([len(str(x)) for x in result['Difference(%)']])
for p, q, r, s in zip(['Test'], ['First Run'], ['Second Run'], ['Difference(%)']): for p, q, r, s in zip(['Test'], ['First Run'], ['Second Run'], ['Difference(%)']):
print ("\033[1m" + "{}|{}|{}|{}".format(p.ljust(width_col1), q.ljust(width_col2), r.ljust(width_col3), print("\033[1m" + "{}|{}|{}|{}".format(p.ljust(width_col1), q.ljust(width_col2), r.ljust(width_col3),
s.ljust(width_col4)) + "\033[0m" + "\n" + "--------------------------------------------------" s.ljust(width_col4)) + "\033[0m" + "\n" + "--------------------------------------------------"
+ "-------------------------------------------------------------------------") + "-------------------------------------------------------------------------")
for a1, b1, c1, d1 in zip(result['Test'], result['Prev_Time'], result['Cur_Time'], result['Difference(%)']): for a1, b1, c1, d1 in zip(result['Test'], result['Prev_Time'], result['Cur_Time'], result['Difference(%)']):
if d1 > 0: if d1 > 0:
print ("\033[91m" + "{}|{}|{}|{}".format(a1.ljust(width_col1), print("\033[91m" + "{}|{}|{}|{}".format(a1.ljust(width_col1),
str(b1).ljust(width_col2), str(c1).ljust(width_col3), str(d1).ljust(width_col4)) + "\033[0m") str(b1).ljust(width_col2), str(c1).ljust(width_col3), str(d1).ljust(width_col4)) + "\033[0m")
elif d1 < 0: elif d1 < 0:
print ("\033[92m" + "{}|{}|{}|{}".format(a1.ljust(width_col1), print("\033[92m" + "{}|{}|{}|{}".format(a1.ljust(width_col1),
str(b1).ljust(width_col2), str(c1).ljust(width_col3), str(d1).ljust(width_col4)) + "\033[0m") str(b1).ljust(width_col2), str(c1).ljust(width_col3), str(d1).ljust(width_col4)) + "\033[0m")
else: else:
print ("{}|{}|{}|{}".format(a1.ljust(width_col1), str(b1).ljust(width_col2), print("{}|{}|{}|{}".format(a1.ljust(width_col1), str(b1).ljust(width_col2),
str(c1).ljust(width_col3), str(d1).ljust(width_col4))) str(c1).ljust(width_col3), str(d1).ljust(width_col4)))
def jquery_test_runner(self, cmd, release, dev): def jquery_test_runner(self, cmd, release, dev):
self.ensure_bootstrapped() self.ensure_bootstrapped()

View file

@ -4,6 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import print_function
import sys import sys
import os import os
from os import path from os import path
@ -12,6 +14,7 @@ import datetime
import argparse import argparse
import platform import platform
import subprocess import subprocess
import six
TOP_DIR = path.join("..", "..") TOP_DIR = path.join("..", "..")
GUARD_TIME = 10 GUARD_TIME = 10
@ -133,7 +136,7 @@ def execute(base_dir, build_target, renderer, page, profile, trial, layout_threa
log_dir = path.join(base_dir, "logs_l" + str(layout_thread_count), log_dir = path.join(base_dir, "logs_l" + str(layout_thread_count),
"trial_" + str(trial)) "trial_" + str(trial))
if os.path.exists(log_dir): if os.path.exists(log_dir):
print "Log directory already exists: " + log_dir print("Log directory already exists: " + log_dir)
sys.exit(1) sys.exit(1)
os.makedirs(log_dir) os.makedirs(log_dir)
@ -142,16 +145,16 @@ def execute(base_dir, build_target, renderer, page, profile, trial, layout_threa
# Execute # Execute
start_energy_reader() start_energy_reader()
print 'sleep ' + str(GUARD_TIME) print('sleep ' + str(GUARD_TIME))
time.sleep(GUARD_TIME) time.sleep(GUARD_TIME)
time_start = time.time() time_start = time.time()
energy_start = read_energy() energy_start = read_energy()
print cmd print(cmd)
os.system(cmd) os.system(cmd)
energy_end = read_energy() energy_end = read_energy()
time_end = time.time() time_end = time.time()
stop_energy_reader() stop_energy_reader()
print 'sleep ' + str(GUARD_TIME) print('sleep ' + str(GUARD_TIME))
time.sleep(GUARD_TIME) time.sleep(GUARD_TIME)
uj = energy_end - energy_start uj = energy_end - energy_start
@ -172,11 +175,11 @@ def execute(base_dir, build_target, renderer, page, profile, trial, layout_threa
f.write("\nPower (W): " + str(watts)) f.write("\nPower (W): " + str(watts))
def characterize(build_target, base_dir, (min_layout_threads, max_layout_threads), renderer, page, profile, trials): def characterize(build_target, base_dir, layout_threads_limits, renderer, page, profile, trials):
"""Run all configurations and capture results. """Run all configurations and capture results.
""" """
for layout_thread_count in xrange(min_layout_threads, max_layout_threads + 1): for layout_thread_count in six.moves.xrange(layout_threads_limits[0], layout_threads_limits[1] + 1):
for trial in xrange(1, trials + 1): for trial in six.moves.xrange(1, trials + 1):
execute(base_dir, build_target, renderer, page, profile, trial, layout_thread_count) execute(base_dir, build_target, renderer, page, profile, trial, layout_thread_count)
@ -250,7 +253,7 @@ def main():
trials = args.trials trials = args.trials
if os.path.exists(output_dir): if os.path.exists(output_dir):
print "Output directory already exists: " + output_dir print("Output directory already exists: " + output_dir)
sys.exit(1) sys.exit(1)
os.makedirs(output_dir) os.makedirs(output_dir)

View file

@ -4,6 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import print_function
import sys import sys
import os import os
from os import path from os import path
@ -43,15 +45,15 @@ def execute(base_dir, renderer, page, profile, trial, layout_thread_count):
log_dir = path.join(base_dir, "logs_l" + str(layout_thread_count), log_dir = path.join(base_dir, "logs_l" + str(layout_thread_count),
"trial_" + str(trial)) "trial_" + str(trial))
if os.path.exists(log_dir): if os.path.exists(log_dir):
print "Log directory already exists: " + log_dir print("Log directory already exists: " + log_dir)
sys.exit(1) sys.exit(1)
os.makedirs(log_dir) os.makedirs(log_dir)
# Execute # Execute
cmd = get_command(layout_thread_count, renderer, page, profile) cmd = get_command(layout_thread_count, renderer, page, profile)
print cmd print(cmd)
os.system(cmd) os.system(cmd)
print 'sleep ' + str(GUARD_TIME) print('sleep ' + str(GUARD_TIME))
time.sleep(GUARD_TIME) time.sleep(GUARD_TIME)
# Write a file that describes this execution # Write a file that describes this execution
@ -109,7 +111,7 @@ def main():
profile = args.profile profile = args.profile
if os.path.exists(output_dir): if os.path.exists(output_dir):
print "Output directory already exists: " + output_dir print("Output directory already exists: " + output_dir)
sys.exit(1) sys.exit(1)
os.makedirs(output_dir) os.makedirs(output_dir)

View file

@ -4,11 +4,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import print_function
import argparse import argparse
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import os import os
from os import path from os import path
import six
import sys import sys
import warnings import warnings
@ -196,7 +199,7 @@ def plot_trial_time_series(config, trial, trial_data, max_end_time, max_power, o
i = 10 i = 10
for (p, ts, te, es, ee) in trial_data: for (p, ts, te, es, ee) in trial_data:
xranges = [(ts[j] / 1000000.0, (te[j] - ts[j]) / 1000000.0) for j in xrange(len(ts))] xranges = [(ts[j] / 1000000.0, (te[j] - ts[j]) / 1000000.0) for j in six.moves.xrange(len(ts))]
ax1.broken_barh(xranges, (i - 0.5 * width, width)) ax1.broken_barh(xranges, (i - 0.5 * width, width))
i += 10 i += 10
# place a vbar at the final time for this trial # place a vbar at the final time for this trial
@ -385,20 +388,20 @@ def main():
android = args.android android = args.android
if not os.path.exists(directory): if not os.path.exists(directory):
print "Input directory does not exist: " + directory print("Input directory does not exist: " + directory)
sys.exit(1) sys.exit(1)
if os.path.exists(output_dir): if os.path.exists(output_dir):
print "Output directory already exists: " + output_dir print("Output directory already exists: " + output_dir)
sys.exit(1) sys.exit(1)
res = process_logs(directory) res = process_logs(directory)
if not android: if not android:
best = find_best_executions(directory) best = find_best_executions(directory)
print 'Best time:', best[0] print('Best time:', best[0])
print 'Best energy:', best[1] print('Best energy:', best[1])
print 'Best power:', best[2] print('Best power:', best[2])
os.makedirs(output_dir) os.makedirs(output_dir)
plot_all_raw_totals(res, output_dir) plot_all_raw_totals(res, output_dir)