22
22
#
23
23
24
24
import re
25
+ import sys
26
+
27
+ sys .path .append ("../docs" )
28
+
25
29
from shared_bindings_matrix import support_matrix_by_board
26
30
27
31
@@ -34,15 +38,16 @@ def module_incidence_matrix_csvs(support_matrix, rows=1000, present="1", absent=
34
38
row = 0
35
39
for board , info in support_matrix .items ():
36
40
if (row % rows ) == 0 :
37
- csv = ["board,branded_name,mcu,flash,port,pins," +
38
- ',' .join (all_modules ) + '\n ' ]
41
+ csv = ["board,branded_name,mcu,flash,port,pins," + "," .join (all_modules ) + "\n " ]
39
42
chip_pin_set = set ([chip_pin for _ , chip_pin in info ["pins" ]])
40
43
n_chip_pins = len (chip_pin_set )
41
- module_incidence = [present if m in info ["modules" ]
42
- else absent for m in all_modules ]
43
- line = f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ," + \
44
- f"{ info .get ('flash' )} ,{ info .get ('port' )} ,{ n_chip_pins } ," + \
45
- ',' .join (module_incidence ) + '\n '
44
+ module_incidence = [present if m in info ["modules" ] else absent for m in all_modules ]
45
+ line = (
46
+ f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ,"
47
+ + f"{ info .get ('flash' )} ,{ info .get ('port' )} ,{ n_chip_pins } ,"
48
+ + "," .join (module_incidence )
49
+ + "\n "
50
+ )
46
51
csv .append (line )
47
52
row += 1
48
53
if (row % rows ) == 0 :
@@ -63,8 +68,7 @@ def frozen_incidence_matrix_csvs(support_matrix, rows=1000, present="1", absent=
63
68
row = 0
64
69
for board , info in support_matrix .items ():
65
70
if (row % rows ) == 0 :
66
- csv = ["board,branded_name,mcu,flash,port,pins," +
67
- "," .join (all_frozen ) + "\n " ]
71
+ csv = ["board,branded_name,mcu,flash,port,pins," + "," .join (all_frozen ) + "\n " ]
68
72
# remove urls if present
69
73
frozen = info ["frozen_libraries" ]
70
74
@@ -73,9 +77,12 @@ def frozen_incidence_matrix_csvs(support_matrix, rows=1000, present="1", absent=
73
77
74
78
frozen = [f [0 ] if type (f ) == tuple else f for f in frozen ]
75
79
frozen_incidence = [present if f in frozen else absent for f in all_frozen ]
76
- line = f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ," + \
77
- f"{ info .get ('flash' )} ,{ info .get ('port' )} ,{ n_chip_pins } ," + \
78
- "," .join (frozen_incidence ) + '\n '
80
+ line = (
81
+ f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ,"
82
+ + f"{ info .get ('flash' )} ,{ info .get ('port' )} ,{ n_chip_pins } ,"
83
+ + "," .join (frozen_incidence )
84
+ + "\n "
85
+ )
79
86
csv .append (line )
80
87
row += 1
81
88
if (row % rows ) == 0 :
@@ -91,19 +98,20 @@ def summarize_pins(pins):
91
98
summarizing the names in the list"""
92
99
pin_prefixes = {}
93
100
for p in pins :
94
- match = re .match (r' ^(.*?)(\d*)$' , p )
101
+ match = re .match (r" ^(.*?)(\d*)$" , p )
95
102
if match :
96
103
prefix = match .group (1 )
97
104
n_str = match .group (2 )
98
105
else :
99
106
raise ValueError ("Cannot parse pin name" )
100
- if prefix in pin_prefixes :
107
+ if prefix in pin_prefixes :
101
108
pin_prefixes [prefix ].add (n_str )
102
109
else :
103
110
pin_prefixes [prefix ] = {n_str }
104
111
105
- return ', ' .join ([f"{ prefix } { span_string (pin_prefixes [prefix ])} "
106
- for prefix in sorted (pin_prefixes .keys ())])
112
+ return ", " .join (
113
+ [f"{ prefix } { span_string (pin_prefixes [prefix ])} " for prefix in sorted (pin_prefixes .keys ())]
114
+ )
107
115
108
116
109
117
def int_or_zero (s ):
@@ -141,14 +149,24 @@ def board_pins_matrix_csvs(support_matrix, rows=1000):
141
149
row = 0
142
150
for board , info in support_matrix .items ():
143
151
if (row % rows ) == 0 :
144
- csv = ["board,branded_name,mcu,flash,port,n_board_pins,"
145
- "board_pins,n_chip_pins,chip_pins\n " ]
152
+ csv = [
153
+ "board,branded_name,mcu,flash,port,n_board_pins,"
154
+ "board_pins,n_chip_pins,chip_pins\n "
155
+ ]
146
156
board_pins = [board_pin for board_pin , _ in info ["pins" ]]
147
157
chip_pins = [chip_pin for _ , chip_pin in info ["pins" ]]
148
- line = f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ," + \
149
- f"{ info .get ('flash' )} ,{ info .get ('port' )} ," + \
150
- str (len (set (board_pins ))) + ',"' + summarize_pins (board_pins ) + '",' + \
151
- str (len (set (chip_pins ))) + ',"' + summarize_pins (chip_pins ) + '"\n '
158
+ line = (
159
+ f"{ board } ,{ info .get ('branded_name' )} ,{ info .get ('mcu' )} ,"
160
+ + f"{ info .get ('flash' )} ,{ info .get ('port' )} ,"
161
+ + str (len (set (board_pins )))
162
+ + ',"'
163
+ + summarize_pins (board_pins )
164
+ + '",'
165
+ + str (len (set (chip_pins )))
166
+ + ',"'
167
+ + summarize_pins (chip_pins )
168
+ + '"\n '
169
+ )
152
170
csv .append (line )
153
171
row += 1
154
172
if (row % rows ) == 0 :
@@ -159,19 +177,19 @@ def board_pins_matrix_csvs(support_matrix, rows=1000):
159
177
160
178
161
179
def write_csvs (rows = 1000 , present = "1" , absent = "0" ):
162
- print (' generating csvs...' )
163
- s = support_matrix_by_board (use_branded_name = False , add_port = True ,
164
- add_chips = True , add_pins = True ,
165
- add_branded_name = True )
166
- csvs = {"modules" : module_incidence_matrix_csvs ( s , rows = rows ,
167
- present = present , absent = absent ),
168
- "frozen" : frozen_incidence_matrix_csvs (s , rows = rows ,
169
- present = present , absent = absent ),
170
- "pins" : board_pins_matrix_csvs ( s , rows = rows ) }
180
+ print (" generating csvs..." )
181
+ s = support_matrix_by_board (
182
+ use_branded_name = False , add_port = True , add_chips = True , add_pins = True , add_branded_name = True
183
+ )
184
+ csvs = {
185
+ "modules" : module_incidence_matrix_csvs ( s , rows = rows , present = present , absent = absent ),
186
+ "frozen" : frozen_incidence_matrix_csvs (s , rows = rows , present = present , absent = absent ) ,
187
+ "pins" : board_pins_matrix_csvs ( s , rows = rows ),
188
+ }
171
189
for key in csvs :
172
190
for i in range (len (csvs [key ])):
173
191
filename = f"{ key } _{ i } .csv"
174
- print (f' writing { filename } ' )
192
+ print (f" writing { filename } " )
175
193
with open (filename , "w" ) as f :
176
194
f .writelines (csvs [key ][i ])
177
195
0 commit comments