diff --git a/.flake8 b/.flake8 index 859c4d3575daaa..eee7c33b89d262 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,3 @@ [flake8] -exclude=.git,deps,lib,src,test/fixtures,tools/*_macros.py,tools/gyp,tools/inspector_protocol,tools/jinja2,tools/markupsafe,tools/pip,tools/v8_gypfiles/broken -select=E901,E999,F821,F822,F823 +exclude=.git,deps,lib,src,tools/gyp,tools/inspector_protocol,tools/pip,tools/v8_gypfiles/broken +ignore=E1,E2,E3,E4,E5,E7,W5,W6 diff --git a/configure.py b/configure.py index d78a1caf64a1d2..f32e82e6f201c3 100755 --- a/configure.py +++ b/configure.py @@ -1110,7 +1110,7 @@ def configure_library(lib, output): output['libraries'] += [pkg_libpath] default_libs = getattr(options, shared_lib + '_libname') - default_libs = ['-l{0}'.format(lib) for lib in default_libs.split(',')] + default_libs = ['-l{0}'.format(l) for l in default_libs.split(',')] if default_libs: output['libraries'] += default_libs diff --git a/node.gyp b/node.gyp index f23fd42908d250..6e792c907b07cf 100644 --- a/node.gyp +++ b/node.gyp @@ -805,20 +805,20 @@ 'inputs': [ '<@(library_files)', 'config.gypi', - 'tools/check_macros.py' + 'tools/js2c_macros/check_macros.py' ], 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc', ], 'conditions': [ [ 'node_use_dtrace=="false" and node_use_etw=="false"', { - 'inputs': [ 'src/notrace_macros.py' ] + 'inputs': [ 'tools/js2c_macros/notrace_macros.py' ] }], [ 'node_debug_lib=="false"', { - 'inputs': [ 'tools/nodcheck_macros.py' ] + 'inputs': [ 'tools/js2c_macros/nodcheck_macros.py' ] }], [ 'node_debug_lib=="true"', { - 'inputs': [ 'tools/dcheck_macros.py' ] + 'inputs': [ 'tools/js2c_macros/dcheck_macros.py' ] }] ], 'action': [ diff --git a/src/inspector/node_inspector.gypi b/src/inspector/node_inspector.gypi index 2eabd9dd3105fa..6ec85461dda0d7 100644 --- a/src/inspector/node_inspector.gypi +++ b/src/inspector/node_inspector.gypi @@ -97,7 +97,7 @@ 'action': [ 'python', 'tools/inspector_protocol/code_generator.py', - '--jinja_dir', '<@(protocol_tool_path)/..', + '--jinja_dir', '<@(protocol_tool_path)', '--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/', '--config', 'src/inspector/node_protocol_config.json', ], diff --git a/test/fixtures/wpt/.gitignore b/test/fixtures/wpt/.gitignore new file mode 100644 index 00000000000000..f104652b68f212 --- /dev/null +++ b/test/fixtures/wpt/.gitignore @@ -0,0 +1 @@ +*.py diff --git a/test/fixtures/wpt/encoding/resources/single-byte-raw.py b/test/fixtures/wpt/encoding/resources/single-byte-raw.py deleted file mode 100644 index b4a6c90405ec85..00000000000000 --- a/test/fixtures/wpt/encoding/resources/single-byte-raw.py +++ /dev/null @@ -1,3 +0,0 @@ -def main(request, response): - response.headers.set("Content-Type", "text/plain;charset=" + request.GET.first("label")) - response.content = "".join(chr(byte) for byte in xrange(255)) diff --git a/test/fixtures/wpt/encoding/resources/text-plain-charset.py b/test/fixtures/wpt/encoding/resources/text-plain-charset.py deleted file mode 100644 index a1c07e70189bce..00000000000000 --- a/test/fixtures/wpt/encoding/resources/text-plain-charset.py +++ /dev/null @@ -1,3 +0,0 @@ -def main(request, response): - response.headers.set("Content-Type", "text/plain;charset=" + request.GET.first("label")) - response.content = "hello encoding" diff --git a/test/message/testcfg.py b/test/message/testcfg.py index a4f802f3efc584..bd56a8eba8c4ce 100644 --- a/test/message/testcfg.py +++ b/test/message/testcfg.py @@ -30,16 +30,7 @@ import os from os.path import join, exists, basename, isdir import re - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") @@ -82,13 +73,13 @@ def IsFailureOutput(self, output): print("expect=%d" % len(patterns)) print("actual=%d" % len(outlines)) print("patterns:") - for i in xrange(len(patterns)): + for i in range(len(patterns)): print("pattern = %s" % patterns[i]) print("outlines:") - for i in xrange(len(outlines)): + for i in range(len(outlines)): print("outline = %s" % outlines[i]) return True - for i in xrange(len(patterns)): + for i in range(len(patterns)): if not re.match(patterns[i], outlines[i]): print("match failed") print("line=%d" % i) @@ -129,13 +120,13 @@ def Ls(self, path): def ListTests(self, current_path, path, arch, mode): all_tests = [current_path + [t] for t in self.Ls(self.root)] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], '')) + for tst in all_tests: + if self.Contains(path, tst): + file_path = join(self.root, reduce(join, tst[1:], '')) output_path = file_path[:file_path.rfind('.')] + '.out' if not exists(output_path): raise Exception("Could not find %s" % output_path) - result.append(MessageTestCase(test, file_path, output_path, + result.append(MessageTestCase(tst, file_path, output_path, arch, mode, self.context, self)) return result diff --git a/test/pseudo-tty/testcfg.py b/test/pseudo-tty/testcfg.py index c12a16f8059e20..f2a7242e833dab 100644 --- a/test/pseudo-tty/testcfg.py +++ b/test/pseudo-tty/testcfg.py @@ -32,34 +32,25 @@ from os.path import join, exists, basename, isdir import re import utils - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") class TTYTestCase(test.TestCase): - def __init__(self, path, file, expected, input, arch, mode, context, config): + def __init__(self, path, file, expected, input_arg, arch, mode, context, config): super(TTYTestCase, self).__init__(context, path, arch, mode) self.file = file self.expected = expected - self.input = input + self.input = input_arg self.config = config self.arch = arch self.mode = mode - def IgnoreLine(self, str): + def IgnoreLine(self, str_arg): """Ignore empty lines and valgrind output.""" - if not str.strip(): return True - else: return str.startswith('==') or str.startswith('**') + if not str_arg.strip(): return True + else: return str_arg.startswith('==') or str_arg.startswith('**') def IsFailureOutput(self, output): f = open(self.expected) @@ -81,13 +72,13 @@ def IsFailureOutput(self, output): print("expect=%d" % len(patterns)) print("actual=%d" % len(outlines)) print("patterns:") - for i in xrange(len(patterns)): + for i in range(len(patterns)): print("pattern = %s" % patterns[i]) print("outlines:") - for i in xrange(len(outlines)): + for i in range(len(outlines)): print("outline = %s" % outlines[i]) return True - for i in xrange(len(patterns)): + for i in range(len(patterns)): if not re.match(patterns[i], outlines[i]): print("match failed") print("line=%d" % i) @@ -117,16 +108,16 @@ def GetSource(self): + open(self.expected).read()) def RunCommand(self, command, env): - input = None + input_arg = None if self.input is not None and exists(self.input): - input = open(self.input).read() + input_arg = open(self.input).read() full_command = self.context.processor(command) output = test.Execute(full_command, self.context, self.context.GetTimeout(self.mode), env, faketty=True, - input=input) + input=input_arg) return test.TestOutput(self, full_command, output, @@ -148,15 +139,15 @@ def ListTests(self, current_path, path, arch, mode): print ("Skipping pseudo-tty tests, as pseudo terminals are not available" " on Windows.") return result - for test in all_tests: - if self.Contains(path, test): - file_prefix = join(self.root, reduce(join, test[1:], "")) + for tst in all_tests: + if self.Contains(path, tst): + file_prefix = join(self.root, reduce(join, tst[1:], "")) file_path = file_prefix + ".js" input_path = file_prefix + ".in" output_path = file_prefix + ".out" if not exists(output_path): raise Exception("Could not find %s" % output_path) - result.append(TTYTestCase(test, file_path, output_path, + result.append(TTYTestCase(tst, file_path, output_path, input_path, arch, mode, self.context, self)) return result diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index 332284ce4cfb4e..9c70e18d6a1291 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -27,18 +27,12 @@ import test import os -from os.path import join, dirname, exists, splitext import re -import ast - -try: - reduce -except NameError: - from functools import reduce +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") - +LS_RE = re.compile(r'^test-.*\.m?js$') class SimpleTestCase(test.TestCase): @@ -107,15 +101,15 @@ def __init__(self, context, root, section, additional=None): self.additional_flags = [] def Ls(self, path): - return [f for f in os.listdir(path) if re.match('^test-.*\.m?js$', f)] + return [f for f in os.listdir(path) if LS_RE.match(f)] def ListTests(self, current_path, path, arch, mode): - all_tests = [current_path + [t] for t in self.Ls(join(self.root))] + all_tests = [current_path + [t] for t in self.Ls(os.path.join(self.root))] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], "")) - test_name = test[:-1] + [splitext(test[-1])[0]] + for tst in all_tests: + if self.Contains(path, tst): + file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "")) + test_name = tst[:-1] + [os.path.splitext(tst[-1])[0]] result.append(SimpleTestCase(test_name, file_path, arch, mode, self.context, self, self.additional_flags)) return result @@ -131,8 +125,8 @@ def __init__(self, context, root, section, additional=None): def ListTests(self, current_path, path, arch, mode): result = super(ParallelTestConfiguration, self).ListTests( current_path, path, arch, mode) - for test in result: - test.parallel = True + for tst in result: + tst.parallel = True return result class AddonTestConfiguration(SimpleTestConfiguration): @@ -145,20 +139,20 @@ def SelectTest(name): result = [] for subpath in os.listdir(path): - if os.path.isdir(join(path, subpath)): - for f in os.listdir(join(path, subpath)): + if os.path.isdir(os.path.join(path, subpath)): + for f in os.listdir(os.path.join(path, subpath)): if SelectTest(f): result.append([subpath, f[:-3]]) return result def ListTests(self, current_path, path, arch, mode): - all_tests = [current_path + t for t in self.Ls(join(self.root))] + all_tests = [current_path + t for t in self.Ls(os.path.join(self.root))] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], "") + ".js") + for tst in all_tests: + if self.Contains(path, tst): + file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "") + ".js") result.append( - SimpleTestCase(test, file_path, arch, mode, self.context, self, self.additional_flags)) + SimpleTestCase(tst, file_path, arch, mode, self.context, self, self.additional_flags)) return result class AbortTestConfiguration(SimpleTestConfiguration): @@ -169,6 +163,6 @@ def __init__(self, context, root, section, additional=None): def ListTests(self, current_path, path, arch, mode): result = super(AbortTestConfiguration, self).ListTests( current_path, path, arch, mode) - for test in result: - test.disable_core_files = True + for tst in result: + tst.disable_core_files = True return result diff --git a/tools/configure.d/nodedownload.py b/tools/configure.d/nodedownload.py index e3fe2c517cc1bb..8734770fc78fff 100644 --- a/tools/configure.d/nodedownload.py +++ b/tools/configure.d/nodedownload.py @@ -107,7 +107,7 @@ def parse(opt): if not anOpt or anOpt == "": # ignore stray commas, etc. continue - elif anOpt is 'all': + elif anOpt == 'all': # all on theRet = dict((key, True) for (key) in download_types) else: diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py index fb86ba1fa923dd..5a88fa6318d2fb 100644 --- a/tools/getmoduleversion.py +++ b/tools/getmoduleversion.py @@ -2,6 +2,7 @@ import os import re + def get_version(): node_version_h = os.path.join( os.path.dirname(__file__), @@ -17,8 +18,9 @@ def get_version(): if re.match(regex, line): major = line.split()[2] return major - + raise Exception('Could not find pattern matching %s' % regex) + if __name__ == '__main__': print(get_version()) diff --git a/tools/icu/icutrim.py b/tools/icu/icutrim.py index 116af32e0220a8..a825b18ac0c8c3 100755 --- a/tools/icu/icutrim.py +++ b/tools/icu/icutrim.py @@ -110,7 +110,7 @@ print("Unknown endianness: %s" % options.endian) sys.exit(1) -if options.endian is "host": +if options.endian == "host": options.endian = endian if not os.path.isdir(options.tmpdir): @@ -153,7 +153,7 @@ def runcmd(tool, cmd, doContinue=False): print("# " + cmd) rc = os.system(cmd) - if rc is not 0 and not doContinue: + if rc != 0 and not doContinue: print("FAILED: %s" % cmd) sys.exit(1) return rc @@ -320,7 +320,7 @@ def removeList(count=0): print(i, file=fi) fi.close() rc = runcmd("icupkg","-r %s %s 2> %s" % (removefile,outfile,hackerrfile),True) - if rc is not 0: + if rc != 0: if(options.verbose>5): print("## Damage control, trying to parse stderr from icupkg..") fi = open(hackerrfile, 'rb') diff --git a/tools/jinja2/AUTHORS b/tools/inspector_protocol/jinja2/AUTHORS similarity index 100% rename from tools/jinja2/AUTHORS rename to tools/inspector_protocol/jinja2/AUTHORS diff --git a/tools/jinja2/Jinja2-2.10.tar.gz.md5 b/tools/inspector_protocol/jinja2/Jinja2-2.10.tar.gz.md5 similarity index 100% rename from tools/jinja2/Jinja2-2.10.tar.gz.md5 rename to tools/inspector_protocol/jinja2/Jinja2-2.10.tar.gz.md5 diff --git a/tools/jinja2/Jinja2-2.10.tar.gz.sha512 b/tools/inspector_protocol/jinja2/Jinja2-2.10.tar.gz.sha512 similarity index 100% rename from tools/jinja2/Jinja2-2.10.tar.gz.sha512 rename to tools/inspector_protocol/jinja2/Jinja2-2.10.tar.gz.sha512 diff --git a/tools/jinja2/LICENSE b/tools/inspector_protocol/jinja2/LICENSE similarity index 100% rename from tools/jinja2/LICENSE rename to tools/inspector_protocol/jinja2/LICENSE diff --git a/tools/jinja2/OWNERS b/tools/inspector_protocol/jinja2/OWNERS similarity index 100% rename from tools/jinja2/OWNERS rename to tools/inspector_protocol/jinja2/OWNERS diff --git a/tools/jinja2/README.chromium b/tools/inspector_protocol/jinja2/README.chromium similarity index 100% rename from tools/jinja2/README.chromium rename to tools/inspector_protocol/jinja2/README.chromium diff --git a/tools/jinja2/__init__.py b/tools/inspector_protocol/jinja2/__init__.py similarity index 100% rename from tools/jinja2/__init__.py rename to tools/inspector_protocol/jinja2/__init__.py diff --git a/tools/jinja2/_compat.py b/tools/inspector_protocol/jinja2/_compat.py similarity index 100% rename from tools/jinja2/_compat.py rename to tools/inspector_protocol/jinja2/_compat.py diff --git a/tools/jinja2/_identifier.py b/tools/inspector_protocol/jinja2/_identifier.py similarity index 100% rename from tools/jinja2/_identifier.py rename to tools/inspector_protocol/jinja2/_identifier.py diff --git a/tools/jinja2/asyncfilters.py b/tools/inspector_protocol/jinja2/asyncfilters.py similarity index 100% rename from tools/jinja2/asyncfilters.py rename to tools/inspector_protocol/jinja2/asyncfilters.py diff --git a/tools/jinja2/asyncsupport.py b/tools/inspector_protocol/jinja2/asyncsupport.py similarity index 100% rename from tools/jinja2/asyncsupport.py rename to tools/inspector_protocol/jinja2/asyncsupport.py diff --git a/tools/jinja2/bccache.py b/tools/inspector_protocol/jinja2/bccache.py similarity index 100% rename from tools/jinja2/bccache.py rename to tools/inspector_protocol/jinja2/bccache.py diff --git a/tools/jinja2/compiler.py b/tools/inspector_protocol/jinja2/compiler.py similarity index 100% rename from tools/jinja2/compiler.py rename to tools/inspector_protocol/jinja2/compiler.py diff --git a/tools/jinja2/constants.py b/tools/inspector_protocol/jinja2/constants.py similarity index 100% rename from tools/jinja2/constants.py rename to tools/inspector_protocol/jinja2/constants.py diff --git a/tools/jinja2/debug.py b/tools/inspector_protocol/jinja2/debug.py similarity index 100% rename from tools/jinja2/debug.py rename to tools/inspector_protocol/jinja2/debug.py diff --git a/tools/jinja2/defaults.py b/tools/inspector_protocol/jinja2/defaults.py similarity index 100% rename from tools/jinja2/defaults.py rename to tools/inspector_protocol/jinja2/defaults.py diff --git a/tools/jinja2/environment.py b/tools/inspector_protocol/jinja2/environment.py similarity index 100% rename from tools/jinja2/environment.py rename to tools/inspector_protocol/jinja2/environment.py diff --git a/tools/jinja2/exceptions.py b/tools/inspector_protocol/jinja2/exceptions.py similarity index 100% rename from tools/jinja2/exceptions.py rename to tools/inspector_protocol/jinja2/exceptions.py diff --git a/tools/jinja2/ext.py b/tools/inspector_protocol/jinja2/ext.py similarity index 100% rename from tools/jinja2/ext.py rename to tools/inspector_protocol/jinja2/ext.py diff --git a/tools/jinja2/filters.py b/tools/inspector_protocol/jinja2/filters.py similarity index 100% rename from tools/jinja2/filters.py rename to tools/inspector_protocol/jinja2/filters.py diff --git a/tools/jinja2/get_jinja2.sh b/tools/inspector_protocol/jinja2/get_jinja2.sh similarity index 100% rename from tools/jinja2/get_jinja2.sh rename to tools/inspector_protocol/jinja2/get_jinja2.sh diff --git a/tools/jinja2/idtracking.py b/tools/inspector_protocol/jinja2/idtracking.py similarity index 100% rename from tools/jinja2/idtracking.py rename to tools/inspector_protocol/jinja2/idtracking.py diff --git a/tools/jinja2/jinja2.gni b/tools/inspector_protocol/jinja2/jinja2.gni similarity index 100% rename from tools/jinja2/jinja2.gni rename to tools/inspector_protocol/jinja2/jinja2.gni diff --git a/tools/jinja2/lexer.py b/tools/inspector_protocol/jinja2/lexer.py similarity index 100% rename from tools/jinja2/lexer.py rename to tools/inspector_protocol/jinja2/lexer.py diff --git a/tools/jinja2/loaders.py b/tools/inspector_protocol/jinja2/loaders.py similarity index 100% rename from tools/jinja2/loaders.py rename to tools/inspector_protocol/jinja2/loaders.py diff --git a/tools/jinja2/meta.py b/tools/inspector_protocol/jinja2/meta.py similarity index 100% rename from tools/jinja2/meta.py rename to tools/inspector_protocol/jinja2/meta.py diff --git a/tools/jinja2/nativetypes.py b/tools/inspector_protocol/jinja2/nativetypes.py similarity index 100% rename from tools/jinja2/nativetypes.py rename to tools/inspector_protocol/jinja2/nativetypes.py diff --git a/tools/jinja2/nodes.py b/tools/inspector_protocol/jinja2/nodes.py similarity index 100% rename from tools/jinja2/nodes.py rename to tools/inspector_protocol/jinja2/nodes.py diff --git a/tools/jinja2/optimizer.py b/tools/inspector_protocol/jinja2/optimizer.py similarity index 100% rename from tools/jinja2/optimizer.py rename to tools/inspector_protocol/jinja2/optimizer.py diff --git a/tools/jinja2/parser.py b/tools/inspector_protocol/jinja2/parser.py similarity index 100% rename from tools/jinja2/parser.py rename to tools/inspector_protocol/jinja2/parser.py diff --git a/tools/jinja2/runtime.py b/tools/inspector_protocol/jinja2/runtime.py similarity index 100% rename from tools/jinja2/runtime.py rename to tools/inspector_protocol/jinja2/runtime.py diff --git a/tools/jinja2/sandbox.py b/tools/inspector_protocol/jinja2/sandbox.py similarity index 100% rename from tools/jinja2/sandbox.py rename to tools/inspector_protocol/jinja2/sandbox.py diff --git a/tools/jinja2/tests.py b/tools/inspector_protocol/jinja2/tests.py similarity index 100% rename from tools/jinja2/tests.py rename to tools/inspector_protocol/jinja2/tests.py diff --git a/tools/jinja2/utils.py b/tools/inspector_protocol/jinja2/utils.py similarity index 100% rename from tools/jinja2/utils.py rename to tools/inspector_protocol/jinja2/utils.py diff --git a/tools/jinja2/visitor.py b/tools/inspector_protocol/jinja2/visitor.py similarity index 100% rename from tools/jinja2/visitor.py rename to tools/inspector_protocol/jinja2/visitor.py diff --git a/tools/markupsafe/AUTHORS b/tools/inspector_protocol/markupsafe/AUTHORS similarity index 100% rename from tools/markupsafe/AUTHORS rename to tools/inspector_protocol/markupsafe/AUTHORS diff --git a/tools/markupsafe/LICENSE b/tools/inspector_protocol/markupsafe/LICENSE similarity index 100% rename from tools/markupsafe/LICENSE rename to tools/inspector_protocol/markupsafe/LICENSE diff --git a/tools/markupsafe/MarkupSafe-0.18.tar.gz.md5 b/tools/inspector_protocol/markupsafe/MarkupSafe-0.18.tar.gz.md5 similarity index 100% rename from tools/markupsafe/MarkupSafe-0.18.tar.gz.md5 rename to tools/inspector_protocol/markupsafe/MarkupSafe-0.18.tar.gz.md5 diff --git a/tools/markupsafe/MarkupSafe-0.18.tar.gz.sha512 b/tools/inspector_protocol/markupsafe/MarkupSafe-0.18.tar.gz.sha512 similarity index 100% rename from tools/markupsafe/MarkupSafe-0.18.tar.gz.sha512 rename to tools/inspector_protocol/markupsafe/MarkupSafe-0.18.tar.gz.sha512 diff --git a/tools/markupsafe/OWNERS b/tools/inspector_protocol/markupsafe/OWNERS similarity index 100% rename from tools/markupsafe/OWNERS rename to tools/inspector_protocol/markupsafe/OWNERS diff --git a/tools/markupsafe/README.chromium b/tools/inspector_protocol/markupsafe/README.chromium similarity index 100% rename from tools/markupsafe/README.chromium rename to tools/inspector_protocol/markupsafe/README.chromium diff --git a/tools/markupsafe/__init__.py b/tools/inspector_protocol/markupsafe/__init__.py similarity index 100% rename from tools/markupsafe/__init__.py rename to tools/inspector_protocol/markupsafe/__init__.py diff --git a/tools/markupsafe/_compat.py b/tools/inspector_protocol/markupsafe/_compat.py similarity index 100% rename from tools/markupsafe/_compat.py rename to tools/inspector_protocol/markupsafe/_compat.py diff --git a/tools/markupsafe/_constants.py b/tools/inspector_protocol/markupsafe/_constants.py similarity index 100% rename from tools/markupsafe/_constants.py rename to tools/inspector_protocol/markupsafe/_constants.py diff --git a/tools/markupsafe/_native.py b/tools/inspector_protocol/markupsafe/_native.py similarity index 100% rename from tools/markupsafe/_native.py rename to tools/inspector_protocol/markupsafe/_native.py diff --git a/tools/markupsafe/_speedups.c b/tools/inspector_protocol/markupsafe/_speedups.c similarity index 100% rename from tools/markupsafe/_speedups.c rename to tools/inspector_protocol/markupsafe/_speedups.c diff --git a/tools/markupsafe/get_markupsafe.sh b/tools/inspector_protocol/markupsafe/get_markupsafe.sh similarity index 100% rename from tools/markupsafe/get_markupsafe.sh rename to tools/inspector_protocol/markupsafe/get_markupsafe.sh diff --git a/tools/install.py b/tools/install.py index 3befec213b1ce6..655802980a6ea9 100755 --- a/tools/install.py +++ b/tools/install.py @@ -1,17 +1,16 @@ #!/usr/bin/env python from __future__ import print_function + import ast import errno import os -import re import shutil import sys -from getmoduleversion import get_version # set at init time node_prefix = '/usr/local' # PREFIX variable from Makefile -install_path = None # base target directory (DESTDIR + PREFIX from Makefile) +install_path = '' # base target directory (DESTDIR + PREFIX from Makefile) target_defaults = None variables = None @@ -101,7 +100,7 @@ def npm_files(action): elif action == install: try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path) else: - assert(0) # unhandled action type + assert 0 # unhandled action type # create/remove symlink link_path = abspath(install_path, 'bin/npx') @@ -110,15 +109,15 @@ def npm_files(action): elif action == install: try_symlink('../lib/node_modules/npm/bin/npx-cli.js', link_path) else: - assert(0) # unhandled action type + assert 0 # unhandled action type def subdir_files(path, dest, action): ret = {} for dirpath, dirnames, filenames in os.walk(path): - files = [dirpath + '/' + f for f in filenames if f.endswith('.h')] - ret[dest + dirpath.replace(path, '')] = files - for subdir, files in ret.items(): - action(files, subdir + '/') + files_in_path = [dirpath + '/' + f for f in filenames if f.endswith('.h')] + ret[dest + dirpath.replace(path, '')] = files_in_path + for subdir, files_in_path in ret.items(): + action(files_in_path, subdir + '/') def files(action): is_windows = sys.platform == 'win32' @@ -162,13 +161,13 @@ def files(action): headers(action) def headers(action): - def ignore_inspector_headers(files, dest): + def ignore_inspector_headers(files_arg, dest): inspector_headers = [ 'deps/v8/include/v8-inspector.h', 'deps/v8/include/v8-inspector-protocol.h' ] - files = [name for name in files if name not in inspector_headers] - action(files, dest) + files_arg = [name for name in files_arg if name not in inspector_headers] + action(files_arg, dest) action([ 'common.gypi', diff --git a/tools/js2c.py b/tools/js2c.py index eff44940c57ec6..86648f785cee5b 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -34,17 +34,10 @@ import os import re import sys -import string -import hashlib - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 def ToCArray(elements, step=10): - slices = (elements[i:i+step] for i in xrange(0, len(elements), step)) + slices = (elements[i:i+step] for i in range(0, len(elements), step)) slices = map(lambda s: ','.join(str(x) for x in s), slices) return ',\n'.join(slices) @@ -149,7 +142,8 @@ def ReadMacros(lines): hash = line.find('#') if hash != -1: line = line[:hash] line = line.strip() - if len(line) is 0: continue + if len(line) == 0: + continue const_match = CONST_PATTERN.match(line) if const_match: name = const_match.group(1) @@ -159,14 +153,14 @@ def ReadMacros(lines): macro_match = MACRO_PATTERN.match(line) if macro_match: name = macro_match.group(1) - args = map(string.strip, macro_match.group(2).split(',')) + args = [s.strip() for s in macro_match.group(2).split(',')] body = macro_match.group(3).strip() macros[name] = TextMacro(args, body) else: python_match = PYTHON_MACRO_PATTERN.match(line) if python_match: name = python_match.group(1) - args = map(string.strip, python_match.group(2).split(',')) + args = [s.strip() for s in python_match.group(2).split(',')] body = python_match.group(3).strip() fun = eval("lambda " + ",".join(args) + ': ' + body) macros[name] = PythonMacro(args, fun) @@ -237,7 +231,7 @@ def GetDefinition(var, source): # Treat non-ASCII as UTF-8 and convert it to UTF-16. if any(ord(c) > 127 for c in source): source = map(ord, source.decode('utf-8').encode('utf-16be')) - source = [source[i] * 256 + source[i+1] for i in xrange(0, len(source), 2)] + source = [source[i] * 256 + source[i+1] for i in range(0, len(source), 2)] source = ToCArray(source) return TWO_BYTE_STRING.format(var=var, data=source) else: diff --git a/tools/check_macros.py b/tools/js2c_macros/check_macros.py similarity index 95% rename from tools/check_macros.py rename to tools/js2c_macros/check_macros.py index 2baf0d7f419573..f24d47c9ee40bf 100644 --- a/tools/check_macros.py +++ b/tools/js2c_macros/check_macros.py @@ -1,3 +1,4 @@ +# flake8: noqa macro CHECK(x) = do { if (!(x)) (process._rawDebug("CHECK: x == true"), process.abort()) } while (0); macro CHECK_EQ(a, b) = CHECK((a) === (b)); macro CHECK_GE(a, b) = CHECK((a) >= (b)); diff --git a/tools/dcheck_macros.py b/tools/js2c_macros/dcheck_macros.py similarity index 100% rename from tools/dcheck_macros.py rename to tools/js2c_macros/dcheck_macros.py diff --git a/tools/nodcheck_macros.py b/tools/js2c_macros/nodcheck_macros.py similarity index 100% rename from tools/nodcheck_macros.py rename to tools/js2c_macros/nodcheck_macros.py diff --git a/src/notrace_macros.py b/tools/js2c_macros/notrace_macros.py similarity index 100% rename from src/notrace_macros.py rename to tools/js2c_macros/notrace_macros.py diff --git a/tools/test.py b/tools/test.py index 549908cf38b061..2247db36359890 100755 --- a/tools/test.py +++ b/tools/test.py @@ -52,21 +52,7 @@ except ImportError: from Queue import Queue, Empty # Python 2 -try: - cmp # Python 2 -except NameError: - def cmp(x, y): # Python 3 - return (x > y) - (x < y) - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce try: from urllib.parse import unquote # Python 3 @@ -135,9 +121,9 @@ def Run(self, tasks): for thread in threads: # Use a timeout so that signals (ctrl-c) will be processed. thread.join(timeout=10000000) - except (KeyboardInterrupt, SystemExit) as e: + except (KeyboardInterrupt, SystemExit): self.shutdown_event.set() - except Exception as e: + except Exception: # If there's an exception we schedule an interruption for any # remaining threads. self.shutdown_event.set() @@ -174,7 +160,7 @@ def RunSingle(self, parallel, thread_id): output = case.Run() output.diagnostic.append('ECONNREFUSED received, test retried') case.duration = (datetime.now() - start) - except IOError as e: + except IOError: return if self.shutdown_event.is_set(): return @@ -355,7 +341,7 @@ def HasRun(self, output): logger.info(' ---') logger.info(' duration_ms: %d.%d' % (total_seconds, duration.microseconds / 1000)) - if self.severity is not 'ok' or self.traceback is not '': + if self.severity != 'ok' or self.traceback != '': if output.HasTimedOut(): self.traceback = 'timeout\n' + output.output.stdout + output.output.stderr self._printDiagnostic() @@ -383,9 +369,10 @@ def HasRun(self, output): stdout = output.output.stdout.strip() printed_file = False for line in stdout.splitlines(): - if (line.startswith("[aborted optimiz") or \ - line.startswith("[disabled optimiz")) and \ - ("because:" in line or "reason:" in line): + if ( + (line.startswith("[aborted optimiz") or line.startswith("[disabled optimiz")) and + ("because:" in line or "reason:" in line) + ): if not printed_file: printed_file = True print('==== %s ====' % command) @@ -522,9 +509,6 @@ def __init__(self, context, path, arch, mode): def IsNegative(self): return self.context.expect_fail - def CompareTime(self, other): - return cmp(other.duration, self.duration) - def DidFail(self, output): if output.failed is None: output.failed = self.IsFailureOutput(output) @@ -597,7 +581,7 @@ def HasCrashed(self): return self.output.exit_code < 0 def HasTimedOut(self): - return self.output.timed_out; + return self.output.timed_out def HasFailed(self): execution_failed = self.test.DidFail(self.output) @@ -731,7 +715,9 @@ def CheckedUnlink(name): PrintError("os.unlink() " + str(e)) break -def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False, input=None): +def Execute(args, context, timeout=None, env=None, faketty=False, disable_core_files=False, input=None): + if env is None: + env = {} if faketty: import pty (out_master, fd_out) = pty.openpty() @@ -897,7 +883,7 @@ def ListTests(self, current_path, path, context, arch, mode): if not name or name.match(test_name): full_path = current_path + [test_name] test.AddTestsToList(result, full_path, path, context, arch, mode) - result.sort(cmp=lambda a, b: cmp(a.GetName(), b.GetName())) + result.sort(key=lambda x: x.GetName()) return result def GetTestStatus(self, context, sections, defs): @@ -1283,7 +1269,7 @@ def Contains(self, path): HEADER_PATTERN = re.compile(r'\[([^]]+)\]') RULE_PATTERN = re.compile(r'\s*([^: ]*)\s*:(.*)') DEF_PATTERN = re.compile(r'^def\s*(\w+)\s*=(.*)$') -PREFIX_PATTERN = re.compile(r'^\s*prefix\s+([\w\_\.\-\/]+)$') +PREFIX_PATTERN = re.compile(r'^\s*prefix\s+([\w_.\-/]+)$') def ReadConfigurationInto(path, sections, defs): @@ -1470,9 +1456,9 @@ def __str__(self): return self.pattern -def SplitPath(s): - stripped = [ c.strip() for c in s.split('/') ] - return [ Pattern(s) for s in stripped if len(s) > 0 ] +def SplitPath(path_arg): + stripped = [c.strip() for c in path_arg.split('/')] + return [Pattern(s) for s in stripped if len(s) > 0] def NormalizePath(path, prefix='test/'): # strip the extra path information of the specified test @@ -1641,7 +1627,7 @@ def Main(): continue archEngineContext = Execute([vm, "-p", "process.arch"], context) vmArch = archEngineContext.stdout.rstrip() - if archEngineContext.exit_code is not 0 or vmArch == "undefined": + if archEngineContext.exit_code != 0 or vmArch == "undefined": print("Can't determine the arch of: '%s'" % vm) print(archEngineContext.stderr.rstrip()) continue @@ -1753,7 +1739,7 @@ def should_keep(case): print() sys.stderr.write("--- Total time: %s ---\n" % FormatTime(duration)) timed_tests = [ t for t in cases_to_run if not t.duration is None ] - timed_tests.sort(lambda a, b: a.CompareTime(b)) + timed_tests.sort(key=lambda x: x.duration) for i, entry in enumerate(timed_tests[:20], start=1): t = FormatTimedelta(entry.duration) sys.stderr.write("%4i (%s) %s\n" % (i, t, entry.GetLabel()))