Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build,python: update flake8 rules #25614

Merged
merged 3 commits into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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
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
8 changes: 4 additions & 4 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
2 changes: 1 addition & 1 deletion src/inspector/node_inspector.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/wpt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py
3 changes: 0 additions & 3 deletions test/fixtures/wpt/encoding/resources/single-byte-raw.py

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/wpt/encoding/resources/text-plain-charset.py

This file was deleted.

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
2 changes: 1 addition & 1 deletion tools/configure.d/nodedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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())
6 changes: 3 additions & 3 deletions tools/icu/icutrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading