Update flake8 and fix warnings in .py files (#334)

This commit is contained in:
Sam Clegg
2019-08-28 15:15:38 -07:00
committed by GitHub
parent 7179fac39b
commit f68effe57e
5 changed files with 82 additions and 51 deletions

18
.flake8
View File

@@ -1,3 +1,17 @@
[flake8]
ignore = E111,E114,E501,E261,E266,E121,E402,E241,E701
filename = emsdk.py
ignore = E111,E114,E501,E261,E266,E121,E402,E241,E701,
E722 # We have a bunch of base 'excepts' still
filename = ./emsdk.py, ./test.py
exclude = \
./gnu
./upstream
./fastcomp
./releases
./clang
./emscripten
./git
./node
./python
./temp
./zips
./crunch

65
.gitignore vendored
View File

@@ -1,30 +1,35 @@
clang
emscripten
emsdk_set_env.bat
emsdk_set_env.sh
git
node
python
temp
zips
crunch
java
mingw
spidermonkey
binaryen
.emscripten
.emscripten_cache
.emscripten_cache__last_clear
.emscripten_sanity
.tmp
tmp
gnu
emscripten-nightlies.txt
llvm-nightlies-32bit.txt
llvm-nightlies-64bit.txt
llvm-tags-32bit.txt
llvm-tags-64bit.txt
upstream
emscripten-releases-tot.txt
fastcomp
releases
# Support for --embedded configs
/.emscripten
/.emscripten_cache
/.emscripten_cache__last_clear
/.emscripten_sanity
# Auto-generated by `active`
/emsdk_set_env.bat
/emsdk_set_env.sh
# Tags files that get generated at runtime
/emscripten-nightlies.txt
/llvm-nightlies-32bit.txt
/llvm-nightlies-64bit.txt
/llvm-tags-32bit.txt
/llvm-tags-64bit.txt
/emscripten-releases-tot.txt
# File that get download/extracted by emsdk itself
/gnu
/upstream
/fastcomp
/releases
/clang
/emscripten
/git
/node
/python
/temp
/zips
/crunch
/java
/mingw
/spidermonkey
/binaryen

View File

@@ -7,7 +7,7 @@ before_install:
- docker pull ubuntu:16.04
install:
- pip install flake8==3.4.1
- pip install flake8==3.7.8
script:
- flake8

View File

@@ -128,6 +128,7 @@ def os_name_for_emscripten_releases():
else:
raise Exception('unknown OS')
def to_unix_path(p):
return p.replace('\\', '/')
@@ -298,7 +299,7 @@ def win_get_environment_variable(key, system=True):
else: # Register locally from CURRENT USER section.
folder = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Environment')
value = str(win32api.RegQueryValueEx(folder, key)[0])
except Exception as e:
except Exception:
# PyWin32 is not available - read via os.environ. This has the drawback that expansion items such as %PROGRAMFILES% will have been expanded, so
# need to be precise not to set these back to system registry, or expansion items would be lost.
return os.environ[key]
@@ -308,7 +309,7 @@ def win_get_environment_variable(key, system=True):
print(str(e), file=sys.stderr)
try:
win32api.RegCloseKey(folder)
except Exception as e:
except Exception:
pass
os.environ['PATH'] = prev_path
return None
@@ -344,7 +345,7 @@ def win_set_environment_variable(key, value, system=True):
cmd = ['REG', 'DELETE', 'HKCU\\Environment', '/V', key, '/f']
if VERBOSE: print(str(cmd))
value = subprocess.call(cmd, stdout=subprocess.PIPE)
except Exception as e:
except Exception:
return
return
@@ -359,7 +360,7 @@ def win_set_environment_variable(key, value, system=True):
cmd = ['SETX', key, value]
if VERBOSE: print(str(cmd))
retcode = subprocess.call(cmd, stdout=subprocess.PIPE)
if retcode is not 0:
if retcode != 0:
print('ERROR! Failed to set environment variable ' + key + '=' + value + '. You may need to set it manually.', file=sys.stderr)
except Exception as e:
print('ERROR! Failed to set environment variable ' + key + '=' + value + ':', file=sys.stderr)
@@ -570,6 +571,7 @@ def get_content_length(download):
return 0
def get_download_target(url, dstpath, filename_prefix=''):
file_name = filename_prefix + url.split('/')[-1]
if path_points_to_directory(dstpath):
@@ -582,6 +584,7 @@ def get_download_target(url, dstpath, filename_prefix=''):
return file_name
# On success, returns the filename on the disk pointing to the destination file that was produced
# On failure, returns None.
def download_file(url, dstpath, download_even_if_exists=False, filename_prefix=''):
@@ -629,7 +632,7 @@ def download_file(url, dstpath, download_even_if_exists=False, filename_prefix='
print("Error downloading URL '" + url + "': " + str(e))
rmfile(file_name)
return None
except KeyboardInterrupt as e:
except KeyboardInterrupt:
print("Aborted by User, exiting")
rmfile(file_name)
sys.exit(1)
@@ -1327,11 +1330,11 @@ def get_installed_vstool_version(installed_path):
class Tool(object):
def __init__(self, data):
# Convert the dictionary representation of the tool in 'data' to members of this class for convenience.
for key in data:
if sys.version_info < (3,) and isinstance(data[key], unicode):
setattr(self, key, data[key].encode('Latin-1'))
else:
setattr(self, key, data[key])
for key, value in data.items():
# Python2 compat, convert unicode to str
if sys.version_info < (3,) and isinstance(value, unicode): # noqa
value = value.encode('Latin-1')
setattr(self, key, value)
# Cache the name ID of this Tool (these are read very often)
self.name = self.id + '-' + self.version
@@ -1638,7 +1641,6 @@ class Tool(object):
def cleanup_temp_install_files(self):
url = self.download_url()
if url.endswith(ARCHIVE_SUFFIXES):
file_name = url.split('/')[-1]
download_target = get_download_target(url, zips_subdir, getattr(self, 'zipfile_prefix', ''))
if VERBOSE: print("Deleting temporary zip file " + download_target)
rmfile(download_target)
@@ -1780,7 +1782,7 @@ def get_emscripten_releases_tot():
'tbz2' if not WINDOWS else 'zip'
)
try:
u = urlopen(url)
urlopen(url)
except:
continue
return release
@@ -1951,8 +1953,11 @@ def load_releases_versions():
def is_string(s):
if sys.version_info[0] >= 3:
return isinstance(s, str)
# Python3 compat
try:
basestring
except NameError:
basestring = str
return isinstance(s, basestring)

15
test.py
View File

@@ -4,19 +4,21 @@ import os
import shlex
import shutil
import subprocess
import sys
import tempfile
# Utilities
def listify(x):
if type(x) == list or type(x) == tuple:
return x
return [x]
def check_call(cmd):
subprocess.check_call(shlex.split(cmd))
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
stdout = subprocess.check_output(cmd.split(' '), stderr=stderr)
if expected:
@@ -26,12 +28,14 @@ def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
for x in listify(unexpected):
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
def failing_call_with_output(cmd, expected):
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode, 'call must have failed'
assert expected in stdout, 'call did not have the right output'
def hack_emsdk(marker, replacement):
src = open('emsdk.py').read()
assert marker in src
@@ -40,6 +44,7 @@ def hack_emsdk(marker, replacement):
open(name, 'w').write(src)
return name
# Set up
open('hello_world.cpp', 'w').write('int main() {}')
@@ -56,6 +61,7 @@ assert 'upstream' not in open(os.path.expanduser('~/.emscripten')).read()
print('building proper system libraries')
def test_lib_building(prefix, use_asmjs_optimizer):
def test_build(args, expected=None, unexpected=None):
checked_call_with_output(prefix + '/emscripten/emcc hello_world.cpp' + args,
@@ -78,11 +84,12 @@ def test_lib_building(prefix, use_asmjs_optimizer):
first_time_system_libs = ['generating system library: libdlmalloc.']
test_build('', expected=first_time_system_libs,
unexpected=unexpected_system_libs)
unexpected=unexpected_system_libs)
test_build(' -O2', unexpected=unexpected_system_libs + first_time_system_libs)
test_build(' -s WASM=0', unexpected=unexpected_system_libs + first_time_system_libs)
test_build(' -O2 -s WASM=0', unexpected=unexpected_system_libs + first_time_system_libs)
test_lib_building('fastcomp', use_asmjs_optimizer=True)
print('update')
@@ -160,11 +167,11 @@ check_call('./emsdk update')
print('verify downloads exist for all OSes')
latest_hash = TAGS['releases'][TAGS['latest']]
for os, suffix in [
for osname, suffix in [
('linux', 'tbz2'),
('mac', 'tbz2'),
('win', 'zip')
]:
url = 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/%s/%s/wasm-binaries.%s' % (os, latest_hash, suffix)
url = 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/%s/%s/wasm-binaries.%s' % (osname, latest_hash, suffix)
print(' url: ' + url),
check_call('wget ' + url)