scripts: Adopted globs in all field matchers (-D/--define, -c/--compare)

Globs in CLI attrs (-L'*=bs=%(bs)s' for example), have been remarkably
useful. It makes sense to extend this to the other flags that match
against CSV fields, though this does add complexity to a large number of
smaller scripts.

- -D/--define can now use globs when filtering:

    $ ./scripts/code.py lfs.o -Dfunction='lfsr_file_*'

  -D/--define already accepted a comma-separated list of options, so
  extending this to globs makes sense.

  Note this differs from test.py/bench.py's -D/--define. Globbing in
  test.py/bench.py wouldn't really work since -D/--define is generative,
  not matching. But there's already other differences such as integer
  parsing, range, etc. It's not worth making these perfectly consistent
  as they are really two different tools that just happen to look the
  same.

- -c/--compare now matches with globs when finding the compare entry:

    $ ./scripts/code.py lfs.o -c'lfs*_file_sync'

  This is quite a bit less useful that -D/--define, but makes sense for
  consistency.

  Note -c/--compare just chooses the first match. It doesn't really make
  sense to compare against multiple entries.

This raised the question of globs in the field specifiers themselves
(-f'bench_*' for example), but I'm rejecting this for now as I need to
draw the complexity/scope _somewhere_, and I'm worried it's already way
over on the too-complex side.

So, for now, field names must always be specified explicitly. Globbing
field names would add too much complexity. Especially considering how
many flags accept field names in these scripts.
This commit is contained in:
Christopher Haster
2025-05-15 14:28:52 -05:00
parent 55ea13b994
commit 7526b469b9
13 changed files with 151 additions and 42 deletions

View File

@@ -18,6 +18,7 @@ if __name__ == "__main__":
import bisect
import collections as co
import csv
import fnmatch
import functools as ft
import io
import itertools as it
@@ -831,7 +832,9 @@ def fold(Result, results, *,
if defines:
results_ = []
for r in results:
if all(str(getattr(r, k)) in vs for k, vs in defines):
if all(any(fnmatch.fnmatchcase(str(getattr(r, k, '')), v)
for v in vs)
for k, vs in defines):
results_.append(r)
results = results_
@@ -969,7 +972,13 @@ def table(Result, results, diff_results=None, *,
# find compare entry if there is one
if compare:
compare_r = table.get(','.join(str(k) for k in compare))
compare_ = min(
(n for n in table.keys()
if all(fnmatch.fnmatchcase(k, c)
for k, c in it.zip_longest(n.split(','), compare,
fillvalue=''))),
default=compare)
compare_r = table.get(compare_)
# build up our lines
lines = []
@@ -1699,7 +1708,8 @@ if __name__ == "__main__":
k.strip(),
{v.strip() for v in vs.split(',')})
)(*x.split('=', 1)),
help="Only include results where this field is this value.")
help="Only include results where this field is this value. May "
"include comma-separated options and globs.")
class AppendSort(argparse.Action):
def __call__(self, parser, namespace, value, option):
if namespace.sort is None: