|
4 | 4 | import functools
|
5 | 5 | import fnmatch
|
6 | 6 | import logging
|
7 |
| -import multiprocessing |
8 | 7 | import re
|
9 | 8 | from typing import List, Tuple
|
10 | 9 | from dotty_dict import dotty
|
11 | 10 | from milc import cli
|
12 | 11 |
|
| 12 | +from qmk.util import parallel_map |
13 | 13 | from qmk.info import keymap_json
|
14 | 14 | import qmk.keyboard
|
15 | 15 | import qmk.keymap
|
@@ -78,17 +78,16 @@ def _expand_keymap_target(keyboard: str, keymap: str, all_keyboards: List[str] =
|
78 | 78 | all_keyboards = qmk.keyboard.list_keyboards()
|
79 | 79 |
|
80 | 80 | if keyboard == 'all':
|
81 |
| - with multiprocessing.Pool() as pool: |
82 |
| - if keymap == 'all': |
83 |
| - cli.log.info('Retrieving list of all keyboards and keymaps...') |
84 |
| - targets = [] |
85 |
| - for kb in pool.imap_unordered(_all_keymaps, all_keyboards): |
86 |
| - targets.extend(kb) |
87 |
| - return targets |
88 |
| - else: |
89 |
| - cli.log.info(f'Retrieving list of keyboards with keymap "{keymap}"...') |
90 |
| - keyboard_filter = functools.partial(_keymap_exists, keymap=keymap) |
91 |
| - return [(kb, keymap) for kb in filter(lambda e: e is not None, pool.imap_unordered(keyboard_filter, all_keyboards))] |
| 81 | + if keymap == 'all': |
| 82 | + cli.log.info('Retrieving list of all keyboards and keymaps...') |
| 83 | + targets = [] |
| 84 | + for kb in parallel_map(_all_keymaps, all_keyboards): |
| 85 | + targets.extend(kb) |
| 86 | + return targets |
| 87 | + else: |
| 88 | + cli.log.info(f'Retrieving list of keyboards with keymap "{keymap}"...') |
| 89 | + keyboard_filter = functools.partial(_keymap_exists, keymap=keymap) |
| 90 | + return [(kb, keymap) for kb in filter(lambda e: e is not None, parallel_map(keyboard_filter, all_keyboards))] |
92 | 91 | else:
|
93 | 92 | if keymap == 'all':
|
94 | 93 | keyboard = qmk.keyboard.resolve_keyboard(keyboard)
|
@@ -117,8 +116,7 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str
|
117 | 116 | targets = [(kb, km, {}) for kb, km in target_list]
|
118 | 117 | else:
|
119 | 118 | cli.log.info('Parsing data for all matching keyboard/keymap combinations...')
|
120 |
| - with multiprocessing.Pool() as pool: |
121 |
| - valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in pool.imap_unordered(_load_keymap_info, target_list)] |
| 119 | + valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in parallel_map(_load_keymap_info, target_list)] |
122 | 120 |
|
123 | 121 | function_re = re.compile(r'^(?P<function>[a-zA-Z]+)\((?P<key>[a-zA-Z0-9_\.]+)(,\s*(?P<value>[^#]+))?\)$')
|
124 | 122 | equals_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$')
|
@@ -179,10 +177,10 @@ def f(e):
|
179 | 177 | return targets
|
180 | 178 |
|
181 | 179 |
|
182 |
| -def search_keymap_targets(keymap='default', filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]: |
| 180 | +def search_keymap_targets(targets: List[Tuple[str, str]] = [('all', 'default')], filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]: |
183 | 181 | """Search for build targets matching the supplied criteria.
|
184 | 182 | """
|
185 |
| - return list(sorted(_filter_keymap_targets(expand_keymap_targets([('all', keymap)]), filters, print_vals), key=lambda e: (e[0], e[1]))) |
| 183 | + return list(sorted(_filter_keymap_targets(expand_keymap_targets(targets), filters, print_vals), key=lambda e: (e[0], e[1]))) |
186 | 184 |
|
187 | 185 |
|
188 | 186 | def search_make_targets(targets: List[str], filters: List[str] = [], print_vals: List[str] = []) -> List[Tuple[str, str, List[Tuple[str, str]]]]:
|
|
0 commit comments