Skip to content

Commit e56e6ed

Browse files
committed
flake8 fixes
1 parent 75b94f0 commit e56e6ed

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

tools/building.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def side_module_external_deps(external_symbols):
114114
sym = demangle_c_symbol_name(sym)
115115
if sym in external_symbols:
116116
deps = deps.union(external_symbols[sym])
117-
return sorted(deps)
117+
return sorted(list(deps))
118118

119119

120120
def create_stub_object(external_symbols):
@@ -184,11 +184,12 @@ def lld_flags_for_executable(external_symbols):
184184
c_exports += side_module_external_deps(external_symbols)
185185
for export in c_exports:
186186
if settings.ERROR_ON_UNDEFINED_SYMBOLS:
187-
cmd.append(f'--export={export}')
187+
cmd.append('--export=' + export)
188188
else:
189-
cmd.append(f'--export-if-defined={export}')
189+
cmd.append('--export-if-defined=' + export)
190190

191-
cmd.extend(f'--export-if-defined={e}' for e in settings.EXPORT_IF_DEFINED)
191+
for e in settings.EXPORT_IF_DEFINED:
192+
cmd.append('--export-if-defined=' + e)
192193

193194
if settings.RELOCATABLE:
194195
cmd.append('--experimental-pic')
@@ -425,7 +426,10 @@ def eval_ctors(js_file, wasm_file, debug_info):
425426
if kept_ctors:
426427
args += ['--kept-exports=' + ','.join(kept_ctors)]
427428
else:
428-
ctor = '_start' if settings.EXPECT_MAIN else '_initialize'
429+
if settings.EXPECT_MAIN:
430+
ctor = '_start'
431+
else:
432+
ctor = '_initialize'
429433
args = ['--ctors=' + ctor, '--kept-exports=' + ctor]
430434
if settings.EVAL_CTORS == 2:
431435
args += ['--ignore-external-input']
@@ -745,10 +749,10 @@ def minify_wasm_js(js_file, wasm_file, expensive_optimizations, debug_info):
745749

746750

747751
def is_internal_global(name):
748-
internal_start_stop_symbols = {'__start_em_asm', '__stop_em_asm',
752+
internal_start_stop_symbols = set(['__start_em_asm', '__stop_em_asm',
749753
'__start_em_js', '__stop_em_js',
750754
'__start_em_lib_deps', '__stop_em_lib_deps',
751-
'__em_lib_deps'}
755+
'__em_lib_deps'])
752756
internal_prefixes = ('__em_js__', '__em_lib_deps')
753757
return name in internal_start_stop_symbols or any(name.startswith(p) for p in internal_prefixes)
754758

tools/emscripten.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def set_memory(static_bump):
225225

226226
def report_missing_exports_wasm_only(metadata):
227227
if diagnostics.is_enabled('undefined'):
228-
defined_symbols = {asmjs_mangle(e) for e in metadata.all_exports}
228+
defined_symbols = set(asmjs_mangle(e) for e in metadata.all_exports)
229229
missing = set(settings.USER_EXPORTS) - defined_symbols
230230
for symbol in sorted(missing):
231231
diagnostics.warning('undefined', f'undefined exported symbol: "{symbol}"')
@@ -235,7 +235,7 @@ def report_missing_exports(js_symbols):
235235
if diagnostics.is_enabled('undefined'):
236236
# Report any symbol that was explicitly exported but is present neither
237237
# as a native function nor as a JS library function.
238-
defined_symbols = {asmjs_mangle(e) for e in settings.WASM_EXPORTS}.union(js_symbols)
238+
defined_symbols = set(asmjs_mangle(e) for e in settings.WASM_EXPORTS).union(js_symbols)
239239
missing = set(settings.USER_EXPORTS) - defined_symbols
240240
for symbol in sorted(missing):
241241
diagnostics.warning('undefined', f'undefined exported symbol: "{symbol}"')
@@ -346,7 +346,10 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
346346

