summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-30 03:27:41 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-11-30 11:33:45 -0800
commitc5d8cf8eb6a6e84347b9379945f308f29a2fe5cb (patch)
tree306901036624b604e0d7d7c0e33c6d10ec39b713
parentd43a4be0d291d2cb1fb4f5a9353b509e87f849eb (diff)
Use pylint.
-rwxr-xr-xbuild_extra/rust/get_rustc_info.py2
-rwxr-xr-xtools/benchmark.py5
-rwxr-xr-xtools/deno_dir_test.py5
-rwxr-xr-xtools/gcloud_upload.py2
-rwxr-xr-xtools/http_server.py8
-rwxr-xr-xtools/lint.py6
-rwxr-xr-xtools/permission_prompt_test.py6
-rw-r--r--tools/repl_test.py8
-rwxr-xr-xtools/setup.py6
-rw-r--r--tools/setup_test.py10
-rw-r--r--tools/sha256sum.py8
-rwxr-xr-xtools/sync_third_party.py3
-rwxr-xr-xtools/test_format.py4
-rw-r--r--tools/third_party.py26
-rwxr-xr-xtools/throughput_benchmark.py9
-rwxr-xr-xtools/unit_tests.py4
-rw-r--r--tools/util.py31
-rw-r--r--tools/util_test.py3
18 files changed, 93 insertions, 53 deletions
diff --git a/build_extra/rust/get_rustc_info.py b/build_extra/rust/get_rustc_info.py
index 1b61bdbc0..66751c20b 100755
--- a/build_extra/rust/get_rustc_info.py
+++ b/build_extra/rust/get_rustc_info.py
@@ -48,7 +48,7 @@ def get_ldflags(rustc_args):
# On Posix systems, this file is directly executable thanks to it's shebang.
# On Windows, we use a .cmd wrapper file.
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"
else:
rustc_linker = __file__
diff --git a/tools/benchmark.py b/tools/benchmark.py
index 760bad100..fe71cc88e 100755
--- a/tools/benchmark.py
+++ b/tools/benchmark.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# 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
# http://localhost:4545/website
@@ -49,7 +50,7 @@ def import_data_from_gh_pages():
"https://github.com/denoland/deno.git", "gh-pages"
])
shutil.copy(gh_pages_data_file, all_data_file)
- except:
+ except ValueError:
write_json(all_data_file, []) # writes empty json data
diff --git a/tools/deno_dir_test.py b/tools/deno_dir_test.py
index bb07b7544..9f53cf3b9 100755
--- a/tools/deno_dir_test.py
+++ b/tools/deno_dir_test.py
@@ -40,9 +40,12 @@ def run_deno(deno_exe, deno_dir=None):
run(cmd, quiet=True, env=deno_dir_env)
+USAGE = "./tools/deno_dir_test.py target/debug/deno target/debug/.deno_dir"
+
+
def main(argv):
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)
deno_dir_test(argv[1], argv[2])
diff --git a/tools/gcloud_upload.py b/tools/gcloud_upload.py
index ed9c48ec8..b919a1ed9 100755
--- a/tools/gcloud_upload.py
+++ b/tools/gcloud_upload.py
@@ -14,7 +14,7 @@ from third_party import tp
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)
diff --git a/tools/http_server.py b/tools/http_server.py
index 065635c6f..f9820ff19 100755
--- a/tools/http_server.py
+++ b/tools/http_server.py
@@ -62,7 +62,7 @@ def redirect_server():
Handler = RedirectHandler
SocketServer.TCPServer.allow_reuse_address = True
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)
return s
@@ -82,7 +82,7 @@ def spawn():
return thread
-if __name__ == '__main__':
+def main():
try:
thread = spawn()
while thread.is_alive():
@@ -90,3 +90,7 @@ if __name__ == '__main__':
except KeyboardInterrupt:
pass
sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tools/lint.py b/tools/lint.py
index f163a3264..e297c0478 100755
--- a/tools/lint.py
+++ b/tools/lint.py
@@ -3,7 +3,8 @@
# Does google-lint on c++ files and ts-lint on typescript files
import os
-from util import enable_ansi_colors, run
+import sys
+from util import enable_ansi_colors, run, find_exts
enable_ansi_colors()
@@ -24,3 +25,6 @@ run([
"node", tslint, "./js/**/*_test.ts", "./tests/**/*.ts", "--exclude",
"**/gen/**/*.ts", "--project", "tsconfig.json"
])
+
+run([sys.executable, "third_party/depot_tools/pylint.py"] +
+ find_exts(["tools", "build_extra"], [".py"], skip=["tools/clang"]))
diff --git a/tools/permission_prompt_test.py b/tools/permission_prompt_test.py
index 2bc24d12c..7f0ae1c97 100755
--- a/tools/permission_prompt_test.py
+++ b/tools/permission_prompt_test.py
@@ -138,6 +138,10 @@ def permission_prompt_test(deno_exe):
p.test_net_no()
-if __name__ == "__main__":
+def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
permission_prompt_test(deno_exe)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/repl_test.py b/tools/repl_test.py
index ce3db8953..afce192f5 100644
--- a/tools/repl_test.py
+++ b/tools/repl_test.py
@@ -35,7 +35,7 @@ class Repl(object):
except CalledProcessError as e:
p.kill()
p.wait()
- raise
+ raise e
retcode = p.poll()
# Ignore Windows CRLF (\r\n).
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()
-if __name__ == "__main__":
+def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
repl_tests(deno_exe)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/setup.py b/tools/setup.py
index 44c183553..8660ee6d7 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -94,9 +94,9 @@ def write_gn_args(args_filename, args):
assert gn_args_are_generated(lines) # With header -> generated.
# Ensure the directory where args.gn goes exists.
- dir = os.path.dirname(args_filename)
- if not os.path.isdir(dir):
- os.makedirs(dir)
+ d = os.path.dirname(args_filename)
+ if not os.path.isdir(d):
+ os.makedirs(d)
with open(args_filename, "w") as f:
f.write("\n".join(lines) + "\n")
diff --git a/tools/setup_test.py b/tools/setup_test.py
index 15dff00fa..bc0a9ecba 100644
--- a/tools/setup_test.py
+++ b/tools/setup_test.py
@@ -40,22 +40,22 @@ def read_gn_args_test():
def write_gn_args_test():
# Build a nonexistent path; write_gn_args() should call mkdir as needed.
- dir = mktemp()
- filename = os.path.join(dir, "args.gn")
- assert not os.path.exists(dir)
+ d = mktemp()
+ filename = os.path.join(d, "args.gn")
+ assert not os.path.exists(d)
assert not os.path.exists(filename)
# Write some args.
args = ['lalala=42', 'foo_bar_baz="lorem ipsum dolor#amet"']
write_gn_args(filename, args)
# Directory and args file should now be created.
- assert os.path.isdir(dir)
+ assert os.path.isdir(d)
assert os.path.isfile(filename)
# Validate that the right contents were written.
(check_args, hand_edited) = read_gn_args(filename)
assert check_args == args
assert hand_edited == False
# Clean up.
- rmtree(dir)
+ rmtree(d)
def setup_test():
diff --git a/tools/sha256sum.py b/tools/sha256sum.py
index d3273d5ba..139368e89 100644
--- a/tools/sha256sum.py
+++ b/tools/sha256sum.py
@@ -55,15 +55,15 @@ def main():
hasher = sha256()
for data in args.input:
hasher.update(data)
- hash = hasher.hexdigest()
+ h = hasher.hexdigest()
# 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):
- with open(filename, "rb") as file:
- return file.read()
+ with open(filename, "rb") as f:
+ return f.read()
if __name__ == '__main__':
diff --git a/tools/sync_third_party.py b/tools/sync_third_party.py
index 5fe78c407..4205c4883 100755
--- a/tools/sync_third_party.py
+++ b/tools/sync_third_party.py
@@ -3,7 +3,8 @@
# Run this script if you are changing Deno's dependencies.
# To update the deno_third_party git repo after running this, try the following:
# 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 util
diff --git a/tools/test_format.py b/tools/test_format.py
index 5e93286b6..a0d5ba08e 100755
--- a/tools/test_format.py
+++ b/tools/test_format.py
@@ -7,7 +7,7 @@ import sys
import subprocess
-def main(argv):
+def main():
util.run([sys.executable, "tools/format.py"])
output = util.run_output(
["git", "status", "-uno", "--porcelain", "--ignore-submodules"])
@@ -18,4 +18,4 @@ def main(argv):
if __name__ == '__main__':
- main(sys.argv)
+ main()
diff --git a/tools/third_party.py b/tools/third_party.py
index 46a9cf82e..d7b587845 100644
--- a/tools/third_party.py
+++ b/tools/third_party.py
@@ -34,7 +34,9 @@ python_site_env = None
# Creates/modifies an environment so python can find packages that are bundled
# 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
# 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
# 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.
env = python_env(env=env, merge_env=merge_env)
# 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.
# We're not using Google's internal infrastructure.
@@ -89,7 +93,7 @@ def fix_symlinks():
# Ensure the third_party directory exists.
try:
os.makedirs(third_party_path)
- except:
+ except OSError:
pass
# 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)
# 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
- # in the root repo while their target is in the third_party repo.
+ # and it's target are in different repos. Here we fix the symlinks that
+ # 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/v8/buildtools", root("buildtools"), True)
remove_and_symlink("third_party/v8/build_overrides",
@@ -120,9 +124,9 @@ def run_yarn():
# Run Cargo to install Rust dependencies.
def run_cargo():
- # Deletes the cargo index lockfile; it appears that cargo itself doesn't do it.
- # If the lockfile ends up in the git repo, it'll make cargo hang for everyone
- # else who tries to run sync_third_party.
+ # Deletes the cargo index lockfile; it appears that cargo itself doesn't do
+ # it. If the lockfile ends up in the git repo, it'll make cargo hang for
+ # everyone else who tries to run sync_third_party.
def delete_lockfile():
lockfiles = find_exts([path.join(rust_crates_path, "registry/index")],
['.cargo-index-lock'])
@@ -186,7 +190,7 @@ def run_gclient_sync():
# Rename depot_tools to depot_tools_temp.
try:
os.rename(depot_tools_path, depot_tools_temp_path)
- except:
+ except OSError:
# If renaming failed, and the depot_tools_temp directory already exists,
# 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.
@@ -204,7 +208,7 @@ def run_gclient_sync():
'DEPOT_TOOLS_UPDATE': "0",
'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)
# Delete the depot_tools_temp directory, but not before verifying that
diff --git a/tools/throughput_benchmark.py b/tools/throughput_benchmark.py
index 457f50bae..7afd3cb81 100755
--- a/tools/throughput_benchmark.py
+++ b/tools/throughput_benchmark.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# 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
# http://localhost:4545/website
@@ -44,7 +45,7 @@ def tcp(deno_exe, megs):
echo_server.kill()
-if __name__ == '__main__':
+def main():
deno_exe = sys.argv[1]
megs = int(sys.argv[2])
if not deno_exe or not megs:
@@ -52,3 +53,7 @@ if __name__ == '__main__':
sys.exit(1)
secs = tcp(sys.argv[1], megs)
print secs, "seconds"
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tools/unit_tests.py b/tools/unit_tests.py
index 47dfcf886..8b36fec44 100755
--- a/tools/unit_tests.py
+++ b/tools/unit_tests.py
@@ -29,7 +29,9 @@ def run_unit_test2(cmd):
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
run_unit_test2(cmd)
diff --git a/tools/util.py b/tools/util.py
index 8c126bd83..b77f17282 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -14,10 +14,12 @@ executable_suffix = ".exe" if os.name == "nt" else ""
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:
env = os.environ
env = env.copy()
+ if merge_env is None:
+ merge_env = {}
for key in merge_env.keys():
env[key] = merge_env[key]
return env
@@ -25,19 +27,21 @@ def make_env(merge_env={}, env=None):
def add_env_path(add, env, key="PATH", prepend=False):
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:
dirs_left, dirs_right = dirs_right, dirs_left
- for dir in dirs_right:
- if not dir in dirs_left:
- dirs_left += [dir]
+ for d in dirs_right:
+ if not d in dirs_left:
+ dirs_left += [d]
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])
if not quiet:
print " ".join(args)
@@ -48,7 +52,9 @@ def run(args, quiet=False, cwd=None, env=None, merge_env={}):
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])
if not quiet:
print " ".join(args)
@@ -92,7 +98,7 @@ def remove_and_symlink(target, name, target_is_dir=False):
os.rmdir(name)
else:
os.unlink(name)
- except:
+ except OSError:
pass
symlink(target, name, target_is_dir)
@@ -146,7 +152,9 @@ def touch(fname):
# * Recursive glob doesn't exist in python 2.7.
# * On windows, `os.walk()` unconditionally follows symlinks.
# 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(extensions, list)
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.
def raise_if(error_result):
- def check(result, func, args):
+ def check(result, _func, args):
if result == error_result:
raise ctypes.WinError(ctypes.get_last_error())
return args
@@ -321,7 +329,7 @@ def enable_ansi_colors_win10():
# Try to set the flag that controls ANSI escape code support.
try:
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:
return False # Not supported, likely an older version of Windows.
raise
@@ -332,7 +340,6 @@ def enable_ansi_colors_win10():
def parse_unit_test_output(output, print_to_stdout):
- first = True
expected = None
actual = None
result = None
diff --git a/tools/util_test.py b/tools/util_test.py
index 24fd2eba1..bf2b92b5a 100644
--- a/tools/util_test.py
+++ b/tools/util_test.py
@@ -21,7 +21,8 @@ def pattern_match_test():
# Iterate through the fixture lists, testing each one
for (pattern, string, expected) in fixtures:
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)
assert pattern_match("foo[BAR]baz", "foobarbaz",