Skip to content

Commit facaf7e

Browse files
committed
move get_board_mapping to shared_binding_matrix because it just uses a list from there
uppercase some of the configuration lists and dicts properly split the extensions into a list
1 parent dfe465c commit facaf7e

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

docs/shared_bindings_matrix.py

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
SUPPORTED_PORTS = ['atmel-samd', 'broadcom', 'cxd56', 'espressif', 'litex', 'mimxrt10xx', 'nrf', 'raspberrypi', 'stm']
3434

35-
aliases_by_board = {
35+
ALIASES_BY_BOARD = {
3636
"circuitplayground_express": [
3737
"circuitplayground_express_4h",
3838
"circuitplayground_express_digikey_pycon2019",
@@ -43,7 +43,7 @@
4343
"pewpew10": ["pewpew13"],
4444
}
4545

46-
aliases_brand_names = {
46+
ALIASES_BRAND_NAMES = {
4747
"circuitplayground_express_4h":
4848
"Adafruit Circuit Playground Express 4-H",
4949
"circuitplayground_express_digikey_pycon2019":
@@ -58,36 +58,64 @@
5858
"PewPew 13",
5959
}
6060

61-
additional_modules = {
61+
ADDITIONAL_MODULES = {
6262
"fontio": "CIRCUITPY_DISPLAYIO",
6363
"terminalio": "CIRCUITPY_DISPLAYIO",
6464
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
6565
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF",
6666
"usb": "CIRCUITPY_USB_HOST",
6767
}
6868

69-
frozen_excludes = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
69+
FROZEN_EXCLUDES = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
7070
"""Files and dirs at the root of a frozen directory that should be ignored.
7171
This is the same list as in the preprocess_frozen_modules script."""
7272

7373
repository_urls = {}
7474
"""Cache of repository URLs for frozen modules."""
7575

7676
def get_circuitpython_root_dir():
77-
""" The path to the root './circuitpython' directory
77+
""" The path to the root './circuitpython' directory.
7878
"""
7979
file_path = pathlib.Path(__file__).resolve()
8080
root_dir = file_path.parent.parent
8181

8282
return root_dir
8383

8484
def get_shared_bindings():
85-
""" Get a list of modules in shared-bindings based on folder names
85+
""" Get a list of modules in shared-bindings based on folder names.
8686
"""
8787
shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings"
8888
return [item.name for item in shared_bindings_dir.iterdir()] + ["binascii", "errno", "json", "re", "ulab"]
8989

9090

91+
def get_board_mapping():
92+
"""
93+
Compiles the list of boards from the directories, with aliases and mapping
94+
to the port.
95+
"""
96+
boards = {}
97+
for port in SUPPORTED_PORTS:
98+
board_path = os.path.join("../ports", port, "boards")
99+
for board_path in os.scandir(board_path):
100+
if board_path.is_dir():
101+
board_files = os.listdir(board_path.path)
102+
board_id = board_path.name
103+
aliases = ALIASES_BY_BOARD.get(board_path.name, [])
104+
boards[board_id] = {
105+
"port": port,
106+
"download_count": 0,
107+
"aliases": aliases,
108+
}
109+
for alias in aliases:
110+
boards[alias] = {
111+
"port": port,
112+
"download_count": 0,
113+
"alias": True,
114+
"aliases": [],
115+
}
116+
return boards
117+
118+
91119
def read_mpconfig():
92120
""" Open 'circuitpy_mpconfig.mk' and return the contents.
93121
"""
@@ -112,8 +140,8 @@ def build_module_map():
112140
full_build = False
113141
for module in modules:
114142
full_name = module
115-
if module in additional_modules:
116-
search_identifier = additional_modules[module]
143+
if module in ADDITIONAL_MODULES:
144+
search_identifier = ADDITIONAL_MODULES[module]
117145
else:
118146
search_identifier = 'CIRCUITPY_'+module.lstrip("_").upper()
119147
re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)"
@@ -211,14 +239,14 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
211239
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
212240
$(TOP)/frozen/circuitpython-stage/meowbit
213241
Python modules are at the root of the path, and are python files or directories
214-
containing python files. Except the ones in the frozen_excludes list.
242+
containing python files. Except the ones in the FROZEN_EXCLUDES list.
215243
"""
216244
frozen_modules = []
217245
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
218246
source_dir = get_circuitpython_root_dir() / frozen_path[7:]
219247
url_repository = get_repository_url(source_dir)
220248
for sub in source_dir.glob("*"):
221-
if sub.name in frozen_excludes:
249+
if sub.name in FROZEN_EXCLUDES:
222250
continue
223251
if sub.name.endswith(".py"):
224252
if withurl:
@@ -279,7 +307,10 @@ def support_matrix(arg):
279307
board_modules.sort()
280308

281309
if "CIRCUITPY_BUILD_EXTENSIONS" in settings:
282-
board_extensions = settings["CIRCUITPY_BUILD_EXTENSIONS"]
310+
board_extensions = [
311+
extension.strip() for extension in
312+
settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",")
313+
]
283314
else:
284315
raise OSError(f"Board extensions undefined: {board_name}.")
285316

@@ -297,11 +328,11 @@ def support_matrix(arg):
297328
"extensions": board_extensions,
298329
}
299330
)]
300-
if entry.name in aliases_by_board:
301-
for alias in aliases_by_board[entry.name]:
331+
if entry.name in ALIASES_BY_BOARD:
332+
for alias in ALIASES_BY_BOARD[entry.name]:
302333
if use_branded_name:
303-
if alias in aliases_brand_names:
304-
alias = aliases_brand_names[alias]
334+
if alias in ALIASES_BRAND_NAMES:
335+
alias = ALIASES_BRAND_NAMES[alias]
305336
else:
306337
alias = alias.replace("_"," ").title()
307338
board_matrix.append((

tools/build_board_info.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
sys.path.append("../docs")
2020
from shared_bindings_matrix import (
2121
SUPPORTED_PORTS,
22-
aliases_by_board,
2322
support_matrix_by_board,
23+
get_board_mapping,
2424
)
2525

26-
language_allow_list = set(
26+
LANGUAGE_ALLOW_LIST = set(
2727
[
2828
"ID",
2929
"de_DE",
@@ -52,34 +52,10 @@ def get_languages(list_all=False):
5252
if f.name.endswith(".po"):
5353
languages.add(f.name[:-3])
5454
if not list_all:
55-
languages = languages & language_allow_list
55+
languages = languages & LANGUAGE_ALLOW_LIST
5656
return sorted(list(languages), key=str.casefold)
5757

5858

59-
def get_board_mapping():
60-
boards = {}
61-
for port in SUPPORTED_PORTS:
62-
board_path = os.path.join("../ports", port, "boards")
63-
for board_path in os.scandir(board_path):
64-
if board_path.is_dir():
65-
board_files = os.listdir(board_path.path)
66-
board_id = board_path.name
67-
aliases = aliases_by_board.get(board_path.name, [])
68-
boards[board_id] = {
69-
"port": port,
70-
"download_count": 0,
71-
"aliases": aliases,
72-
}
73-
for alias in aliases:
74-
boards[alias] = {
75-
"port": port,
76-
"download_count": 0,
77-
"alias": True,
78-
"aliases": [],
79-
}
80-
return boards
81-
82-
8359
def get_version_info():
8460
version = None
8561
sha = git("rev-parse", "--short", "HEAD").stdout.decode("utf-8")

0 commit comments

Comments
 (0)