0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

Use pylint.

This commit is contained in:
Ryan Dahl 2018-11-30 03:27:41 -05:00
parent d43a4be0d2
commit c5d8cf8eb6
18 changed files with 93 additions and 53 deletions

View file

@ -48,7 +48,7 @@ def get_ldflags(rustc_args):
# On Posix systems, this file is directly executable thanks to it's shebang. # On Posix systems, this file is directly executable thanks to it's shebang.
# On Windows, we use a .cmd wrapper file. # On Windows, we use a .cmd wrapper file.
if os.name == "nt": if os.name == "nt":
rustc_linker_base, rustc_linker_ext = path.splitext(__file__) rustc_linker_base, _rustc_linker_ext = path.splitext(__file__)
rustc_linker = rustc_linker_base + ".cmd" rustc_linker = rustc_linker_base + ".cmd"
else: else:
rustc_linker = __file__ rustc_linker = __file__

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright 2018 the Deno authors. All rights reserved. MIT license. # Copyright 2018 the Deno authors. All rights reserved. MIT license.
# Performs benchmark and append data to //website/data.json. # Performs benchmark and append data to //website/data.json.
# If //website/data.json doesn't exist, this script tries to import it from gh-pages branch. # If //website/data.json doesn't exist, this script tries to import it from
# gh-pages branch.
# To view the results locally run ./tools/http_server.py and visit # To view the results locally run ./tools/http_server.py and visit
# http://localhost:4545/website # http://localhost:4545/website
@ -49,7 +50,7 @@ def import_data_from_gh_pages():
"https://github.com/denoland/deno.git", "gh-pages" "https://github.com/denoland/deno.git", "gh-pages"
]) ])
shutil.copy(gh_pages_data_file, all_data_file) shutil.copy(gh_pages_data_file, all_data_file)
except: except ValueError:
write_json(all_data_file, []) # writes empty json data write_json(all_data_file, []) # writes empty json data

View file

@ -40,9 +40,12 @@ def run_deno(deno_exe, deno_dir=None):
run(cmd, quiet=True, env=deno_dir_env) run(cmd, quiet=True, env=deno_dir_env)
USAGE = "./tools/deno_dir_test.py target/debug/deno target/debug/.deno_dir"
def main(argv): def main(argv):
if len(sys.argv) != 3: if len(sys.argv) != 3:
print "Usage ./tools/deno_dir_test.py target/debug/deno target/debug/.deno_dir" print "Usage: " + USAGE
sys.exit(1) sys.exit(1)
deno_dir_test(argv[1], argv[2]) deno_dir_test(argv[1], argv[2])

View file

@ -14,7 +14,7 @@ from third_party import tp
def print_usage(): def print_usage():
print "Usage: ./tools/gcloud_upload.py target/release/obj/third_party/v8/libv8.a" print "Usage: ./tools/gcloud_upload.py target/release/libv8.a"
sys.exit(1) sys.exit(1)

View file

@ -62,7 +62,7 @@ def redirect_server():
Handler = RedirectHandler Handler = RedirectHandler
SocketServer.TCPServer.allow_reuse_address = True SocketServer.TCPServer.allow_reuse_address = True
s = SocketServer.TCPServer(("", REDIRECT_PORT), Handler) s = SocketServer.TCPServer(("", REDIRECT_PORT), Handler)
print "Deno redirect server http://localhost:%d/ -> http://localhost:%d/" % ( print "redirect server http://localhost:%d/ -> http://localhost:%d/" % (
REDIRECT_PORT, PORT) REDIRECT_PORT, PORT)
return s return s
@ -82,7 +82,7 @@ def spawn():
return thread return thread
if __name__ == '__main__': def main():
try: try:
thread = spawn() thread = spawn()
while thread.is_alive(): while thread.is_alive():
@ -90,3 +90,7 @@ if __name__ == '__main__':
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
sys.exit(1) sys.exit(1)
if __name__ == '__main__':
main()

View file