347347
for em_js_func, raw in metadata.em_js_funcs.items():
348348
c_sig = raw.split('<::>')[0].strip('()')
349-
c_sig = [] if (c_sig or 'void') == 'void' else c_sig.split(',')
349+
if not c_sig or c_sig == 'void':
350+
c_sig = []
351+
else:
352+
c_sig = c_sig.split(',')
350353
if em_js_func in import_map:
351354
imp = import_map[em_js_func]
352355
assert imp.kind == webassembly.ExternType.FUNC
@@ -643,8 +646,11 @@ def create_tsd_exported_runtime_methods(metadata):
643646
tsc_output_file = in_temp('jsdoc.d.ts')
644647
utils.write_file(js_doc_file, js_doc)
645648
tsc = shutil.which('tsc')
646-
# Use the full path from the which command so windows can find tsc.
647-
tsc = [tsc] if tsc else shared.get_npm_cmd('tsc')
649+
if tsc:
650+
# Use the full path from the which command so windows can find tsc.
651+
tsc = [tsc]
652+
else:
653+
tsc = shared.get_npm_cmd('tsc')
648654
cmd = tsc + ['--outFile', tsc_output_file, '--declaration', '--emitDeclarationOnly', '--allowJs', js_doc_file]
649655
shared.check_call(cmd, cwd=path_from_root())
650656
return utils.read_file(tsc_output_file)
@@ -693,12 +699,15 @@ def create_asm_consts(metadata):
693699
asm_consts = {}
694700
for addr, const in metadata.em_asm_consts.items():
695701
body = trim_asm_const_body(const)
702+
args = []
696703
max_arity = 16
697704
arity = 0
698705
for i in range(max_arity):
699-
if f'${i}' in const:
706+
if ('$' + str(i)) in const:
700707
arity = i + 1
701-
args = ', '.join(f"${i}" for i in range(arity))
708+
for i in range(arity):
709+
args.append('$' + str(i))
710+
args = ', '.join(args)
702711
if 'arguments' in body:
703712
# arrow functions don't bind `arguments` so we have to use
704713
# the old function syntax in this case
@@ -708,7 +717,8 @@ def create_asm_consts(metadata):
708717
if settings.RELOCATABLE:
709718
addr += settings.GLOBAL_BASE
710719
asm_consts[addr] = func
711-
asm_consts = sorted(asm_consts.items())
720+
asm_consts = [(key, value) for key, value in asm_consts.items()]
721+
asm_consts.sort()
712722
return asm_consts
713723

714724

@@ -752,7 +762,10 @@ def create_em_js(metadata):
752762
assert separator in raw
753763
args, body = raw.split(separator, 1)
754764
args = args[1:-1]
755-
args = [] if args == 'void' else args.split(',')
765+
if args == 'void':
766+
args = []
767+
else:
768+
args = args.split(',')
756769
arg_names = [arg.split()[-1].replace('*', '') for arg in args if arg]
757770
args = ','.join(arg_names)
758771
func = f'function {name}({args}) {body}'
@@ -823,8 +836,10 @@ def add_standard_wasm_imports(send_items_map):
823836

824837
def create_sending(metadata, library_symbols):
825838
# Map of wasm imports to mangled/external/JS names
826-
send_items_map = {name: name for name in metadata.imports}
839+
send_items_map = {}
827840

841+
for name in metadata.invoke_funcs:
842+
send_items_map[name] = name
828843
for name in metadata.imports:
829844
if name in metadata.em_js_funcs:
830845
send_items_map[name] = name
@@ -888,7 +903,9 @@ def install_wrapper(sym):
888903
# pthread_self and _emscripten_proxy_execute_task_queue are currently called in some
889904
# cases after the runtime has exited.
890905
# TODO: Look into removing these, and improving our robustness around thread termination.
891-
return sym not in {'__trap', 'pthread_self', '_emscripten_proxy_execute_task_queue'}
906+
if sym in ('__trap', 'pthread_self', '_emscripten_proxy_execute_task_queue'):
907+
return False
908+
return True
892909

893910
for name, types in function_exports.items():
894911
nargs = len(types.params)

tools/maint/gen_struct_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def gen_inspect_code(path, struct, code):
205205

206206
def generate_c_code(headers):
207207
code = ['#include <stdio.h>', '#include <stddef.h>']
208-
208+
209209
code.extend(f'''#include "{header['name']}"''' for header in headers)
210210

211211
code.append('int main() {')

0 commit comments

Comments
 (0)