Update flake8 and fix warnings in .py files (#334)
This commit is contained in:
18
.flake8
18
.flake8
@@ -1,3 +1,17 @@
|
|||||||
[flake8]
|
[flake8]
|
||||||
ignore = E111,E114,E501,E261,E266,E121,E402,E241,E701
|
ignore = E111,E114,E501,E261,E266,E121,E402,E241,E701,
|
||||||
filename = emsdk.py
|
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
65
.gitignore
vendored
@@ -1,30 +1,35 @@
|
|||||||
clang
|
# Support for --embedded configs
|
||||||
emscripten
|
/.emscripten
|
||||||
emsdk_set_env.bat
|
/.emscripten_cache
|
||||||
emsdk_set_env.sh
|
/.emscripten_cache__last_clear
|
||||||
git
|
/.emscripten_sanity
|
||||||
node
|
|
||||||
python
|
# Auto-generated by `active`
|
||||||
temp
|
/emsdk_set_env.bat
|
||||||
zips
|
/emsdk_set_env.sh
|
||||||
crunch
|
|
||||||
java
|
# Tags files that get generated at runtime
|
||||||
mingw
|
/emscripten-nightlies.txt
|
||||||
spidermonkey
|
/llvm-nightlies-32bit.txt
|
||||||
binaryen
|
/llvm-nightlies-64bit.txt
|
||||||
.emscripten
|
/llvm-tags-32bit.txt
|
||||||
.emscripten_cache
|
/llvm-tags-64bit.txt
|
||||||
.emscripten_cache__last_clear
|
/emscripten-releases-tot.txt
|
||||||
.emscripten_sanity
|
|
||||||
.tmp
|
# File that get download/extracted by emsdk itself
|
||||||
tmp
|
/gnu
|
||||||
gnu
|
/upstream
|
||||||
emscripten-nightlies.txt
|
/fastcomp
|
||||||
llvm-nightlies-32bit.txt
|
/releases
|
||||||
llvm-nightlies-64bit.txt
|
/clang
|
||||||
llvm-tags-32bit.txt
|
/emscripten
|
||||||
llvm-tags-64bit.txt
|
/git
|
||||||
upstream
|
/node
|
||||||
emscripten-releases-tot.txt
|
/python
|
||||||
fastcomp
|
/temp
|
||||||
releases
|
/zips
|
||||||
|
/crunch
|
||||||
|
/java
|
||||||
|
/mingw
|
||||||
|
/spidermonkey
|
||||||
|
/binaryen
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ before_install:
|
|||||||
- docker pull ubuntu:16.04
|
- docker pull ubuntu:16.04
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install flake8==3.4.1
|
- pip install flake8==3.7.8
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- flake8
|
- flake8
|
||||||
|
|||||||
33
emsdk.py
33
emsdk.py
@@ -128,6 +128,7 @@ def os_name_for_emscripten_releases():
|
|||||||
else:
|
else:
|
||||||
raise Exception('unknown OS')
|
raise Exception('unknown OS')
|
||||||
|
|
||||||
|
|
||||||
def to_unix_path(p):
|
def to_unix_path(p):
|
||||||
return p.replace('\\', '/')
|
return p.replace('\\', '/')
|
||||||
|
|
||||||
@@ -298,7 +299,7 @@ def win_get_environment_variable(key, system=True):
|
|||||||
else: # Register locally from CURRENT USER section.
|
else: # Register locally from CURRENT USER section.
|
||||||
folder = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Environment')
|
folder = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Environment')
|
||||||
value = str(win32api.RegQueryValueEx(folder, key)[0])
|
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
|
# 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.
|
# need to be precise not to set these back to system registry, or expansion items would be lost.
|
||||||
return os.environ[key]
|
return os.environ[key]
|
||||||
@@ -308,7 +309,7 @@ def win_get_environment_variable(key, system=True):
|
|||||||
print(str(e), file=sys.stderr)
|
print(str(e), file=sys.stderr)
|
||||||
try:
|
try:
|
||||||
win32api.RegCloseKey(folder)
|
win32api.RegCloseKey(folder)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
os.environ['PATH'] = prev_path
|
os.environ['PATH'] = prev_path
|
||||||
return None
|
return None
|
||||||
@@ -344,7 +345,7 @@ def win_set_environment_variable(key, value, system=True):
|
|||||||
cmd = ['REG', 'DELETE', 'HKCU\\Environment', '/V', key, '/f']
|
cmd = ['REG', 'DELETE', 'HKCU\\Environment', '/V', key, '/f']
|
||||||
if VERBOSE: print(str(cmd))
|
if VERBOSE: print(str(cmd))
|
||||||
value = subprocess.call(cmd, stdout=subprocess.PIPE)
|
value = subprocess.call(cmd, stdout=subprocess.PIPE)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -359,7 +360,7 @@ def win_set_environment_variable(key, value, system=True):
|
|||||||
cmd = ['SETX', key, value]
|
cmd = ['SETX', key, value]
|
||||||
if VERBOSE: print(str(cmd))
|
if VERBOSE: print(str(cmd))
|
||||||
retcode = subprocess.call(cmd, stdout=subprocess.PIPE)
|
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)
|
print('ERROR! Failed to set environment variable ' + key + '=' + value + '. You may need to set it manually.', file=sys.stderr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('ERROR! Failed to set environment variable ' + key + '=' + value + ':', file=sys.stderr)
|
print('ERROR! Failed to set environment variable ' + key + '=' + value + ':', file=sys.stderr)
|
||||||
@@ -570,6 +571,7 @@ def get_content_length(download):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def get_download_target(url, dstpath, filename_prefix=''):
|
def get_download_target(url, dstpath, filename_prefix=''):
|
||||||
file_name = filename_prefix + url.split('/')[-1]
|
file_name = filename_prefix + url.split('/')[-1]
|
||||||
if path_points_to_directory(dstpath):
|
if path_points_to_directory(dstpath):
|
||||||
@@ -582,6 +584,7 @@ def get_download_target(url, dstpath, filename_prefix=''):
|
|||||||
|
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
|
||||||
# On success, returns the filename on the disk pointing to the destination file that was produced
|
# On success, returns the filename on the disk pointing to the destination file that was produced
|
||||||
# On failure, returns None.
|
# On failure, returns None.
|
||||||
def download_file(url, dstpath, download_even_if_exists=False, filename_prefix=''):
|
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))
|
print("Error downloading URL '" + url + "': " + str(e))
|
||||||
rmfile(file_name)
|
rmfile(file_name)
|
||||||
return None
|
return None
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt:
|
||||||
print("Aborted by User, exiting")
|
print("Aborted by User, exiting")
|
||||||
rmfile(file_name)
|
rmfile(file_name)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -1327,11 +1330,11 @@ def get_installed_vstool_version(installed_path):
|
|||||||
class Tool(object):
|
class Tool(object):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
# Convert the dictionary representation of the tool in 'data' to members of this class for convenience.
|
# Convert the dictionary representation of the tool in 'data' to members of this class for convenience.
|
||||||
for key in data:
|
for key, value in data.items():
|
||||||
if sys.version_info < (3,) and isinstance(data[key], unicode):
|
# Python2 compat, convert unicode to str
|
||||||
setattr(self, key, data[key].encode('Latin-1'))
|
if sys.version_info < (3,) and isinstance(value, unicode): # noqa
|
||||||
else:
|
value = value.encode('Latin-1')
|
||||||
setattr(self, key, data[key])
|
setattr(self, key, value)
|
||||||
|
|
||||||
# Cache the name ID of this Tool (these are read very often)
|
# Cache the name ID of this Tool (these are read very often)
|
||||||
self.name = self.id + '-' + self.version
|
self.name = self.id + '-' + self.version
|
||||||
@@ -1638,7 +1641,6 @@ class Tool(object):
|
|||||||
def cleanup_temp_install_files(self):
|
def cleanup_temp_install_files(self):
|
||||||
url = self.download_url()
|
url = self.download_url()
|
||||||
if url.endswith(ARCHIVE_SUFFIXES):
|
if url.endswith(ARCHIVE_SUFFIXES):
|
||||||
file_name = url.split('/')[-1]
|
|
||||||
download_target = get_download_target(url, zips_subdir, getattr(self, 'zipfile_prefix', ''))
|
download_target = get_download_target(url, zips_subdir, getattr(self, 'zipfile_prefix', ''))
|
||||||
if VERBOSE: print("Deleting temporary zip file " + download_target)
|
if VERBOSE: print("Deleting temporary zip file " + download_target)
|
||||||
rmfile(download_target)
|
rmfile(download_target)
|
||||||
@@ -1780,7 +1782,7 @@ def get_emscripten_releases_tot():
|
|||||||
'tbz2' if not WINDOWS else 'zip'
|
'tbz2' if not WINDOWS else 'zip'
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
u = urlopen(url)
|
urlopen(url)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
return release
|
return release
|
||||||
@@ -1951,8 +1953,11 @@ def load_releases_versions():
|
|||||||
|
|
||||||
|
|
||||||
def is_string(s):
|
def is_string(s):
|
||||||
if sys.version_info[0] >= 3:
|
# Python3 compat
|
||||||
return isinstance(s, str)
|
try:
|
||||||
|
basestring
|
||||||
|
except NameError:
|
||||||
|
basestring = str
|
||||||
return isinstance(s, basestring)
|
return isinstance(s, basestring)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
test.py
15
test.py
@@ -4,19 +4,21 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
|
|
||||||
|
|
||||||
def listify(x):
|
def listify(x):
|
||||||
if type(x) == list or type(x) == tuple:
|
if type(x) == list or type(x) == tuple:
|
||||||
return x
|
return x
|
||||||
return [x]
|
return [x]
|
||||||
|
|
||||||
|
|
||||||
def check_call(cmd):
|
def check_call(cmd):
|
||||||
subprocess.check_call(shlex.split(cmd))
|
subprocess.check_call(shlex.split(cmd))
|
||||||
|
|
||||||
|
|
||||||
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
|
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
|
||||||
stdout = subprocess.check_output(cmd.split(' '), stderr=stderr)
|
stdout = subprocess.check_output(cmd.split(' '), stderr=stderr)
|
||||||
if expected:
|
if expected:
|
||||||
@@ -26,12 +28,14 @@ def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
|
|||||||
for x in listify(unexpected):
|
for x in listify(unexpected):
|
||||||
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
|
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
|
||||||
|
|
||||||
|
|
||||||
def failing_call_with_output(cmd, expected):
|
def failing_call_with_output(cmd, expected):
|
||||||
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE)
|
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE)
|
||||||
stdout, stderr = proc.communicate()
|
stdout, stderr = proc.communicate()
|
||||||
assert proc.returncode, 'call must have failed'
|
assert proc.returncode, 'call must have failed'
|
||||||
assert expected in stdout, 'call did not have the right output'
|
assert expected in stdout, 'call did not have the right output'
|
||||||
|
|
||||||
|
|
||||||
def hack_emsdk(marker, replacement):
|
def hack_emsdk(marker, replacement):
|
||||||
src = open('emsdk.py').read()
|
src = open('emsdk.py').read()
|
||||||
assert marker in src
|
assert marker in src
|
||||||
@@ -40,6 +44,7 @@ def hack_emsdk(marker, replacement):
|
|||||||
open(name, 'w').write(src)
|
open(name, 'w').write(src)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
# Set up
|
# Set up
|
||||||
|
|
||||||
open('hello_world.cpp', 'w').write('int main() {}')
|
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')
|
print('building proper system libraries')
|
||||||
|
|
||||||
|
|
||||||
def test_lib_building(prefix, use_asmjs_optimizer):
|
def test_lib_building(prefix, use_asmjs_optimizer):
|
||||||
def test_build(args, expected=None, unexpected=None):
|
def test_build(args, expected=None, unexpected=None):
|
||||||
checked_call_with_output(prefix + '/emscripten/emcc hello_world.cpp' + args,
|
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.']
|
first_time_system_libs = ['generating system library: libdlmalloc.']
|
||||||
|
|
||||||
test_build('', expected=first_time_system_libs,
|
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(' -O2', unexpected=unexpected_system_libs + first_time_system_libs)
|
||||||
test_build(' -s WASM=0', 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_build(' -O2 -s WASM=0', unexpected=unexpected_system_libs + first_time_system_libs)
|
||||||
|
|
||||||
|
|
||||||
test_lib_building('fastcomp', use_asmjs_optimizer=True)
|
test_lib_building('fastcomp', use_asmjs_optimizer=True)
|
||||||
|
|
||||||
print('update')
|
print('update')
|
||||||
@@ -160,11 +167,11 @@ check_call('./emsdk update')
|
|||||||
|
|
||||||
print('verify downloads exist for all OSes')
|
print('verify downloads exist for all OSes')
|
||||||
latest_hash = TAGS['releases'][TAGS['latest']]
|
latest_hash = TAGS['releases'][TAGS['latest']]
|
||||||
for os, suffix in [
|
for osname, suffix in [
|
||||||
('linux', 'tbz2'),
|
('linux', 'tbz2'),
|
||||||
('mac', 'tbz2'),
|
('mac', 'tbz2'),
|
||||||
('win', 'zip')
|
('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),
|
print(' url: ' + url),
|
||||||
check_call('wget ' + url)
|
check_call('wget ' + url)
|
||||||
|
|||||||
Reference in New Issue
Block a user