Skip to content
Snippets Groups Projects
Commit e402bad5 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

bin: rewrite `diff-result` with `click`

This is much simpler and more powerful than rolling it by hand.
parent d82a0b5b
No related branches found
No related tags found
1 merge request!23Use click for argument parsing, etc.
#!/usr/bin/env python3
#
# Small tool to compare two results
import argparse
import collections
......@@ -5,5 +2,6 @@
import collections
import sys
import click
import poulpe
......@@ -7,26 +5,6 @@
import poulpe
err = poulpe.err
def compare(old_path, new_path, full=False):
old = poulpe.get_data(old_path)
if old is None:
err(f'old file not found: {old_path}')
return 1
new = poulpe.get_data(new_path)
if new is None:
err(f'new file not found: {new_path}')
return 1
if full:
full_compare(old, new)
else:
simple_compare(old, new)
return 0
def simple_compare(old, new):
old_median = old['result']['time']['median']
......@@ -37,8 +15,6 @@
print(f"{old_median:.4f} -> {new_median:.4f}: {diff:.4f} ({ratio:.2f})")
return 0
def _linear_data(data, prefix=""):
"""call to display data"""
......@@ -77,6 +53,5 @@
else:
n = v[1]
print(f"{k}: {o} -> {n}")
return 0
......@@ -81,5 +56,11 @@
def _parsers():
cmd_parser = argparse.ArgumentParser(prog='poulpe-bin-env-util')
@click.command(no_args_is_help=True)
@click.argument("old_result", type=click.Path(exists=True, dir_okay=False))
@click.argument("new_result", type=click.Path(exists=True, dir_okay=False))
@click.option(
"--full", is_flag=True, default=False, help="also show the unchanged parts"
)
def diff_result(old_result, new_result, full):
"""Small tool to compare two results together
......@@ -85,10 +66,9 @@
cmd_parser.add_argument(
'OLD_RESULT',
help="path to the old result",
)
cmd_parser.add_argument(
'NEW_RESULT',
help="path to the new result",
)
\b
ARGS:
<OLD_RESULT> is the path the old result
<NEW_RESULT> is the path the old result
"""
old = poulpe.get_data(old_result)
new = poulpe.get_data(new_result)
......@@ -94,13 +74,8 @@
cmd_parser.add_argument('--full', action='store_const', const=True)
return cmd_parser
def main(args):
parser = _parsers()
param = parser.parse_args(args)
ret = compare(param.OLD_RESULT, param.NEW_RESULT, full=param.full)
return ret
if full:
full_compare(old, new)
else:
simple_compare(old, new)
if __name__ == "__main__":
......@@ -104,6 +79,4 @@
if __name__ == "__main__":
ret = main(sys.argv[1:])
assert ret is not None
sys.exit(ret)
diff_result()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment