Skip to content

Commit 5422dd6

Browse files
committed
shared_bindings_matrix: Run in parallel
.. this makes it take a fraction of the time, at least on systems with a lot of CPU threads. Even on my old laptop with a 2-core CPU it reduces the time from 55s to 27s.
1 parent 5755160 commit 5422dd6

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

docs/shared_bindings_matrix.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import subprocess
2929
import sys
3030

31+
from concurrent.futures import ThreadPoolExecutor
3132

3233
SUPPORTED_PORTS = ['atmel-samd', 'esp32s2', 'litex', 'mimxrt10xx', 'nrf', 'stm']
3334

@@ -131,38 +132,44 @@ def lookup_setting(settings, key, default=''):
131132
key = value[2:-1]
132133
return value
133134

135+
def all_ports_all_boards(ports=SUPPORTED_PORTS):
136+
for port in ports:
137+
138+
port_dir = get_circuitpython_root_dir() / "ports" / port
139+
for entry in (port_dir / "boards").iterdir():
140+
if not entry.is_dir():
141+
continue
142+
yield (port, entry)
143+
134144
def support_matrix_by_board(use_branded_name=True):
135145
""" Compiles a list of the available core modules available for each
136146
board.
137147
"""
138148
base = build_module_map()
139149

140-
boards = dict()
141-
for port in SUPPORTED_PORTS:
142-
150+
def support_matrix(arg):
151+
port, entry = arg
143152
port_dir = get_circuitpython_root_dir() / "ports" / port
144-
for entry in (port_dir / "boards").iterdir():
145-
if not entry.is_dir():
146-
continue
147-
board_modules = []
148-
board_name = entry.name
149-
150-
settings = get_settings_from_makefile(str(port_dir), entry.name)
151-
152-
if use_branded_name:
153-
with open(entry / "mpconfigboard.h") as get_name:
154-
board_contents = get_name.read()
155-
board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)",
156-
board_contents)
157-
if board_name_re:
158-
board_name = board_name_re.group(1).strip('"')
159-
160-
board_modules = []
161-
for module in base:
162-
key = f'CIRCUITPY_{module.upper()}'
163-
if int(lookup_setting(settings, key, '0')):
164-
board_modules.append(base[module]['name'])
165-
boards[board_name] = sorted(board_modules)
153+
settings = get_settings_from_makefile(str(port_dir), entry.name)
154+
155+
if use_branded_name:
156+
with open(entry / "mpconfigboard.h") as get_name:
157+
board_contents = get_name.read()
158+
board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)",
159+
board_contents)
160+
if board_name_re:
161+
board_name = board_name_re.group(1).strip('"')
162+
163+
board_modules = []
164+
for module in base:
165+
key = f'CIRCUITPY_{module.upper()}'
166+
if int(lookup_setting(settings, key, '0')):
167+
board_modules.append(base[module]['name'])
168+
169+
return (board_name, sorted(board_modules))
170+
171+
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
172+
boards = dict(sorted(executor.map(support_matrix, all_ports_all_boards())))
166173

167174
#print(json.dumps(boards, indent=2))
168175
return boards

0 commit comments

Comments
 (0)