Skip to content

Commit

Permalink
tools: python: ignore instead of select flake8 rules
Browse files Browse the repository at this point in the history
PR-URL: #25614
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
refack committed Apr 14, 2019
1 parent a16a0fe commit 1fc4255
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
exclude=.git,deps,lib,src,tools/gyp,tools/inspector_protocol,tools/pip,tools/v8_gypfiles/broken
select=E9,F63,F72,F82
ignore=E1,E2,E3,E4,E5,E7,W5,W6
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 8 additions & 17 deletions test/message/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:(.*)")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
41 changes: 16 additions & 25 deletions test/pseudo-tty/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down
44 changes: 19 additions & 25 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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
4 changes: 3 additions & 1 deletion tools/getmoduleversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re


def get_version():
node_version_h = os.path.join(
os.path.dirname(__file__),
Expand All @@ -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())
23 changes: 11 additions & 12 deletions tools/install.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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')
Expand All @@ -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'
Expand Down Expand Up @@ -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',
Expand Down
15 changes: 4 additions & 11 deletions tools/js2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -160,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)
Expand Down Expand Up @@ -238,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:
Expand Down
Loading

0 comments on commit 1fc4255

Please sign in to comment.