Skip to content

Commit c5f0cbb

Browse files
Aravind VasudevanLUCI CQ
Aravind Vasudevan
authored and
LUCI CQ
committed
Use pylint 2.7 for depot_tools
This includes a few fixes for specific errors, and disables several new warnings introduced in this version, in order to allow for an incremental migration. Bug:1262286 Change-Id: I4b8f8fc521386419a3121bbb07edc8ac83170a94 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3413679 Reviewed-by: Josip Sokcevic <[email protected]> Commit-Queue: Aravind Vasudevan <[email protected]>
1 parent d94f9a6 commit c5f0cbb

39 files changed

+341
-275
lines changed

PRESUBMIT.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,27 @@ def CheckPylint(input_api, output_api):
5757
files_to_skip.extend([fnmatch.translate(l) for l in lines if
5858
l and not l.startswith('#')])
5959
disabled_warnings = [
60-
'R0401', # Cyclic import
61-
'W0613', # Unused argument
60+
'R0401', # Cyclic import
61+
'W0613', # Unused argument
62+
'C0415', # import-outside-toplevel
63+
'R1710', # inconsistent-return-statements
64+
'E1101', # no-member
65+
'E1120', # no-value-for-parameter
66+
'R1708', # stop-iteration-return
67+
'W1510', # subprocess-run-check
68+
# Checks which should be re-enabled after Python 2 support is removed.
69+
'R0205', # useless-object-inheritance
70+
'R1725', # super-with-arguments
71+
'W0707', # raise-missing-from
72+
'W1113', # keyword-arg-before-vararg
6273
]
6374
return input_api.RunTests(input_api.canned_checks.GetPylint(
6475
input_api,
6576
output_api,
6677
files_to_check=files_to_check,
6778
files_to_skip=files_to_skip,
68-
disabled_warnings=disabled_warnings))
79+
disabled_warnings=disabled_warnings,
80+
version='2.7'), parallel=False)
6981

7082

7183
def CheckRecipes(input_api, output_api):

autoninja.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
elif arg.startswith('-C'):
5252
# Support -Cout/Default
5353
output_dir = arg[2:]
54-
elif arg == '-o' or arg == '--offline':
54+
elif arg in ('-o', '--offline'):
5555
offline = True
5656
elif arg == '-h':
5757
print('autoninja: Use -o/--offline to temporary disable goma.',
5858
file=sys.stderr)
5959
print(file=sys.stderr)
6060

6161
# Strip -o/--offline so ninja doesn't see them.
62-
input_args = [ arg for arg in input_args if arg != '-o' and arg != '--offline']
62+
input_args = [ arg for arg in input_args if arg not in ('-o', '--offline')]
6363

6464
use_goma = False
6565
use_remoteexec = False

cit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def is_exe(filename):
8383
"""Given a full filepath, return true if the file is an executable."""
8484
if sys.platform.startswith('win'):
8585
return filename.endswith('.exe')
86-
else:
87-
return os.path.isfile(filename) and os.access(filename, os.X_OK)
86+
87+
return os.path.isfile(filename) and os.access(filename, os.X_OK)
8888

8989

9090
def get_available_tools():

clang_format_merge_driver.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def main():
2828
sys.argv[0])
2929
sys.exit(1)
3030

31+
# pylint: disable=unbalanced-tuple-unpacking
3132
base, current, others, file_name_in_tree = sys.argv[1:5]
33+
# pylint: enable=unbalanced-tuple-unpacking
3234

3335
if file_name_in_tree == '%P':
3436
print(file=sys.stderr)

compile_single_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def path_to_source_root(path):
2323
# to break when we rename directories.
2424
fingerprints = ['chrome', 'net', 'v8', 'build', 'skia']
2525
while candidate and not all(
26-
[os.path.isdir(os.path.join(candidate, fp)) for fp in fingerprints]):
26+
os.path.isdir(os.path.join(candidate, fp)) for fp in fingerprints):
2727
new_candidate = os.path.dirname(candidate)
2828
if new_candidate == candidate:
2929
raise Exception("Couldn't find source-dir from %s" % path)

