Skip to content

Commit 1fc4255

Browse files
committed
tools: python: ignore instead of select flake8 rules
PR-URL: #25614 Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent a16a0fe commit 1fc4255

File tree

9 files changed

+81
-125
lines changed

9 files changed

+81
-125
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
exclude=.git,deps,lib,src,tools/gyp,tools/inspector_protocol,tools/pip,tools/v8_gypfiles/broken
3-
select=E9,F63,F72,F82
3+
ignore=E1,E2,E3,E4,E5,E7,W5,W6

configure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ def configure_library(lib, output):
11101110
output['libraries'] += [pkg_libpath]
11111111

11121112
default_libs = getattr(options, shared_lib + '_libname')
1113-
default_libs = ['-l{0}'.format(lib) for lib in default_libs.split(',')]
1113+
default_libs = ['-l{0}'.format(l) for l in default_libs.split(',')]
11141114

11151115
if default_libs:
11161116
output['libraries'] += default_libs

test/message/testcfg.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,7 @@
3030
import os
3131
from os.path import join, exists, basename, isdir
3232
import re
33-
34-
try:
35-
reduce # Python 2
36-
except NameError: # Python 3
37-
from functools import reduce
38-
39-
try:
40-
xrange # Python 2
41-
except NameError:
42-
xrange = range # Python 3
33+
from functools import reduce
4334

4435
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
4536

@@ -82,13 +73,13 @@ def IsFailureOutput(self, output):
8273
print("expect=%d" % len(patterns))
8374
print("actual=%d" % len(outlines))
8475
print("patterns:")
85-
for i in xrange(len(patterns)):
76+
for i in range(len(patterns)):
8677
print("pattern = %s" % patterns[i])
8778
print("outlines:")
88-
for i in xrange(len(outlines)):
79+
for i in range(len(outlines)):
8980
print("outline = %s" % outlines[i])
9081
return True
91-
for i in xrange(len(patterns)):
82+
for i in range(len(patterns)):
9283
if not re.match(patterns[i], outlines[i]):
9384
print("match failed")
9485
print("line=%d" % i)
@@ -129,13 +120,13 @@ def Ls(self, path):
129120
def ListTests(self, current_path, path, arch, mode):
130121
all_tests = [current_path + [t] for t in self.Ls(self.root)]
131122
result = []
132-
for test in all_tests:
133-
if self.Contains(path, test):
134-
file_path = join(self.root, reduce(join, test[1:], ''))
123+
for tst in all_tests:
124+
if self.Contains(path, tst):
125+
file_path = join(self.root, reduce(join, tst[1:], ''))
135126
output_path = file_path[:file_path.rfind('.')] + '.out'
136127
if not exists(output_path):
137128
raise Exception("Could not find %s" % output_path)
138-
result.append(MessageTestCase(test, file_path, output_path,
129+
result.append(MessageTestCase(tst, file_path, output_path,
139130
arch, mode, self.context, self))
140131
return result
141132

test/pseudo-tty/testcfg.py

+16-25
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,25 @@
3232
from os.path import join, exists, basename, isdir
3333
import re
3434
import utils
35-
36-
try:
37-
reduce # Python 2
38-
except NameError: # Python 3
39-
from functools import reduce
40-
41-
try:
42-
xrange # Python 2
43-
except NameError:
44-
xrange = range # Python 3
35+
from functools import reduce
4536

4637
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
4738

4839
class TTYTestCase(test.TestCase):
4940

50-
def __init__(self, path, file, expected, input, arch, mode, context, config):
41+
def __init__(self, path, file, expected, input_arg, arch, mode, context, config):
5142
super(TTYTestCase, self).__init__(context, path, arch, mode)
5243
self.file = file
5344
self.expected = expected
54-
self.input = input
45+
self.input = input_arg
5546
self.config = config
5647
self.arch = arch
5748
self.mode = mode
5849

59-
def IgnoreLine(self, str):
50+
def IgnoreLine(self, str_arg):
6051
"""Ignore empty lines and valgrind output."""
61-
if not str.strip(): return True
62-
else: return str.startswith('==') or str.startswith('**')
52+
if not str_arg.strip(): return True
53+
else: return str_arg.startswith('==') or str_arg.startswith('**')
6354

6455
def IsFailureOutput(self, output):
6556
f = open(self.expected)
@@ -81,13 +72,13 @@ def IsFailureOutput(self, output):
8172
print("expect=%d" % len(patterns))
8273
print("actual=%d" % len(outlines))
8374
print("patterns:")
84-
for i in xrange(len(patterns)):
75+
for i in range(len(patterns)):
8576
print("pattern = %s" % patterns[i])
8677
print("outlines:")
87-
for i in xrange(len(outlines)):
78+
for i in range(len(outlines)):
8879
print("outline = %s" % outlines[i])
8980
return True
90-
for i in xrange(len(patterns)):
81+
for i in range(len(patterns)):
9182
if not re.match(patterns[i], outlines[i]):
9283
print("match failed")
9384
print("line=%d" % i)
@@ -117,16 +108,16 @@ def GetSource(self):
117108
+ open(self.expected).read())
118109

119110
def RunCommand(self, command, env):
120-
input = None
111+
input_arg = None
121112
if self.input is not None and exists(self.input):
122-
input = open(self.input).read()
113+
input_arg = open(self.input).read()
123114
full_command = self.context.processor(command)
124115
output = test.Execute(full_command,
125116
self.context,
126117
self.context.GetTimeout(self.mode),
127118
env,
128119
faketty=True,
129-
input=input)
120+
input=input_arg)
130121
return test.TestOutput(self,
131122
full_command,
132123
output,
@@ -148,15 +139,15 @@ def ListTests(self, current_path, path, arch, mode):
148139
print ("Skipping pseudo-tty tests, as pseudo terminals are not available"
149140
" on Windows.")
150141
return result
151-
for test in all_tests:
152-
if self.Contains(path, test):
153-
file_prefix = join(self.root, reduce(join, test[1:], ""))
142+
for tst in all_tests:
143+
if self.Contains(path, tst):
144+
file_prefix = join(self.root, reduce(join, tst[1:], ""))
154145
file_path = file_prefix + ".js"
155146
input_path = file_prefix + ".in"
156147
output_path = file_prefix + ".out"
157148
if not exists(output_path):
158149
raise Exception("Could not find %s" % output_path)
159-
result.append(TTYTestCase(test, file_path, output_path,
150+
result.append(TTYTestCase(tst, file_path, output_path,
160151
input_path, arch, mode, self.context, self))
161152
return result
162153

test/testpy/__init__.py

+19-25
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@
2727

2828
import test
2929
import os
30-
from os.path import join, dirname, exists, splitext
3130
import re
32-
import ast
33-
34-
try:
35-
reduce
36-
except NameError:
37-
from functools import reduce
31+
from functools import reduce
3832

3933

4034
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
41-
35+
LS_RE = re.compile(r'^test-.*\.m?js$')
4236

4337
class SimpleTestCase(test.TestCase):
4438

@@ -107,15 +101,15 @@ def __init__(self, context, root, section, additional=None):
107101
self.additional_flags = []
108102

109103
def Ls(self, path):
110-
return [f for f in os.listdir(path) if re.match('^test-.*\.m?js$', f)]
104+
return [f for f in os.listdir(path) if LS_RE.match(f)]
111105

112106
def ListTests(self, current_path, path, arch, mode):
113-
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
107+
all_tests = [current_path + [t] for t in self.Ls(os.path.join(self.root))]
114108
result = []
115-
for test in all_tests:
116-
if self.Contains(path, test):
117-
file_path = join(self.root, reduce(join, test[1:], ""))
118-
test_name = test[:-1] + [splitext(test[-1])[0]]
109+
for tst in all_tests:
110+
if self.Contains(path, tst):
111+
file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], ""))
112+
test_name = tst[:-1] + [os.path.splitext(tst[-1])[0]]
119113
result.append(SimpleTestCase(test_name, file_path, arch, mode,
120114
self.context, self, self.additional_flags))
121115
return result
@@ -131,8 +125,8 @@ def __init__(self, context, root, section, additional=None):
131125
def ListTests(self, current_path, path, arch, mode):
132126
result = super(ParallelTestConfiguration, self).ListTests(
133127
current_path, path, arch, mode)
134-
for test in result:
135-
test.parallel = True
128+
for tst in result:
129+
tst.parallel = True
136130
return result
137131

138132
class AddonTestConfiguration(SimpleTestConfiguration):
@@ -145,20 +139,20 @@ def SelectTest(name):
145139

146140
result = []
147141
for subpath in os.listdir(path):
148-
if os.path.isdir(join(path, subpath)):
149-
for f in os.listdir(join(path, subpath)):
142+
if os.path.isdir(os.path.join(path, subpath)):
143+
for f in os.listdir(os.path.join(path, subpath)):
150144
if SelectTest(f):
151145
result.append([subpath, f[:-3]])
152146
return result
153147

154148
def ListTests(self, current_path, path, arch, mode):
155-
all_tests = [current_path + t for t in self.Ls(join(self.root))]
149+
all_tests = [current_path + t for t in self.Ls(os.path.join(self.root))]
156150
result = []
157-
for test in all_tests:
158-
if self.Contains(path, test):
159-
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
151+
for tst in all_tests:
152+
if self.Contains(path, tst):
153+
file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "") + ".js")
160154
result.append(
161-
SimpleTestCase(test, file_path, arch, mode, self.context, self, self.additional_flags))
155+
SimpleTestCase(tst, file_path, arch, mode, self.context, self, self.additional_flags))
162156
return result
163157

164158
class AbortTestConfiguration(SimpleTestConfiguration):
@@ -169,6 +163,6 @@ def __init__(self, context, root, section, additional=None):
169163
def ListTests(self, current_path, path, arch, mode):
170164
result = super(AbortTestConfiguration, self).ListTests(
171165
current_path, path, arch, mode)
172-
for test in result:
173-
test.disable_core_files = True
166+
for tst in result:
167+
tst.disable_core_files = True
174168
return result