@ -3,7 +3,8 @@
# Does google-lint on c++ files and ts-lint on typescript files # Does google-lint on c++ files and ts-lint on typescript files
import os import os
from util import enable_ansi_colors, run import sys
from util import enable_ansi_colors, run, find_exts
enable_ansi_colors() enable_ansi_colors()
@ -24,3 +25,6 @@ run([
"node", tslint, "./js/**/*_test.ts", "./tests/**/*.ts", "--exclude", "node", tslint, "./js/**/*_test.ts", "./tests/**/*.ts", "--exclude",
"**/gen/**/*.ts", "--project", "tsconfig.json" "**/gen/**/*.ts", "--project", "tsconfig.json"
]) ])
run([sys.executable, "third_party/depot_tools/pylint.py"] +
find_exts(["tools", "build_extra"], [".py"], skip=["tools/clang"]))

View file

@ -138,6 +138,10 @@ def permission_prompt_test(deno_exe):
p.test_net_no() p.test_net_no()
if __name__ == "__main__": def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix) deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
permission_prompt_test(deno_exe) permission_prompt_test(deno_exe)
if __name__ == "__main__":
main()

View file

@ -35,7 +35,7 @@ class Repl(object):
except CalledProcessError as e: except CalledProcessError as e:
p.kill() p.kill()
p.wait() p.wait()
raise raise e
retcode = p.poll() retcode = p.poll()
# Ignore Windows CRLF (\r\n). # Ignore Windows CRLF (\r\n).
return out.replace('\r\n', '\n'), err.replace('\r\n', '\n'), retcode return out.replace('\r\n', '\n'), err.replace('\r\n', '\n'), retcode
@ -125,6 +125,10 @@ def repl_tests(deno_exe):
Repl(deno_exe).run() Repl(deno_exe).run()
if __name__ == "__main__": def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix) deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
repl_tests(deno_exe) repl_tests(deno_exe)
if __name__ == "__main__":
main()

View file

@ -94,9 +94,9 @@ def write_gn_args(args_filename, args):
assert gn_args_are_generated(lines) # With header -> generated. assert gn_args_are_generated(lines) # With header -> generated.
# Ensure the directory where args.gn goes exists. # Ensure the directory where args.gn goes exists.
dir = os.path.dirname(args_filename) d = os.path.dirname(args_filename)
if not os.path.isdir(dir): if not os.path.isdir(d):
os.makedirs(dir) os.makedirs(d)
with open(args_filename, "w") as f: with open(args_filename, "w") as f:
f.write("\n".join(lines) + "\n") f.write("\n".join(lines) + "\n")

View file

@ -40,22 +40,22 @@ def read_gn_args_test():
def write_gn_args_test(): def write_gn_args_test():
# Build a nonexistent path; write_gn_args() should call mkdir as needed. # Build a nonexistent path; write_gn_args() should call mkdir as needed.
dir = mktemp() d = mktemp()
filename = os.path.join(dir, "args.gn") filename = os.path.join(d, "args.gn")
assert not os.path.exists(dir) assert not os.path.exists(d)
assert not os.path.exists(filename) assert not os.path.exists(filename)
# Write some args. # Write some args.
args = ['lalala=42', 'foo_bar_baz="lorem ipsum dolor#amet"'] args = ['lalala=42', 'foo_bar_baz="lorem ipsum dolor#amet"']
write_gn_args(filename, args) write_gn_args(filename, args)
# Directory and args file should now be created. # Directory and args file should now be created.
assert os.path.isdir(dir) assert os.path.isdir(d)
assert os.path.isfile(filename) assert os.path.isfile(filename)
# Validate that the right contents were written. # Validate that the right contents were written.
(check_args, hand_edited) = read_gn_args(filename) (check_args, hand_edited) = read_gn_args(filename)
assert check_args == args assert check_args == args
assert hand_edited == False assert hand_edited == False
# Clean up. # Clean up.
rmtree(dir) rmtree(d)
def setup_test(): def setup_test():

View file

@ -55,15 +55,15 @@ def main():
hasher = sha256() hasher = sha256()
for data in args.input: for data in args.input:
hasher.update(data) hasher.update(data)
hash = hasher.hexdigest() h = hasher.hexdigest()
# Format and write to specified out file (or the default, stdout). # Format and write to specified out file (or the default, stdout).
args.outfile.write(args.format % hash) args.outfile.write(args.format % h)
def read_file(filename): def read_file(filename):
with open(filename, "rb") as file: with open(filename, "rb") as f:
return file.read() return f.read()
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -3,7 +3,8 @@
# Run this script if you are changing Deno's dependencies. # Run this script if you are changing Deno's dependencies.
# To update the deno_third_party git repo after running this, try the following: # To update the deno_third_party git repo after running this, try the following:
# cd third_party # cd third_party
# find . -type f | grep -v "\.git" | xargs -I% git add -f --no-warn-embedded-repo "%" # find . -type f | grep -v "\.git" | \
# xargs -I% git add -f --no-warn-embedded-repo "%"
import third_party import third_party
import util import util

