mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-08 00:22:44 +00:00
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:
@@ -18,6 +18,7 @@ if __name__ == "__main__":
|
||||
|
||||
import collections as co
|
||||
import csv
|
||||
import fnmatch
|
||||
import functools as ft
|
||||
import io
|
||||
import itertools as it
|
||||
@@ -543,7 +544,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_
|
||||
|
||||
@@ -634,7 +637,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 = []
|
||||
@@ -1156,7 +1165,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:
|
||||
|
||||
Reference in New Issue
Block a user