cpplint.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -5263,8 +5263,8 @@ def ExpectingFunctionArgs(clean_lines, linenum):
52635263
_re_pattern_headers_maybe_templates = []
52645264
for _header, _templates in _HEADERS_MAYBE_TEMPLATES:
52655265
for _template in _templates:
5266-
# Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max or
5267-
# type::max().
5266+
# Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max
5267+
# or type::max().
52685268
_re_pattern_headers_maybe_templates.append(
52695269
(re.compile(r'[^>.]\b' + _template + r'(<.*?>)?\([^\)]'),
52705270
_template,
@@ -5380,9 +5380,9 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
53805380
io: The IO factory to use to read the header file. Provided for unittest
53815381
injection.
53825382
"""
5383-
required = {} # A map of header name to linenumber and the template entity.
5384-
# Example of required: { '<functional>': (1219, 'less<>') }
5385-
5383+
# A map of header name to linenumber and the template entity.
5384+
# Example of required: { '<functional>': (1219, 'less<>') }
5385+
required = {}
53865386
for linenum in range(clean_lines.NumLines()):
53875387
line = clean_lines.elided[linenum]
53885388
if not line or line[0] == '#':
@@ -5865,9 +5865,9 @@ def ProcessConfigOverrides(filename):
58655865
elif name == 'linelength':
58665866
global _line_length
58675867
try:
5868-
_line_length = int(val)
5868+
_line_length = int(val)
58695869
except ValueError:
5870-
sys.stderr.write('Line length must be numeric.')
5870+
sys.stderr.write('Line length must be numeric.')
58715871
else:
58725872
sys.stderr.write(
58735873
'Invalid configuration option (%s) in file %s\n' %
@@ -5881,7 +5881,7 @@ def ProcessConfigOverrides(filename):
58815881
# Apply all the accumulated filters in reverse order (top-level directory
58825882
# config options having the least priority).
58835883
for filter in reversed(cfg_filters):
5884-
_AddFilters(filter)
5884+
_AddFilters(filter)
58855885

58865886
return True
58875887

@@ -6053,15 +6053,15 @@ def ParseArguments(args):
60536053
elif opt == '--linelength':
60546054
global _line_length
60556055
try:
6056-
_line_length = int(val)
6056+
_line_length = int(val)
60576057
except ValueError:
6058-
PrintUsage('Line length must be digits.')
6058+
PrintUsage('Line length must be digits.')
60596059
elif opt == '--extensions':
60606060
global _valid_extensions
60616061
try:
6062-
_valid_extensions = set(val.split(','))
6062+
_valid_extensions = set(val.split(','))
60636063
except ValueError:
6064-
PrintUsage('Extensions must be comma separated list.')
6064+
PrintUsage('Extensions must be comma separated list.')
60656065

60666066
if not filenames:
60676067
PrintUsage('No files were specified.')

download_from_google_storage.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
'aix7': 'aix',
4545
}
4646

47-
48-
class FileNotFoundError(IOError):
49-
pass
47+
if sys.version_info.major == 2:
48+
# pylint: disable=redefined-builtin
49+
class FileNotFoundError(IOError):
50+
pass
5051

5152

5253
class InvalidFileError(IOError):

fetch.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def __init__(self, options, spec, root):
5656

5757
def exists(self):
5858
"""Check does this checkout already exist on desired location"""
59-
pass
6059

6160
def init(self):
6261
pass
@@ -67,18 +66,18 @@ def run(self, cmd, return_stdout=False, **kwargs):
6766
return ''
6867
if return_stdout:
6968
return subprocess.check_output(cmd, **kwargs).decode()
70-
else:
71-
try:
72-
subprocess.check_call(cmd, **kwargs)
73-
except subprocess.CalledProcessError as e:
74-
# If the subprocess failed, it likely emitted its own distress message
75-
# already - don't scroll that message off the screen with a stack trace
76-
# from this program as well. Emit a terse message and bail out here;
77-
# otherwise a later step will try doing more work and may hide the
78-
# subprocess message.
79-
print('Subprocess failed with return code %d.' % e.returncode)
80-
sys.exit(e.returncode)
81-
return ''
69+
70+
try:
71+
subprocess.check_call(cmd, **kwargs)
72+
except subprocess.CalledProcessError as e:
73+
# If the subprocess failed, it likely emitted its own distress message
74+
# already - don't scroll that message off the screen with a stack trace
75+
# from this program as well. Emit a terse message and bail out here;
76+
# otherwise a later step will try doing more work and may hide the
77+
# subprocess message.
78+
print('Subprocess failed with return code %d.' % e.returncode)
79+
sys.exit(e.returncode)
80+
return ''
8281

8382

8483
class GclientCheckout(Checkout):

gclient.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def run(self):
238238
not gclient_eval.EvaluateCondition(self._condition, self._variables)):
239239
return
240240

241-
cmd = [arg for arg in self._action]
241+
cmd = list(self._action)
242242

243243
if cmd[0] == 'python':
244244
cmd[0] = 'vpython'
@@ -373,8 +373,8 @@ def condition(self):
373373
def target_os(self):
374374
if self.local_target_os is not None:
375375
return tuple(set(self.local_target_os).union(self.parent.target_os))
376-
else:
377-
return self.parent.target_os
376+
377+
return self.parent.target_os
378378

379379
@property
380380
def target_cpu(self):
@@ -1420,7 +1420,7 @@ def __init__(self, root_dir, options):
14201420
if 'all' in enforced_os:
14211421
enforced_os = self.DEPS_OS_CHOICES.values()
14221422
self._enforced_os = tuple(set(enforced_os))
1423-
self._enforced_cpu = detect_host_arch.HostArch(),
1423+
self._enforced_cpu = (detect_host_arch.HostArch(), )
14241424
self._root_dir = root_dir
14251425
self._cipd_root = None
14261426
self.config_content = None
@@ -1830,7 +1830,7 @@ def RunOnDeps(self, command, args, ignore_requirements=False, progress=True):
18301830
if command == 'update':
18311831
gn_args_dep = self.dependencies[0]
18321832
if gn_args_dep._gn_args_from:
1833-
deps_map = dict([(dep.name, dep) for dep in gn_args_dep.dependencies])
1833+
deps_map = {dep.name: dep for dep in gn_args_dep.dependencies}
18341834
gn_args_dep = deps_map.get(gn_args_dep._gn_args_from)
18351835
if gn_args_dep and gn_args_dep.HasGNArgsFile():
18361836
gn_args_dep.WriteGNArgsFile()
@@ -1874,11 +1874,12 @@ def ShouldPrintRevision(dep):
18741874
entries = {}
18751875
def GrabDeps(dep):
18761876
"""Recursively grab dependencies."""
1877-
for d in dep.dependencies:
1878-
d.PinToActualRevision()
1879-
if ShouldPrintRevision(d):
1880-
entries[d.name] = d.url
1881-
GrabDeps(d)
1877+
for rec_d in dep.dependencies:
1878+
rec_d.PinToActualRevision()
1879+
if ShouldPrintRevision(rec_d):
1880+
entries[rec_d.name] = rec_d.url
1881+
GrabDeps(rec_d)
1882+
18821883
GrabDeps(d)
18831884
json_output.append({
18841885
'name': d.name,
@@ -2275,7 +2276,7 @@ def _flatten_dep(self, dep):
22752276
if key not in self._vars:
22762277
continue
22772278
# Don't "override" existing vars if it's actually the same value.
2278-
elif self._vars[key][1] == value:
2279+
if self._vars[key][1] == value:
22792280
continue
22802281
# Anything else is overriding a default value from the DEPS.
22812282
self._vars[key] = (hierarchy + ' [custom_var override]', value)

0 commit comments

Comments
 (0)