Add mass-compile
ability to filter by key existence. (#19885)
This commit is contained in:
parent
48a79b08cc
commit
1283863c0e
1 changed files with 10 additions and 3 deletions
|
@ -60,7 +60,7 @@ def _load_keymap_info(keyboard, keymap):
|
|||
action='append',
|
||||
default=[],
|
||||
help= # noqa: `format-python` and `pytest` don't agree here.
|
||||
"Filter the list of keyboards based on the supplied value in rules.mk. Matches info.json structure, and accepts the format 'features.rgblight=true'. May be passed multiple times, all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here.
|
||||
"Filter the list of keyboards based on the supplied value in rules.mk. Matches info.json structure, and accepts the formats 'features.rgblight=true' or 'exists(matrix_pins.direct)'. May be passed multiple times, all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here.
|
||||
)
|
||||
@cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.")
|
||||
@cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
|
||||
|
@ -95,9 +95,10 @@ def mass_compile(cli):
|
|||
cli.log.info('Parsing data for all matching keyboard/keymap combinations...')
|
||||
valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in pool.starmap(_load_keymap_info, target_list)]
|
||||
|
||||
filter_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$')
|
||||
equals_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$')
|
||||
exists_re = re.compile(r'^exists\((?P<key>[a-zA-Z0-9_\.]+)\)$')
|
||||
for filter_txt in cli.args.filter:
|
||||
f = filter_re.match(filter_txt)
|
||||
f = equals_re.match(filter_txt)
|
||||
if f is not None:
|
||||
key = f.group('key')
|
||||
value = f.group('value')
|
||||
|
@ -116,6 +117,12 @@ def mass_compile(cli):
|
|||
|
||||
valid_keymaps = filter(_make_filter(key, value), valid_keymaps)
|
||||
|
||||
f = exists_re.match(filter_txt)
|
||||
if f is not None:
|
||||
key = f.group('key')
|
||||
cli.log.info(f'Filtering on condition (exists: "{key}")...')
|
||||
valid_keymaps = filter(lambda e: e[2].get(key) is not None, valid_keymaps)
|
||||
|
||||
targets = [(e[0], e[1]) for e in valid_keymaps]
|
||||
|
||||
if len(targets) == 0:
|
||||
|
|
Loading…
Reference in a new issue