1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -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 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__

View file

@ -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

View file

@ -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])

View file

@ -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)

View file

@ -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()

View file

@ -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"]))

View file

@ -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()

View file

@ -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()

View file

@ -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")

View file

@ -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():

View file

@ -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__':

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -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)

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__)))
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

View file

@ -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",