32
32
33
33
SUPPORTED_PORTS = ['atmel-samd' , 'broadcom' , 'cxd56' , 'espressif' , 'litex' , 'mimxrt10xx' , 'nrf' , 'raspberrypi' , 'stm' ]
34
34
35
- aliases_by_board = {
35
+ ALIASES_BY_BOARD = {
36
36
"circuitplayground_express" : [
37
37
"circuitplayground_express_4h" ,
38
38
"circuitplayground_express_digikey_pycon2019" ,
43
43
"pewpew10" : ["pewpew13" ],
44
44
}
45
45
46
- aliases_brand_names = {
46
+ ALIASES_BRAND_NAMES = {
47
47
"circuitplayground_express_4h" :
48
48
"Adafruit Circuit Playground Express 4-H" ,
49
49
"circuitplayground_express_digikey_pycon2019" :
58
58
"PewPew 13" ,
59
59
}
60
60
61
- additional_modules = {
61
+ ADDITIONAL_MODULES = {
62
62
"fontio" : "CIRCUITPY_DISPLAYIO" ,
63
63
"terminalio" : "CIRCUITPY_DISPLAYIO" ,
64
64
"adafruit_bus_device" : "CIRCUITPY_BUSDEVICE" ,
65
65
"adafruit_pixelbuf" : "CIRCUITPY_PIXELBUF" ,
66
66
"usb" : "CIRCUITPY_USB_HOST" ,
67
67
}
68
68
69
- frozen_excludes = ["examples" , "docs" , "tests" , "utils" , "conf.py" , "setup.py" ]
69
+ FROZEN_EXCLUDES = ["examples" , "docs" , "tests" , "utils" , "conf.py" , "setup.py" ]
70
70
"""Files and dirs at the root of a frozen directory that should be ignored.
71
71
This is the same list as in the preprocess_frozen_modules script."""
72
72
73
73
repository_urls = {}
74
74
"""Cache of repository URLs for frozen modules."""
75
75
76
76
def get_circuitpython_root_dir ():
77
- """ The path to the root './circuitpython' directory
77
+ """ The path to the root './circuitpython' directory.
78
78
"""
79
79
file_path = pathlib .Path (__file__ ).resolve ()
80
80
root_dir = file_path .parent .parent
81
81
82
82
return root_dir
83
83
84
84
def get_shared_bindings ():
85
- """ Get a list of modules in shared-bindings based on folder names
85
+ """ Get a list of modules in shared-bindings based on folder names.
86
86
"""
87
87
shared_bindings_dir = get_circuitpython_root_dir () / "shared-bindings"
88
88
return [item .name for item in shared_bindings_dir .iterdir ()] + ["binascii" , "errno" , "json" , "re" , "ulab" ]
89
89
90
90
91
+ def get_board_mapping ():
92
+ """
93
+ Compiles the list of boards from the directories, with aliases and mapping
94
+ to the port.
95
+ """
96
+ boards = {}
97
+ for port in SUPPORTED_PORTS :
98
+ board_path = os .path .join ("../ports" , port , "boards" )
99
+ for board_path in os .scandir (board_path ):
100
+ if board_path .is_dir ():
101
+ board_files = os .listdir (board_path .path )
102
+ board_id = board_path .name
103
+ aliases = ALIASES_BY_BOARD .get (board_path .name , [])
104
+ boards [board_id ] = {
105
+ "port" : port ,
106
+ "download_count" : 0 ,
107
+ "aliases" : aliases ,
108
+ }
109
+ for alias in aliases :
110
+ boards [alias ] = {
111
+ "port" : port ,
112
+ "download_count" : 0 ,
113
+ "alias" : True ,
114
+ "aliases" : [],
115
+ }
116
+ return boards
117
+
118
+
91
119
def read_mpconfig ():
92
120
""" Open 'circuitpy_mpconfig.mk' and return the contents.
93
121
"""
@@ -112,8 +140,8 @@ def build_module_map():
112
140
full_build = False
113
141
for module in modules :
114
142
full_name = module
115
- if module in additional_modules :
116
- search_identifier = additional_modules [module ]
143
+ if module in ADDITIONAL_MODULES :
144
+ search_identifier = ADDITIONAL_MODULES [module ]
117
145
else :
118
146
search_identifier = 'CIRCUITPY_' + module .lstrip ("_" ).upper ()
119
147
re_pattern = f"{ re .escape (search_identifier )} \s*\??=\s*(.+)"
@@ -204,27 +232,33 @@ def get_repository_url(directory):
204
232
repository_urls [directory ] = path
205
233
return path
206
234
207
- def frozen_modules_from_dirs (frozen_mpy_dirs ):
235
+ def frozen_modules_from_dirs (frozen_mpy_dirs , withurl ):
208
236
"""
209
237
Go through the list of frozen directories and extract the python modules.
210
238
Paths are of the type:
211
239
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
212
240
$(TOP)/frozen/circuitpython-stage/meowbit
213
241
Python modules are at the root of the path, and are python files or directories
214
- containing python files. Except the ones in the frozen_excludes list.
242
+ containing python files. Except the ones in the FROZEN_EXCLUDES list.
215
243
"""
216
244
frozen_modules = []
217
245
for frozen_path in filter (lambda x : x , frozen_mpy_dirs .split (" " )):
218
246
source_dir = get_circuitpython_root_dir () / frozen_path [7 :]
219
247
url_repository = get_repository_url (source_dir )
220
248
for sub in source_dir .glob ("*" ):
221
- if sub .name in frozen_excludes :
249
+ if sub .name in FROZEN_EXCLUDES :
222
250
continue
223
251
if sub .name .endswith (".py" ):
224
- frozen_modules .append ((sub .name [:- 3 ], url_repository ))
252
+ if withurl :
253
+ frozen_modules .append ((sub .name [:- 3 ], url_repository ))
254
+ else :
255
+ frozen_modules .append (sub .name [:- 3 ])
225
256
continue
226
257
if next (sub .glob ("**/*.py" ), None ): # tests if not empty
227
- frozen_modules .append ((sub .name , url_repository ))
258
+ if withurl :
259
+ frozen_modules .append ((sub .name , url_repository ))
260
+ else :
261
+ frozen_modules .append (sub .name )
228
262
return frozen_modules
229
263
230
264
def lookup_setting (settings , key , default = '' ):
@@ -244,7 +278,7 @@ def all_ports_all_boards(ports=SUPPORTED_PORTS):
244
278
continue
245
279
yield (port , entry )
246
280
247
- def support_matrix_by_board (use_branded_name = True ):
281
+ def support_matrix_by_board (use_branded_name = True , withurl = True ):
248
282
""" Compiles a list of the available core modules available for each
249
283
board.
250
284
"""
@@ -272,29 +306,49 @@ def support_matrix(arg):
272
306
board_modules .append (base [module ]['name' ])
273
307
board_modules .sort ()
274
308
309
+ if "CIRCUITPY_BUILD_EXTENSIONS" in settings :
310
+ board_extensions = [
311
+ extension .strip () for extension in
312
+ settings ["CIRCUITPY_BUILD_EXTENSIONS" ].split ("," )
313
+ ]
314
+ else :
315
+ raise OSError (f"Board extensions undefined: { board_name } ." )
316
+
275
317
frozen_modules = []
276
318
if "FROZEN_MPY_DIRS" in settings :
277
- frozen_modules = frozen_modules_from_dirs (settings ["FROZEN_MPY_DIRS" ])
319
+ frozen_modules = frozen_modules_from_dirs (settings ["FROZEN_MPY_DIRS" ], withurl )
278
320
if frozen_modules :
279
321
frozen_modules .sort ()
280
322
281
323
# generate alias boards too
282
- board_matrix = [(board_name , (board_modules , frozen_modules ))]
283
- if entry .name in aliases_by_board :
284
- for alias in aliases_by_board [entry .name ]:
324
+ board_matrix = [(
325
+ board_name , {
326
+ "modules" : board_modules ,
327
+ "frozen_libraries" : frozen_modules ,
328
+ "extensions" : board_extensions ,
329
+ }
330
+ )]
331
+ if entry .name in ALIASES_BY_BOARD :
332
+ for alias in ALIASES_BY_BOARD [entry .name ]:
285
333
if use_branded_name :
286
- if alias in aliases_brand_names :
287
- alias = aliases_brand_names [alias ]
334
+ if alias in ALIASES_BRAND_NAMES :
335
+ alias = ALIASES_BRAND_NAMES [alias ]
288
336
else :
289
337
alias = alias .replace ("_" ," " ).title ()
290
- board_matrix .append ( (alias , (board_modules , frozen_modules )) )
338
+ board_matrix .append ((
339
+ alias , {
340
+ "modules" : board_modules ,
341
+ "frozen_libraries" : frozen_modules ,
342
+ "extensions" : board_extensions ,
343
+ },
344
+ ))
291
345
292
346
return board_matrix # this is now a list of (board,modules)
293
347
294
348
executor = ThreadPoolExecutor (max_workers = os .cpu_count ())
295
349
mapped_exec = executor .map (support_matrix , all_ports_all_boards ())
296
350
# flatmap with comprehensions
297
- boards = dict (sorted ([board for matrix in mapped_exec for board in matrix ]))
351
+ boards = dict (sorted ([board for matrix in mapped_exec for board in matrix ], key = lambda x : x [ 0 ] ))
298
352
299
353
return boards
300
354
0 commit comments