From 58d8b632721ea93344639395ae60f2d017aac02d Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sun, 7 Feb 2021 03:09:43 -0500 Subject: [PATCH] [tools] Format code --- tools/fmt.py | 1 - tools/format_trace.py | 9 ++++++--- tools/lit.py | 18 ++++++++---------- tools/run.py | 20 +++++++++----------- tools/trace.py | 9 ++++++--- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/tools/fmt.py b/tools/fmt.py index d7d0563..ac1bfc5 100644 --- a/tools/fmt.py +++ b/tools/fmt.py @@ -1,6 +1,5 @@ import sys - IS_TTY = sys.stdout.isatty() diff --git a/tools/format_trace.py b/tools/format_trace.py index 6343b1b..fc9c3b7 100755 --- a/tools/format_trace.py +++ b/tools/format_trace.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import argparse -import sys import subprocess +import sys def get_syms(program): @@ -15,7 +15,7 @@ def get_syms(program): for line in result.stdout.split("\n"): if not line.strip(): continue - addr, _, name = line.split(' ', 2) + addr, _, name = line.split(" ", 2) if name.startswith("ivy_builtin$"): name = name.split("$", 2)[1] syms[addr] = name @@ -24,6 +24,7 @@ def get_syms(program): def handle_trace(lines, syms={}, only_debug=False): objs = {} + def obj(x): if int(x, 16) % 2 == 1: return int(x, 16) >> 1 @@ -70,7 +71,9 @@ if __name__ == "__main__": parser.add_argument("program", help="The program that produced the trace") parser.add_argument("trace", help="A file containing the trace") parser.add_argument( - "-d", "--only-debug", action="store_true", + "-d", + "--only-debug", + action="store_true", help="If set, only print the DEBUG outputs", ) if len(sys.argv) == 1: diff --git a/tools/lit.py b/tools/lit.py index 3648c04..7821dd6 100755 --- a/tools/lit.py +++ b/tools/lit.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 import argparse import os +import shlex import subprocess import sys -import shlex from pathlib import Path -from fmt import green, yellow, red - +from fmt import green, red, yellow ROOT = Path(__file__).parent.parent TOOLS = ROOT / "tools" @@ -54,12 +53,12 @@ def split_seq(seq, split): def run_test(source, pipeline, verbose=False, PATH=None): s = shlex.shlex(pipeline, posix=True, punctuation_chars=True) s.whitespace_split = True - pipeline = list(split_seq(s, '|')) + pipeline = list(split_seq(s, "|")) env = {} if PATH: env["PATH"] = PATH - print(f"{relative(source):<72}", end='', flush=True) + print(f"{relative(source):<72}", end="", flush=True) next_stdin = subprocess.PIPE first_process = None processes = [] @@ -80,7 +79,7 @@ def run_test(source, pipeline, verbose=False, PATH=None): any_failed |= process.returncode != 0 os.close(stderr) if any_failed: - print(red('FAIL')) + print(red("FAIL")) if verbose: print(yellow("stdout:")) for line in processes[-1].stdout: @@ -92,11 +91,10 @@ def run_test(source, pipeline, verbose=False, PATH=None): print() return False else: - print(green('PASS')) + print(green("PASS")) return True - def report(tests): passes = [path for path, status in tests.items() if status == "PASS"] failures = [path for path, status in tests.items() if status == "FAIL"] @@ -120,8 +118,8 @@ FAIL: {len(failures)} def main(): parser = argparse.ArgumentParser() - parser.add_argument("tests", nargs='+') - parser.add_argument("-v", "--verbose", action='store_true') + parser.add_argument("tests", nargs="+") + parser.add_argument("-v", "--verbose", action="store_true") args = parser.parse_args() tests = {} PATH = ":".join([os.getenv("PATH"), str(TOOLS), str(TARGET_RELEASE)]) diff --git a/tools/run.py b/tools/run.py index 16e1717..72030d1 100755 --- a/tools/run.py +++ b/tools/run.py @@ -2,38 +2,36 @@ import argparse import subprocess import tempfile -from pathlib import Path - import trace - +from pathlib import Path root = Path(__file__).parent.parent -ivy = root / 'target' / 'release' / 'ivy' -library_path = root / 'rt' / 'target' / 'release' +ivy = root / "target" / "release" / "ivy" +library_path = root / "rt" / "target" / "release" def compile(source, output): subprocess.run( - [ivy, source, '-o', output], - env={'LIBRARY_PATH': library_path}, + [ivy, source, "-o", output], + env={"LIBRARY_PATH": library_path}, check=True, ) def run(script, only_debug=True): with tempfile.TemporaryDirectory() as d: - binary = Path(d) / 'a.out' + binary = Path(d) / "a.out" compile(script, output=binary) trace.trace(binary, only_debug) def main(): parser = argparse.ArgumentParser() - parser.add_argument('script') - parser.add_argument('-v', '--verbose', action='store_true') + parser.add_argument("script") + parser.add_argument("-v", "--verbose", action="store_true") args = parser.parse_args() run(args.script, not args.verbose) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/tools/trace.py b/tools/trace.py index b515667..97239ba 100755 --- a/tools/trace.py +++ b/tools/trace.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import argparse -import format_trace import subprocess import sys +import format_trace + def get_trace(command): result = subprocess.run( @@ -31,7 +32,9 @@ def main(): help="The command to execute.", ) parser.add_argument( - "-d", "--only-debug", action="store_true", + "-d", + "--only-debug", + action="store_true", help="If set, only print the DEBUG outputs", ) if len(sys.argv) <= 1: @@ -41,5 +44,5 @@ def main(): trace(args.command, args.only_debug) -if __name__ == '__main__': +if __name__ == "__main__": main() -- 2.47.0