23
23
24
24
import json
25
25
import os
26
+ import pathlib
26
27
import re
27
28
import subprocess
28
29
import sys
29
30
30
31
31
32
SUPPORTED_PORTS = ['atmel-samd' , 'esp32s2' , 'litex' , 'mimxrt10xx' , 'nrf' , 'stm' ]
32
33
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
+
33
42
def get_shared_bindings ():
34
43
""" Get a list of modules in shared-bindings based on folder names
35
44
"""
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 ()]
37
47
38
48
39
49
def read_mpconfig ():
40
50
""" Open 'circuitpy_mpconfig.mk' and return the contents.
41
51
"""
42
52
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 :
44
55
configs = mpconfig .read ()
45
56
46
57
return configs
@@ -120,7 +131,7 @@ def lookup_setting(settings, key, default=''):
120
131
key = value [2 :- 1 ]
121
132
return value
122
133
123
- def support_matrix_by_board ():
134
+ def support_matrix_by_board (use_branded_name = True ):
124
135
""" Compiles a list of the available core modules available for each
125
136
board.
126
137
"""
@@ -129,20 +140,22 @@ def support_matrix_by_board():
129
140
boards = dict ()
130
141
for port in SUPPORTED_PORTS :
131
142
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 ( ):
134
145
if not entry .is_dir ():
135
146
continue
136
147
board_modules = []
148
+ board_name = entry .name
137
149
138
- settings = get_settings_from_makefile (f'ports/ { port } ' , entry .name )
150
+ settings = get_settings_from_makefile (str ( port_dir ) , entry .name )
139
151
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 ('"' )
146
159
147
160
board_modules = []
148
161
for module in base :
0 commit comments