Skip to content

Commit e08502f

Browse files
committed
list frozen modules in the support matrix
- fix the list of frozen modules in the board info, separate it from the builtin modules - frozen modules are listed along with the link to their repository - get the repository by running the git command in the frozen directory - frozen modules are listed at the end - they copy the style of the other modules - frozen modules in build_board_info don't need the URLs, they are filtered out
1 parent 0642917 commit e08502f

File tree

6 files changed

+90
-29
lines changed

6 files changed

+90
-29
lines changed

conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@
5353
modules_support_matrix = shared_bindings_matrix.support_matrix_by_board()
5454
modules_support_matrix_reverse = defaultdict(list)
5555
for board, modules in modules_support_matrix.items():
56-
for module in modules:
56+
for module in modules[0]:
5757
modules_support_matrix_reverse[module].append(board)
58-
modules_support_matrix_reverse = dict((module, sorted(boards)) for module, boards in modules_support_matrix_reverse.items())
58+
59+
modules_support_matrix_reverse = dict(
60+
(module, sorted(boards))
61+
for module, boards in modules_support_matrix_reverse.items()
62+
)
5963

6064
html_context = {
6165
'support_matrix': modules_support_matrix,

docs/shared_bindings_matrix.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@
6262
"fontio": "CIRCUITPY_DISPLAYIO",
6363
"terminalio": "CIRCUITPY_DISPLAYIO",
6464
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
65-
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF"
65+
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF",
66+
"usb": "CIRCUITPY_USB_HOST",
6667
}
6768

69+
frozen_excludes = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
70+
"""Files and dirs at the root of a frozen directory that should be ignored.
71+
This is the same list as in the preprocess_frozen_modules script."""
72+
6873
def get_circuitpython_root_dir():
6974
""" The path to the root './circuitpython' directory
7075
"""
@@ -162,6 +167,40 @@ def get_settings_from_makefile(port_dir, board_name):
162167

163168
return settings
164169

170+
def get_repository_url(directory):
171+
contents = subprocess.run(
172+
["git", "remote", "get-url", "origin"],
173+
encoding="utf-8",
174+
errors="replace",
175+
stdout=subprocess.PIPE,
176+
stderr=subprocess.PIPE,
177+
cwd=directory
178+
)
179+
return contents.stdout.strip()
180+
181+
def frozen_modules_from_dirs(frozen_mpy_dirs):
182+
"""
183+
Go through the list of frozen directories and extract the python modules.
184+
Paths are of the type:
185+
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
186+
$(TOP)/frozen/circuitpython-stage/meowbit
187+
Python modules are at the root of the path, and are python files or directories
188+
containing python files. Except the ones in the frozen_excludes list.
189+
"""
190+
frozen_modules = []
191+
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
192+
source_dir = get_circuitpython_root_dir() / frozen_path[7:]
193+
url_repository = get_repository_url(source_dir)
194+
for sub in source_dir.glob("*"):
195+
if sub.name in frozen_excludes:
196+
continue
197+
if sub.name.endswith(".py"):
198+
frozen_modules.append((sub.name[:-3], url_repository))
199+
continue
200+
if next(sub.glob("**/*.py"), None): # tests if not empty
201+
frozen_modules.append((sub.name, url_repository))
202+
return frozen_modules
203+
165204
def lookup_setting(settings, key, default=''):
166205
while True:
167206
value = settings.get(key, default)
@@ -207,16 +246,22 @@ def support_matrix(arg):
207246
board_modules.append(base[module]['name'])
208247
board_modules.sort()
209248

249+
frozen_modules = []
250+
if "FROZEN_MPY_DIRS" in settings:
251+
frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"])
252+
if frozen_modules:
253+
frozen_modules.sort()
254+
210255
# generate alias boards too
211-
board_matrix = [(board_name, board_modules)]
256+
board_matrix = [(board_name, (board_modules, frozen_modules))]
212257
if entry.name in aliases_by_board:
213258
for alias in aliases_by_board[entry.name]:
214259
if use_branded_name:
215260
if alias in aliases_brand_names:
216261
alias = aliases_brand_names[alias]
217262
else:
218263
alias = alias.replace("_"," ").title()
219-
board_matrix.append( (alias, board_modules) )
264+
board_matrix.append( (alias, (board_modules, frozen_modules)) )
220265

221266
return board_matrix # this is now a list of (board,modules)
222267

@@ -225,7 +270,6 @@ def support_matrix(arg):
225270
# flatmap with comprehensions
226271
boards = dict(sorted([board for matrix in mapped_exec for board in matrix]))
227272

228-
# print(json.dumps(boards, indent=2))
229273
return boards
230274

231275
if __name__ == '__main__':