View file

@ -7,7 +7,7 @@ import sys
import subprocess import subprocess
def main(argv): def main():
util.run([sys.executable, "tools/format.py"]) util.run([sys.executable, "tools/format.py"])
output = util.run_output( output = util.run_output(
["git", "status", "-uno", "--porcelain", "--ignore-submodules"]) ["git", "status", "-uno", "--porcelain", "--ignore-submodules"])
@ -18,4 +18,4 @@ def main(argv):
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv) main()

View file

@ -34,7 +34,9 @@ python_site_env = None
# Creates/modifies an environment so python can find packages that are bundled # Creates/modifies an environment so python can find packages that are bundled
# in the 'third_party' directory. # in the 'third_party' directory.
def python_env(env=None, merge_env={}, depot_tools_path=depot_tools_path): def python_env(env=None, merge_env=None):
if merge_env is None:
merge_env = {}
global python_site_env global python_site_env
# Use site.addsitedir() to determine which search paths would be considered # Use site.addsitedir() to determine which search paths would be considered
@ -59,12 +61,14 @@ def python_env(env=None, merge_env={}, depot_tools_path=depot_tools_path):
# This function creates or modifies an environment so that it matches the # This function creates or modifies an environment so that it matches the
# expectations of various google tools (gn, gclient, etc). # expectations of various google tools (gn, gclient, etc).
def google_env(env=None, merge_env={}, depot_tools_path=depot_tools_path): def google_env(env=None, merge_env=None, depot_tools_path_=depot_tools_path):
if merge_env is None:
merge_env = {}
# Google tools need the python env too. # Google tools need the python env too.
env = python_env(env=env, merge_env=merge_env) env = python_env(env=env, merge_env=merge_env)
# Depot_tools to be in the PATH, before Python. # Depot_tools to be in the PATH, before Python.
add_env_path(depot_tools_path, env=env, prepend=True) add_env_path(depot_tools_path_, env=env, prepend=True)
if os.name == "nt": # Windows-only enviroment tweaks. if os.name == "nt": # Windows-only enviroment tweaks.
# We're not using Google's internal infrastructure. # We're not using Google's internal infrastructure.
@ -89,7 +93,7 @@ def fix_symlinks():
# Ensure the third_party directory exists. # Ensure the third_party directory exists.
try: try:
os.makedirs(third_party_path) os.makedirs(third_party_path)
except: except OSError:
pass pass
# Make symlinks to Yarn metadata living in the root repo. # Make symlinks to Yarn metadata living in the root repo.
@ -102,8 +106,8 @@ def fix_symlinks():
remove_and_symlink("v8/third_party/markupsafe", tp("markupsafe"), True) remove_and_symlink("v8/third_party/markupsafe", tp("markupsafe"), True)
# On Windows, git doesn't create the right type of symlink if the symlink # On Windows, git doesn't create the right type of symlink if the symlink
# and it's target are in different repos. Here we fix the symlinks that exist # and it's target are in different repos. Here we fix the symlinks that
# in the root repo while their target is in the third_party repo. # exist in the root repo while their target is in the third_party repo.
remove_and_symlink("third_party/node_modules", root("node_modules"), True) remove_and_symlink("third_party/node_modules", root("node_modules"), True)
remove_and_symlink("third_party/v8/buildtools", root("buildtools"), True) remove_and_symlink("third_party/v8/buildtools", root("buildtools"), True)
remove_and_symlink("third_party/v8/build_overrides", remove_and_symlink("third_party/v8/build_overrides",
@ -120,9 +124,9 @@ def run_yarn():
# Run Cargo to install Rust dependencies. # Run Cargo to install Rust dependencies.
def run_cargo(): def run_cargo():
# Deletes the cargo index lockfile; it appears that cargo itself doesn't do it. # Deletes the cargo index lockfile; it appears that cargo itself doesn't do
# If the lockfile ends up in the git repo, it'll make cargo hang for everyone # it. If the lockfile ends up in the git repo, it'll make cargo hang for
# else who tries to run sync_third_party. # everyone else who tries to run sync_third_party.
def delete_lockfile(): def delete_lockfile():
lockfiles = find_exts([path.join(rust_crates_path, "registry/index")], lockfiles = find_exts([path.join(rust_crates_path, "registry/index")],
['.cargo-index-lock']) ['.cargo-index-lock'])
@ -186,7 +190,7 @@ def run_gclient_sync():
# Rename depot_tools to depot_tools_temp. # Rename depot_tools to depot_tools_temp.
try: try:
os.rename(depot_tools_path, depot_tools_temp_path) os.rename(depot_tools_path, depot_tools_temp_path)
except: except OSError:
# If renaming failed, and the depot_tools_temp directory already exists, # If renaming failed, and the depot_tools_temp directory already exists,
# assume that it's still there because a prior run_gclient_sync() call # assume that it's still there because a prior run_gclient_sync() call
# failed half-way, before we got the chance to remove the temp dir. # failed half-way, before we got the chance to remove the temp dir.
@ -204,7 +208,7 @@ def run_gclient_sync():
'DEPOT_TOOLS_UPDATE': "0", 'DEPOT_TOOLS_UPDATE': "0",
'GCLIENT_FILE': root("gclient_config.py") 'GCLIENT_FILE': root("gclient_config.py")
} }
env = google_env(depot_tools_path=depot_tools_temp_path, merge_env=envs) env = google_env(depot_tools_path_=depot_tools_temp_path, merge_env=envs)
run(args, cwd=third_party_path, env=env) run(args, cwd=third_party_path, env=env)
# Delete the depot_tools_temp directory, but not before verifying that # Delete the depot_tools_temp directory, but not before verifying that

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright 2018 the Deno authors. All rights reserved. MIT license. # Copyright 2018 the Deno authors. All rights reserved. MIT license.
# Performs benchmark and append data to //website/data.json. # Performs benchmark and append data to //website/data.json.
# If //website/data.json doesn't exist, this script tries to import it from gh-pages branch. # If //website/data.json doesn't exist, this script tries to import it from
# gh-pages branch.
# To view the results locally run ./tools/http_server.py and visit # To view the results locally run ./tools/http_server.py and visit
# http://localhost:4545/website # http://localhost:4545/website
@ -44,7 +45,7 @@ def tcp(deno_exe, megs):
echo_server.kill() echo_server.kill()
if __name__ == '__main__': def main():
deno_exe = sys.argv[1] deno_exe = sys.argv[1]
megs = int(sys.argv[2]) megs = int(sys.argv[2])
if not deno_exe or not megs: if not deno_exe or not megs:
@ -52,3 +53,7 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
secs = tcp(sys.argv[1], megs) secs = tcp(sys.argv[1], megs)
print secs, "seconds" print secs, "seconds"
if __name__ == '__main__':
main()

