Typos and cleanup.

This commit is contained in:
Nick Brassel 2023-09-29 11:33:45 +10:00
parent 06316a1cd4
commit 6803275180
No known key found for this signature in database

View File

@ -27,20 +27,19 @@ def _set_log_level(level):
@contextlib.contextmanager @contextlib.contextmanager
def parallelize(parallel): def parallelize(parallel):
with contextlib.suppress(ImportError): if not parallel:
from mpire import WorkerPool yield map
if parallel:
with WorkerPool() as pool:
yield functools.partial(pool.imap_unordered, progress_bar=True)
else:
yield map
return return
if parallel: with contextlib.suppress(ImportError):
with multiprocessing.Pool() as pool: from mpire import WorkerPool
yield pool.imap_unordered with WorkerPool() as pool:
else: yield functools.partial(pool.imap_unordered, progress_bar=True)
yield map return
with multiprocessing.Pool() as pool:
yield pool.imap_unordered
return
@contextlib.contextmanager @contextlib.contextmanager
@ -68,7 +67,7 @@ def _keymap_exists(keyboard, keymap):
def _load_keymap_info(arg0, arg1=None): def _load_keymap_info(arg0, arg1=None):
"""Returns a tuple of (keyboard, keymap, info.json) for the given keyboard/keymap combination. """Returns a tuple of (keyboard, keymap, info.json) for the given keyboard/keymap combination.
Caters for the different unpacking requirements of each variatn of imap_unordered(). Caters for the different unpacking requirements of each variant of map()/imap_unordered().
""" """
with ignore_logging(): with ignore_logging():
if arg1 is None: if arg1 is None:
@ -140,7 +139,6 @@ def _filter_keymap_targets(target_list: List[Tuple[str, str]], filters: List[str
targets = [(kb, km, {}) for kb, km in target_list] targets = [(kb, km, {}) for kb, km in target_list]
else: else:
cli.log.info('Parsing data for all matching keyboard/keymap combinations...') cli.log.info('Parsing data for all matching keyboard/keymap combinations...')
with parallelize(parallel) as map_func: with parallelize(parallel) as map_func:
valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in map_func(_load_keymap_info, target_list)] valid_keymaps = [(e[0], e[1], dotty(e[2])) for e in map_func(_load_keymap_info, target_list)]