docs/static/filter.css

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@
77
right: 10px;
88
top: 4px;
99
}
10-
.support-matrix-table .this_module code,
11-
.support-matrix-table .this_module span {
10+
11+
.support-matrix-table .reference.external {
12+
box-sizing: border-box;
13+
font-weight: 700;
14+
color: #404050;
15+
font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace;
16+
padding: 2px 5px;
17+
background: white;
18+
border: 1px solid #e1e4e5;
19+
font-size: 75%;
20+
}
21+
22+
.support-matrix-table .this_module,
23+
.support-matrix-table .this_module.reference.external,
24+
.support-matrix-table .this_module * {
1225
background: black;
1326
color: white;
1427
}

docs/static/filter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ $(() => {
4444
var nvisible = 0;
4545
$(".support-matrix-table tbody tr").each( (index,item) => {
4646
var name = $(item).find("td:first-child p").html();
47-
var modules = $(item).find("a.reference.internal");
47+
var modules = $(item).find("code, a.reference.external");
4848
var matching_all = true;
4949
//
5050
list_search.forEach((sstring) => {
5151
var matching = (sstring[0] == "-");
5252
for(var modi = 0; modi < modules.length; ++modi) {
5353
module = modules[modi];
54-
var mod_name = module.firstChild.firstChild.textContent;
54+
var mod_name = module.firstChild.textContent;
5555
if(sstring[0] == "-") {
5656
if(mod_name.match(sstring.substr(1))) {
5757
matching = false;

shared-bindings/support_matrix.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Module Support Matrix - Which Modules Are Available on Which Boards
44
===================================================================
55

66
The following table lists the available built-in modules for each CircuitPython
7-
capable board.
7+
capable board, as well as each :term:`frozen module` included on it.
88

99
.. raw:: html
1010

@@ -21,6 +21,14 @@ capable board.
2121
{% for key, value in support_matrix|dictsort %}
2222
{{ '.. _' ~ key|replace(" ", "-") ~ ':' }}
2323
* - {{ key }}
24-
- {{ ':py:mod:`' ~ value|join("`, :py:mod:`") ~ '`' }}
24+
- {{ ':py:mod:`' ~ value[0]|join("`, :py:mod:`") ~ '`' }}
25+
26+
{% for module in value[1] %}\
27+
{% if loop.index == 1 %}**Frozen Modules:** {% endif %}\
28+
{% if loop.index > 1 %}, {% endif %}\
29+
{% if module[1] %}{{ '`' ~ module[0] ~ ' <' ~ module[1] ~ '>`__' }}\
30+
{% else %}{{ '`' ~ module[0] ~ ' <#>`__' }}\
31+
{% endif %}\
32+
{% endfor %}
2533

2634
{% endfor %}

tools/build_board_info.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
from datetime import date
1414
from sh.contrib import git
1515

16-
sys.path.append("../docs")
17-
import shared_bindings_matrix
18-
1916
sys.path.append("adabot")
2017
import adabot.github_requests as github
2118

22-
from shared_bindings_matrix import SUPPORTED_PORTS
23-
from shared_bindings_matrix import aliases_by_board
19+
sys.path.append("../docs")
20+
from shared_bindings_matrix import (
21+
SUPPORTED_PORTS,
22+
aliases_by_board,
23+
support_matrix_by_board,
24+
)
2425

2526
BIN = ("bin",)
2627
UF2 = ("uf2",)
@@ -124,20 +125,11 @@ def get_board_mapping():
124125
extensions = extension_by_port[port]
125126
extensions = extension_by_board.get(board_path.name, extensions)
126127
aliases = aliases_by_board.get(board_path.name, [])
127-
frozen_libraries = []
128-
with open(os.path.join(board_path, "mpconfigboard.mk")) as mpconfig:
129-
frozen_lines = [
130-
line for line in mpconfig if line.startswith("FROZEN_MPY_DIRS")
131-
]
132-
frozen_libraries.extend(
133-
[line[line.rfind("/") + 1 :].strip() for line in frozen_lines]
134-
)
135128
boards[board_id] = {
136129
"port": port,
137130
"extensions": extensions,
138131
"download_count": 0,
139132
"aliases": aliases,
140-
"frozen_libraries": frozen_libraries,
141133
}
142134
for alias in aliases:
143135
boards[alias] = {
@@ -284,7 +276,7 @@ def generate_download_info():
284276

285277
languages = get_languages()
286278

287-
support_matrix = shared_bindings_matrix.support_matrix_by_board(use_branded_name=False)
279+
support_matrix = support_matrix_by_board(use_branded_name=False)
288280

289281
new_stable = "-" not in new_tag
290282

@@ -321,10 +313,10 @@ def generate_download_info():
321313
new_version = {
322314
"stable": new_stable,
323315
"version": new_tag,
324-
"modules": support_matrix[alias],
316+
"modules": support_matrix[alias][0],
325317
"languages": languages,
326318
"extensions": board_info["extensions"],
327-
"frozen_libraries": board_info["frozen_libraries"],
319+
"frozen_libraries": [frozen[0] for frozen in support_matrix[alias][1]],
328320
}
329321
current_info[alias]["downloads"] = alias_info["download_count"]
330322
current_info[alias]["versions"].append(new_version)

0 commit comments

Comments
 (0)