Skip to content

Commit

Permalink
Add mass-compile ability to filter by key existence. (#19885)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc authored Feb 19, 2023
1 parent 48a79b0 commit 1283863
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/python/qmk/cli/mass_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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')
Expand All @@ -116,6 +117,12 @@ def f(e):

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:
Expand Down

0 comments on commit 1283863

Please sign in to comment.