Skip to content

Commit 095c488

Browse files
authored
Python lint: Use flake8 --extend-ignore instead of --ignore (#1498)
1 parent b644e2e commit 095c488

File tree

9 files changed

+27
-68
lines changed

9 files changed

+27
-68
lines changed

.flake8

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
11
[flake8]
2-
# E111: Indentation is not a multiple of four
3-
# E114: Indentation is not a multiple of four (comment)
4-
# E121: Continuation line under-indented for hanging indent
5-
# E122: continuation line missing indentation or outdented
6-
# E126: continuation line over-indented for hanging indent
7-
# E127: continuation line over-indented for visual indent
8-
# E128: continuation line under-indented for visual indent
9-
# E201: whitespace after '['
10-
# E202: whitespace before ']'
11-
# E203: whitespace before ':'
12-
# E211: whitespace before '('
13-
# E221: multiple spaces before operator
14-
# E226: missing whitespace around arithmetic operator
15-
# E228: missing whitespace around modulo operator
16-
# E231: missing whitespace after ','
17-
# E241: multiple spaces after ','
18-
# E251: unexpected spaces around keyword / parameter equals
19-
# E261: at least two spaces before inline comment
20-
# E262: inline comment should start with '# '
21-
# E266: too many leading '#' for block comment
22-
# E271: multiple spaces after keyword
23-
# E301: expected 1 blank line, found 0
24-
# E302: expected 2 blank lines, found 1
25-
# E303: too many blank lines (2)
26-
# E305: expected 2 blank lines after class or function definition, found 1
27-
# E306: expected 1 blank line before a nested definition, found 0
28-
# E402: module level import not at top of file
29-
# E501: Line too long
30-
# E704: multiple statements on one line (def)
31-
# E713: test for membership should be 'not in'
32-
# E721: do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
33-
# E722: bare excepts
34-
# E731: do not assign a lambda expression, use a def
35-
# E741: Variable names such as 'l', 'O', or 'I'
36-
# F401: 'pip._internal.cli.index_command.SessionCommandMixin' imported but unused
37-
# F403: 'from .core import *' used; unable to detect undefined names
38-
# F405: 'encode' may be undefined, or defined from star imports: .codec, .core
39-
# F541: f-string is missing placeholders
40-
# F811: redefinition of unused 'Console' from line 8
41-
# F821: undefined name 'basestring'
42-
# F841: local variable 'foos' is assigned to but never used
43-
# W291: trailing whitespace
44-
# W391: blank line at end of file
45-
# W503: line break before binary operator
46-
# W504: line break after binary operator
47-
ignore = E111, E114, E121, E122, E126, E127, E128, E201, E202, E203, E211, E221, E226,
48-
E228, E231, E241, E251, E261, E262, E266, E271, E301, E302, E303, E305, E306, E402,
49-
E501, E704, E713, E721, E722, E731, E741, F401, F403, F405, F541, F811, F821, F841,
50-
W291, W391, W503, W504
51-
52-
exclude =
2+
extend-exclude =
3+
./.*,
534
./binaryen,
545
./clang,
556
./crunch,
@@ -65,3 +16,9 @@ exclude =
6516
./releases,
6617
./temp,
6718
./upstream,
19+
20+
# E111: Indentation is not a multiple of four
21+
# E114: Indentation is not a multiple of four (comment)
22+
extend-ignore = E111, E114
23+
24+
max-line-length = 326

bazel/emscripten_toolchain/link_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Only argument should be @path/to/parameter/file
2525
assert sys.argv[1][0] == '@', sys.argv
2626
param_filename = sys.argv[1][1:]
27-
param_file_args = [l.strip() for l in open(param_filename, 'r').readlines()]
27+
param_file_args = [line.strip() for line in open(param_filename, 'r').readlines()]
2828

2929
# Re-write response file if needed.
3030
if any(' ' in a for a in param_file_args):

emsdk.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def GIT(must_succeed=True):
784784
if ret == 0:
785785
cached_git_executable = git
786786
return git
787-
except:
787+
except Exception:
788788
pass
789789
if must_succeed:
790790
if WINDOWS:
@@ -853,7 +853,7 @@ def git_pull(repo_path, branch_or_tag):
853853
if ret != 0:
854854
return False
855855
run([GIT(), 'submodule', 'update', '--init'], repo_path, quiet=True)
856-
except:
856+
except Exception:
857857
errlog('git operation failed!')
858858
return False
859859
print("Successfully updated and checked out branch/tag '" + branch_or_tag + "' on repository '" + repo_path + "'")
@@ -1041,7 +1041,7 @@ def xcode_sdk_version():
10411041
if sys.version_info >= (3,):
10421042
output = output.decode('utf8')
10431043
return output.strip().split('.')
1044-
except:
1044+
except Exception:
10451045
return subprocess.checkplatform.mac_ver()[0].split('.')
10461046

10471047

@@ -1490,14 +1490,14 @@ def load_em_config():
14901490
lines = []
14911491
try:
14921492
lines = open(EM_CONFIG_PATH, "r").read().split('\n')
1493-
except:
1493+
except Exception:
14941494
pass
14951495
for line in lines:
14961496
try:
14971497
key, value = parse_key_value(line)
14981498
if value != '':
14991499
EM_CONFIG_DICT[key] = value
1500-
except:
1500+
except Exception:
15011501
pass
15021502

15031503

@@ -2127,13 +2127,13 @@ def make_url(ext):
21272127
make_url('tar.xz' if not WINDOWS else 'zip')
21282128
try:
21292129
urlopen(make_url('tar.xz' if not WINDOWS else 'zip'))
2130-
except:
2130+
except Exception:
21312131
if not WINDOWS:
21322132
# Try the old `.tbz2` name
21332133
# TODO:remove this once tot builds are all using xz
21342134
try:
21352135
urlopen(make_url('tbz2'))
2136-
except:
2136+
except Exception:
21372137
continue
21382138
else:
21392139
continue
@@ -2918,7 +2918,7 @@ def extract_string_arg(name):
29182918
build_type_index = [x.lower() for x in build_types].index(build_type.lower())
29192919
CMAKE_BUILD_TYPE_OVERRIDE = build_types[build_type_index]
29202920
args[i] = ''
2921-
except:
2921+
except Exception:
29222922
errlog('Unknown CMake build type "' + build_type + '" specified! Please specify one of ' + str(build_types))
29232923
return 1
29242924
else:

scripts/create_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def main(args):
6262

6363
branch_name = 'version_' + new_version
6464

65-
if is_github_runner: # For GitHub Actions workflows
65+
if is_github_runner: # For GitHub Actions workflows
6666
with open(os.environ['GITHUB_ENV'], 'a') as f:
6767
f.write(f'RELEASE_VERSION={new_version}')
68-
else: # Local use
68+
else: # Local use
6969
# Create a new git branch
7070
subprocess.check_call(['git', 'checkout', '-b', branch_name, 'origin/main'], cwd=root_dir)
7171

scripts/get_emscripten_revision_info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
EMSCRIPTEN_RELEASES_GIT = 'https://chromium.googlesource.com/emscripten-releases'
99
TAGFILE = 'emscripten-releases-tags.json'
1010

11+
1112
def get_latest_hash(tagfile):
1213
with open(tagfile) as f:
1314
versions = json.load(f)
1415
latest = versions['aliases']['latest']
1516
return versions['releases'][latest]
1617

18+
1719
def get_latest_emscripten(tagfile):
1820
latest = get_latest_hash(tagfile)
1921
if not os.path.isdir('emscripten-releases'):
@@ -30,6 +32,7 @@ def get_latest_emscripten(tagfile):
3032
if len(tokens) and tokens[0] == 'emscripten':
3133
return tokens[2]
3234

35+
3336
if __name__ == '__main__':
3437
emscripten_hash = get_latest_emscripten(TAGFILE)
3538
print('Emscripten revision ' + emscripten_hash)

scripts/get_release_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
import json
4-
import os
54
import sys
65

6+
77
def get_latest(tagfile):
88
with open(tagfile) as f:
99
versions = json.load(f)

scripts/update_python.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
upload_base = 'gs://webassembly/emscripten-releases-builds/deps/'
4646

4747

48-
49-
5048
def make_python_patch():
5149
pywin32_filename = 'pywin32-%s.win-amd64-py%s.exe' % (pywin32_version, major_minor_version)
5250
filename = 'python-%s-amd64.zip' % (version)

scripts/zip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
34
def unzip_cmd():
45
# Use 7-Zip if available (https://www.7-zip.org/)
56
sevenzip = os.path.join(os.getenv('ProgramFiles', ''), '7-Zip', '7z.exe')

test/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828

2929
def listify(x):
30-
if type(x) == list or type(x) == tuple:
30+
if type(x) in {list, tuple}:
3131
return x
3232
return [x]
3333

3434

3535
def check_call(cmd, **args):
36-
if type(cmd) != list:
36+
if type(cmd) is not list:
3737
cmd = cmd.split()
3838
print('running: %s' % cmd)
3939
args['universal_newlines'] = True
@@ -115,7 +115,7 @@ def do_build(args, is_expected=None):
115115

116116

117117
def run_emsdk(cmd):
118-
if type(cmd) != list:
118+
if type(cmd) is not list:
119119
cmd = cmd.split()
120120
check_call([emsdk] + cmd)
121121

0 commit comments

Comments
 (0)