View file

@ -29,7 +29,9 @@ def run_unit_test2(cmd):
sys.exit(errcode) sys.exit(errcode)
def run_unit_test(deno_exe, permStr, flags=[]): def run_unit_test(deno_exe, permStr, flags=None):
if flags is None:
flags = []
cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags
run_unit_test2(cmd) run_unit_test2(cmd)

View file

@ -14,10 +14,12 @@ executable_suffix = ".exe" if os.name == "nt" else ""
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
def make_env(merge_env={}, env=None): def make_env(merge_env=None, env=None):
if env is None: if env is None:
env = os.environ env = os.environ
env = env.copy() env = env.copy()
if merge_env is None:
merge_env = {}
for key in merge_env.keys(): for key in merge_env.keys():
env[key] = merge_env[key] env[key] = merge_env[key]
return env return env
@ -25,19 +27,21 @@ def make_env(merge_env={}, env=None):
def add_env_path(add, env, key="PATH", prepend=False): def add_env_path(add, env, key="PATH", prepend=False):
dirs_left = env[key].split(os.pathsep) if key in env else [] dirs_left = env[key].split(os.pathsep) if key in env else []
dirs_right = add.split(os.pathsep) if type(add) is str else add dirs_right = add.split(os.pathsep) if isinstance(add, str) else add
if prepend: if prepend:
dirs_left, dirs_right = dirs_right, dirs_left dirs_left, dirs_right = dirs_right, dirs_left
for dir in dirs_right: for d in dirs_right:
if not dir in dirs_left: if not d in dirs_left:
dirs_left += [dir] dirs_left += [d]
env[key] = os.pathsep.join(dirs_left) env[key] = os.pathsep.join(dirs_left)
def run(args, quiet=False, cwd=None, env=None, merge_env={}): def run(args, quiet=False, cwd=None, env=None, merge_env=None):
if merge_env is None:
merge_env = {}
args[0] = os.path.normpath(args[0]) args[0] = os.path.normpath(args[0])
if not quiet: if not quiet:
print " ".join(args) print " ".join(args)
@ -48,7 +52,9 @@ def run(args, quiet=False, cwd=None, env=None, merge_env={}):
sys.exit(rc) sys.exit(rc)
def run_output(args, quiet=False, cwd=None, env=None, merge_env={}): def run_output(args, quiet=False, cwd=None, env=None, merge_env=None):
if merge_env is None:
merge_env = {}
args[0] = os.path.normpath(args[0]) args[0] = os.path.normpath(args[0])
if not quiet: if not quiet:
print " ".join(args) print " ".join(args)
@ -92,7 +98,7 @@ def remove_and_symlink(target, name, target_is_dir=False):
os.rmdir(name) os.rmdir(name)
else: else:
os.unlink(name) os.unlink(name)
except: except OSError:
pass pass
symlink(target, name, target_is_dir) symlink(target, name, target_is_dir)
@ -146,7 +152,9 @@ def touch(fname):
# * Recursive glob doesn't exist in python 2.7. # * Recursive glob doesn't exist in python 2.7.
# * On windows, `os.walk()` unconditionally follows symlinks. # * On windows, `os.walk()` unconditionally follows symlinks.
# The `skip` parameter should be used to avoid recursing through those. # The `skip` parameter should be used to avoid recursing through those.
def find_exts(directories, extensions, skip=[]): def find_exts(directories, extensions, skip=None):
if skip is None:
skip = []
assert isinstance(directories, list) assert isinstance(directories, list)
assert isinstance(extensions, list) assert isinstance(extensions, list)
skip = [os.path.normpath(i) for i in skip] skip = [os.path.normpath(i) for i in skip]
@ -247,7 +255,7 @@ def enable_ansi_colors_win10():
# Function factory for errcheck callbacks that raise WinError on failure. # Function factory for errcheck callbacks that raise WinError on failure.
def raise_if(error_result): def raise_if(error_result):
def check(result, func, args): def check(result, _func, args):
if result == error_result: if result == error_result:
raise ctypes.WinError(ctypes.get_last_error()) raise ctypes.WinError(ctypes.get_last_error())
return args return args
@ -321,7 +329,7 @@ def enable_ansi_colors_win10():
# Try to set the flag that controls ANSI escape code support. # Try to set the flag that controls ANSI escape code support.
try: try:
SetConsoleMode(conout, mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING) SetConsoleMode(conout, mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
except WindowsError as e: except WindowsError as e: # pylint:disable=undefined-variable
if e.winerror == ERROR_INVALID_PARAMETER: if e.winerror == ERROR_INVALID_PARAMETER:
return False # Not supported, likely an older version of Windows. return False # Not supported, likely an older version of Windows.
raise raise
@ -332,7 +340,6 @@ def enable_ansi_colors_win10():
def parse_unit_test_output(output, print_to_stdout): def parse_unit_test_output(output, print_to_stdout):
first = True
expected = None expected = None
actual = None actual = None
result = None result = None

View file

@ -21,7 +21,8 @@ def pattern_match_test():
# Iterate through the fixture lists, testing each one # Iterate through the fixture lists, testing each one
for (pattern, string, expected) in fixtures: for (pattern, string, expected) in fixtures:
actual = pattern_match(pattern, string) actual = pattern_match(pattern, string)
assert expected == actual, "expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % ( assert expected == actual, \
"expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % (
expected, pattern, string) expected, pattern, string)
assert pattern_match("foo[BAR]baz", "foobarbaz", assert pattern_match("foo[BAR]baz", "foobarbaz",