2323
2424import json
2525import os
26+ import pathlib
2627import re
2728import subprocess
2829import sys
2930
3031
3132SUPPORTED_PORTS = ['atmel-samd' , 'esp32s2' , 'litex' , 'mimxrt10xx' , 'nrf' , 'stm' ]
3233
34+ def get_circuitpython_root_dir ():
35+ """ The path to the root './circuitpython' directory
36+ """
37+ file_path = pathlib .Path (__file__ ).resolve ()
38+ root_dir = file_path .parent .parent
39+
40+ return root_dir
41+
3342def get_shared_bindings ():
3443 """ Get a list of modules in shared-bindings based on folder names
3544 """
36- return [item for item in os .listdir ("./shared-bindings" )]
45+ shared_bindings_dir = get_circuitpython_root_dir () / "shared-bindings"
46+ return [item .name for item in shared_bindings_dir .iterdir ()]
3747
3848
3949def read_mpconfig ():
4050 """ Open 'circuitpy_mpconfig.mk' and return the contents.
4151 """
4252 configs = []
43- with open ("py/circuitpy_mpconfig.mk" ) as mpconfig :
53+ cpy_mpcfg = get_circuitpython_root_dir () / "py" / "circuitpy_mpconfig.mk"
54+ with open (cpy_mpcfg ) as mpconfig :
4455 configs = mpconfig .read ()
4556
4657 return configs
@@ -120,7 +131,7 @@ def lookup_setting(settings, key, default=''):
120131 key = value [2 :- 1 ]
121132 return value
122133
123- def support_matrix_by_board ():
134+ def support_matrix_by_board (use_branded_name = True ):
124135 """ Compiles a list of the available core modules available for each
125136 board.
126137 """
@@ -129,20 +140,22 @@ def support_matrix_by_board():
129140 boards = dict ()
130141 for port in SUPPORTED_PORTS :
131142
132- port_dir = "ports/{}/boards" . format ( port )
133- for entry in os . scandir (port_dir ):
143+ port_dir = get_circuitpython_root_dir () / "ports" / port
144+ for entry in (port_dir / "boards" ). iterdir ( ):
134145 if not entry .is_dir ():
135146 continue
136147 board_modules = []
148+ board_name = entry .name
137149
138- settings = get_settings_from_makefile (f'ports/ { port } ' , entry .name )
150+ settings = get_settings_from_makefile (str ( port_dir ) , entry .name )
139151
140- with open (os .path .join (entry .path , "mpconfigboard.h" )) as get_name :
141- board_contents = get_name .read ()
142- board_name_re = re .search ("(?<=MICROPY_HW_BOARD_NAME)\s+(.+)" ,
143- board_contents )
144- if board_name_re :
145- board_name = board_name_re .group (1 ).strip ('"' )
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 ('"' )
146159
147160 board_modules = []
148161 for module in base :
0 commit comments