tools/getmoduleversion.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44

5+
56
def get_version():
67
node_version_h = os.path.join(
78
os.path.dirname(__file__),
@@ -17,8 +18,9 @@ def get_version():
1718
if re.match(regex, line):
1819
major = line.split()[2]
1920
return major
20-
21+
2122
raise Exception('Could not find pattern matching %s' % regex)
2223

24+
2325
if __name__ == '__main__':
2426
print(get_version())

tools/install.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env python
22

33
from __future__ import print_function
4+
45
import ast
56
import errno
67
import os
7-
import re
88
import shutil
99
import sys
10-
from getmoduleversion import get_version
1110

1211
# set at init time
1312
node_prefix = '/usr/local' # PREFIX variable from Makefile
14-
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
13+
install_path = '' # base target directory (DESTDIR + PREFIX from Makefile)
1514
target_defaults = None
1615
variables = None
1716

@@ -101,7 +100,7 @@ def npm_files(action):
101100
elif action == install:
102101
try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path)
103102
else:
104-
assert(0) # unhandled action type
103+
assert 0 # unhandled action type
105104

106105
# create/remove symlink
107106
link_path = abspath(install_path, 'bin/npx')
@@ -110,15 +109,15 @@ def npm_files(action):
110109
elif action == install:
111110
try_symlink('../lib/node_modules/npm/bin/npx-cli.js', link_path)
112111
else:
113-
assert(0) # unhandled action type
112+
assert 0 # unhandled action type
114113

115114
def subdir_files(path, dest, action):
116115
ret = {}
117116
for dirpath, dirnames, filenames in os.walk(path):
118-
files = [dirpath + '/' + f for f in filenames if f.endswith('.h')]
119-
ret[dest + dirpath.replace(path, '')] = files
120-
for subdir, files in ret.items():
121-
action(files, subdir + '/')
117+
files_in_path = [dirpath + '/' + f for f in filenames if f.endswith('.h')]
118+
ret[dest + dirpath.replace(path, '')] = files_in_path
119+
for subdir, files_in_path in ret.items():
120+
action(files_in_path, subdir + '/')
122121

123122
def files(action):
124123
is_windows = sys.platform == 'win32'
@@ -162,13 +161,13 @@ def files(action):
162161
headers(action)
163162

164163
def headers(action):
165-
def ignore_inspector_headers(files, dest):
164+
def ignore_inspector_headers(files_arg, dest):
166165
inspector_headers = [
167166
'deps/v8/include/v8-inspector.h',
168167
'deps/v8/include/v8-inspector-protocol.h'
169168
]
170-
files = [name for name in files if name not in inspector_headers]
171-
action(files, dest)
169+
files_arg = [name for name in files_arg if name not in inspector_headers]
170+
action(files_arg, dest)
172171

173172
action([
174173
'common.gypi',

tools/js2c.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,10 @@
3434
import os
3535
import re
3636
import sys
37-
import string
38-
import hashlib
39-
40-
try:
41-
xrange # Python 2
42-
except NameError:
43-
xrange = range # Python 3
4437

4538

4639
def ToCArray(elements, step=10):
47-
slices = (elements[i:i+step] for i in xrange(0, len(elements), step))
40+
slices = (elements[i:i+step] for i in range(0, len(elements), step))
4841
slices = map(lambda s: ','.join(str(x) for x in s), slices)
4942
return ',\n'.join(slices)
5043

@@ -160,14 +153,14 @@ def ReadMacros(lines):
160153
macro_match = MACRO_PATTERN.match(line)
161154
if macro_match:
162155
name = macro_match.group(1)
163-
args = map(string.strip, macro_match.group(2).split(','))
156+
args = [s.strip() for s in macro_match.group(2).split(',')]
164157
body = macro_match.group(3).strip()
165158
macros[name] = TextMacro(args, body)
166159
else:
167160
python_match = PYTHON_MACRO_PATTERN.match(line)
168161
if python_match:
169162
name = python_match.group(1)
170-
args = map(string.strip, python_match.group(2).split(','))
163+
args = [s.strip() for s in python_match.group(2).split(',')]
171164
body = python_match.group(3).strip()
172165
fun = eval("lambda " + ",".join(args) + ': ' + body)
173166
macros[name] = PythonMacro(args, fun)
@@ -238,7 +231,7 @@ def GetDefinition(var, source):
238231
# Treat non-ASCII as UTF-8 and convert it to UTF-16.
239232
if any(ord(c) > 127 for c in source):
240233
source = map(ord, source.decode('utf-8').encode('utf-16be'))
241-
source = [source[i] * 256 + source[i+1] for i in xrange(0, len(source), 2)]
234+
source = [source[i] * 256 + source[i+1] for i in range(0, len(source), 2)]
242235
source = ToCArray(source)
243236
return TWO_BYTE_STRING.format(var=var, data=source)
244237
else:

0 commit comments

Comments
 (0)