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
+ cwd = pathlib .Path ('.' ).resolve ()
38
+ cwd_parts = cwd .parts
39
+
40
+ root_idx = len (cwd_parts )
41
+
42
+ # Search the path from tail to head, so that we capture the
43
+ # deepest folder. This avoids overshooting in instances like:
44
+ # '/home/user/circuitpython_v5/circuitpython'
45
+ for idx , val in enumerate (cwd_parts [::- 1 ]):
46
+ if val .startswith ("circuitpython" ):
47
+ root_idx = root_idx - idx
48
+ break
49
+
50
+ root_dir = '/' .join (cwd_parts [:root_idx ])
51
+
52
+ return pathlib .Path (root_dir ).resolve ()
53
+
33
54
def get_shared_bindings ():
34
55
""" Get a list of modules in shared-bindings based on folder names
35
56
"""
36
- return [item for item in os .listdir ("./shared-bindings" )]
57
+ shared_bindings_dir = get_circuitpython_root_dir () / "shared-bindings"
58
+ return [item .name for item in shared_bindings_dir .iterdir ()]
37
59
38
60
39
61
def read_mpconfig ():
40
62
""" Open 'circuitpy_mpconfig.mk' and return the contents.
41
63
"""
42
64
configs = []
43
- with open ("py/circuitpy_mpconfig.mk" ) as mpconfig :
65
+ cpy_mpcfg = get_circuitpython_root_dir () / "py" / "circuitpy_mpconfig.mk"
66
+ with open (cpy_mpcfg ) as mpconfig :
44
67
configs = mpconfig .read ()
45
68
46
69
return configs
@@ -120,7 +143,7 @@ def lookup_setting(settings, key, default=''):
120
143
key = value [2 :- 1 ]
121
144
return value
122
145
123
- def support_matrix_by_board ():
146
+ def support_matrix_by_board (use_branded_name = True ):
124
147
""" Compiles a list of the available core modules available for each
125
148
board.
126
149
"""
@@ -129,20 +152,22 @@ def support_matrix_by_board():
129
152
boards = dict ()
130
153
for port in SUPPORTED_PORTS :
131
154
132
- port_dir = "ports/{}/boards" . format ( port )
133
- for entry in os . scandir (port_dir ):
155
+ port_dir = get_circuitpython_root_dir () / "ports" / port
156
+ for entry in (port_dir / "boards" ). iterdir ( ):
134
157
if not entry .is_dir ():
135
158
continue
136
159
board_modules = []
160
+ board_name = entry .name
137
161
138
- settings = get_settings_from_makefile (f'ports/ { port } ' , entry .name )
162
+ settings = get_settings_from_makefile (str ( port_dir ) , entry .name )
139
163
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 ('"' )
164
+ if use_branded_name :
165
+ with open (os .path .join (entry .path , "mpconfigboard.h" )) as get_name :
166
+ board_contents = get_name .read ()
167
+ board_name_re = re .search (r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)" ,
168
+ board_contents )
169
+ if board_name_re :
170
+ board_name = board_name_re .group (1 ).strip ('"' )
146
171
147
172
board_modules = []
148
173
for module in base :
0 commit comments