mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-08 08:32:48 +00:00
scripts: Tweaked -p/--percent to accept the csv file for diffing
This makes the -p/--percent flag a bit more consistent with -d/--diff and -c/--compare, both of which change the printing strategy based on additional context.
This commit is contained in:
@@ -375,10 +375,11 @@ def table(Result, results, diff_results=None, *,
|
||||
by=None,
|
||||
fields=None,
|
||||
sort=None,
|
||||
summary=False,
|
||||
diff=None,
|
||||
percent=None,
|
||||
all=False,
|
||||
percent=False,
|
||||
compare=None,
|
||||
summary=False,
|
||||
**_):
|
||||
all_, all = all, __builtins__.all
|
||||
|
||||
@@ -411,12 +412,12 @@ def table(Result, results, diff_results=None, *,
|
||||
for k in fields)]
|
||||
|
||||
# find compare entry if there is one
|
||||
if compare is not None:
|
||||
if compare:
|
||||
compare_result = table.get(','.join(str(k) for k in compare))
|
||||
|
||||
# sort again, now with diff info, note that python's sort is stable
|
||||
names.sort()
|
||||
if compare is not None:
|
||||
if compare:
|
||||
names.sort(
|
||||
key=lambda n: (
|
||||
table.get(n) == compare_result,
|
||||
@@ -426,7 +427,7 @@ def table(Result, results, diff_results=None, *,
|
||||
getattr(compare_result, k, None))
|
||||
for k in fields)),
|
||||
reverse=True)
|
||||
if diff_results is not None:
|
||||
if diff or percent:
|
||||
names.sort(
|
||||
key=lambda n: tuple(
|
||||
types[k].ratio(
|
||||
@@ -457,12 +458,9 @@ def table(Result, results, diff_results=None, *,
|
||||
' (%d added, %d removed)' % (
|
||||
sum(1 for n in table if n not in diff_table),
|
||||
sum(1 for n in diff_table if n not in table))
|
||||
if diff_results is not None and not percent else '')
|
||||
if diff else '')
|
||||
if not summary else '']
|
||||
if diff_results is None:
|
||||
for k in fields:
|
||||
header.append(k)
|
||||
elif percent:
|
||||
if not diff:
|
||||
for k in fields:
|
||||
header.append(k)
|
||||
else:
|
||||
@@ -479,7 +477,8 @@ def table(Result, results, diff_results=None, *,
|
||||
entry = [name]
|
||||
# normal entry?
|
||||
if ((compare is None or r == compare_result)
|
||||
and diff_results is None):
|
||||
and not percent
|
||||
and not diff):
|
||||
for k in fields:
|
||||
entry.append(
|
||||
(getattr(r, k).table(),
|
||||
@@ -487,7 +486,7 @@ def table(Result, results, diff_results=None, *,
|
||||
if getattr(r, k, None) is not None
|
||||
else types[k].none)
|
||||
# compare entry?
|
||||
elif compare is not None and diff_results is None:
|
||||
elif not percent and not diff:
|
||||
for k in fields:
|
||||
entry.append(
|
||||
(getattr(r, k).table()
|
||||
@@ -500,7 +499,7 @@ def table(Result, results, diff_results=None, *,
|
||||
getattr(r, k, None),
|
||||
getattr(compare_result, k, None)))))
|
||||
# percent entry?
|
||||
elif diff_results is not None and percent:
|
||||
elif not diff:
|
||||
for k in fields:
|
||||
entry.append(
|
||||
(getattr(r, k).table()
|
||||
@@ -513,7 +512,7 @@ def table(Result, results, diff_results=None, *,
|
||||
getattr(r, k, None),
|
||||
getattr(diff_r, k, None)))))
|
||||
# diff entry?
|
||||
elif diff_results is not None:
|
||||
else:
|
||||
for k in fields:
|
||||
entry.append(getattr(diff_r, k).table()
|
||||
if getattr(diff_r, k, None) is not None
|
||||
@@ -537,7 +536,7 @@ def table(Result, results, diff_results=None, *,
|
||||
return entry
|
||||
|
||||
# entries
|
||||
if not summary or compare:
|
||||
if (not summary) or compare:
|
||||
for name in names:
|
||||
r = table.get(name)
|
||||
if diff_results is None:
|
||||
@@ -547,7 +546,7 @@ def table(Result, results, diff_results=None, *,
|
||||
lines.append(table_entry(name, r, diff_r))
|
||||
|
||||
# total, unless we're comparing
|
||||
if not (compare is not None and diff_results is None):
|
||||
if not (compare and not percent and not diff):
|
||||
r = next(iter(fold(Result, results, by=[])), None)
|
||||
if diff_results is None:
|
||||
diff_r = None
|
||||
@@ -640,10 +639,11 @@ def main(obj_paths, *,
|
||||
else CodeResult._fields)})
|
||||
|
||||
# find previous results?
|
||||
if args.get('diff'):
|
||||
diff_results = None
|
||||
if args.get('diff') or args.get('percent'):
|
||||
diff_results = []
|
||||
try:
|
||||
with openio(args['diff']) as f:
|
||||
with openio(args.get('diff') or args.get('percent')) as f:
|
||||
reader = csv.DictReader(f, restval='')
|
||||
for r in reader:
|
||||
# filter by matching defines
|
||||
@@ -669,8 +669,7 @@ def main(obj_paths, *,
|
||||
|
||||
# print table
|
||||
if not args.get('quiet'):
|
||||
table(CodeResult, results,
|
||||
diff_results if args.get('diff') else None,
|
||||
table(CodeResult, results, diff_results,
|
||||
by=by if by is not None else ['function'],
|
||||
fields=fields,
|
||||
sort=sort,
|
||||
@@ -704,18 +703,22 @@ if __name__ == "__main__":
|
||||
parser.add_argument(
|
||||
'-d', '--diff',
|
||||
help="Specify CSV file to diff against.")
|
||||
parser.add_argument(
|
||||
'-p', '--percent',
|
||||
help="Specify CSV file to diff against, but only show precentage "
|
||||
"change, not a full diff.")
|
||||
parser.add_argument(
|
||||
'-a', '--all',
|
||||
action='store_true',
|
||||
help="Show all, not just the ones that changed.")
|
||||
parser.add_argument(
|
||||
'-p', '--percent',
|
||||
action='store_true',
|
||||
help="Only show percentage change, not a full diff.")
|
||||
parser.add_argument(
|
||||
'-c', '--compare',
|
||||
type=lambda x: tuple(v.strip() for v in x.split(',')),
|
||||
help="Compare results to the row matching this by pattern.")
|
||||
parser.add_argument(
|
||||
'-Y', '--summary',
|
||||
action='store_true',
|
||||
help="Only show the total.")
|
||||
parser.add_argument(
|
||||
'-b', '--by',
|
||||
action='append',
|
||||
@@ -752,10 +755,6 @@ if __name__ == "__main__":
|
||||
nargs='?',
|
||||
action=AppendSort,
|
||||
help="Sort by this field, but backwards.")
|
||||
parser.add_argument(
|
||||
'-Y', '--summary',
|
||||
action='store_true',
|
||||
help="Only show the total.")
|
||||
parser.add_argument(
|
||||
'-F', '--source',
|
||||
dest='sources',
|
||||
|
||||
Reference in New Issue
Block a user