forked from Imagelibrary/littlefs
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:
@@ -211,7 +211,9 @@ def collect(csv_paths, defines=[]):
|
||||
if k not in fields)
|
||||
for r in reader:
|
||||
# filter by matching defines
|
||||
if not all(k in r and r[k] in vs for k, vs in defines):
|
||||
if not all(any(fnmatch.fnmatchcase(r.get(k, ''), v)
|
||||
for v in vs)
|
||||
for k, vs in defines):
|
||||
continue
|
||||
|
||||
results.append(r)
|
||||
@@ -225,7 +227,9 @@ def fold(results, by=None, x=None, y=None, defines=[]):
|
||||
if defines:
|
||||
results_ = []
|
||||
for r in results:
|
||||
if all(k in r and r[k] in vs for k, vs in defines):
|
||||
if all(any(fnmatch.fnmatchcase(r.get(k, ''), v)
|
||||
for v in vs)
|
||||
for k, vs in defines):
|
||||
results_.append(r)
|
||||
results = results_
|
||||
|
||||
@@ -1367,7 +1371,7 @@ if __name__ == "__main__":
|
||||
)(*x.split('=', 1)),
|
||||
action='append',
|
||||
help="Only include results where this field is this value. May "
|
||||
"include comma-separated options.")
|
||||
"include comma-separated options and globs.")
|
||||
parser.add_argument(
|
||||
'-L', '--add-label',
|
||||
dest='labels',
|
||||
|
||||
Reference in New Issue
Block a user