diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c284a57f788..cf29a7b677e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -198,7 +198,7 @@ jobs: name: stubs path: circuitpython-stubs/dist/* - name: Test Documentation Build (HTML) - run: sphinx-build -E -W -b html -D version="$CP_VERSION" -D release="$CP_VERSION" . _build/html + run: sphinx-build -E -W -j auto -b html -D version="$CP_VERSION" -D release="$CP_VERSION" . _build/html - uses: actions/upload-artifact@v7 with: name: docs-html diff --git a/Makefile b/Makefile index e7150281352..ca0539fd4ee 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,11 @@ # You can set these variables from the command line. PYTHON = python3 -SPHINXOPTS = -W --keep-going +SPHINXOPTS = -W --keep-going -j auto SPHINXBUILD = sphinx-build +# -silent hides pdflatex's progress output, including the thousands of undefined-reference +# warnings from its first pass. Warnings left after the last pass, and errors, are still reported. +LATEXMKOPTS = -silent PAPER = # path to build the generated docs BUILDDIR = _build @@ -171,7 +174,7 @@ latex: latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf + $(MAKE) -C $(BUILDDIR)/latex all-pdf LATEXMKOPTS="$(LATEXMKOPTS)" @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." # seems to be malfunctioning diff --git a/conf.py b/conf.py index 379ac442f19..277d4f355ad 100644 --- a/conf.py +++ b/conf.py @@ -36,6 +36,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("docs")) +sys.path.insert(0, os.path.abspath("tools")) sys.path.insert(0, os.path.abspath(".")) import shared_bindings_matrix @@ -45,11 +46,14 @@ # Grab the JSON values to use while building the module support matrix # in 'shared-bindings/index.rst' -# The stubs must be built before we calculate the shared bindings matrix +# Building the stubs also saves the board data the support matrix needs, so the +# slow per-board collection runs only once. If that file is missing, +# support_matrix_by_board() collects the data itself. subprocess.check_output(["make", "stubs"]) +board_data = shared_bindings_matrix.read_board_data("circuitpython-stubs/board_data.json") # modules_support_matrix = shared_bindings_matrix.support_matrix_excluded_boards() -modules_support_matrix = shared_bindings_matrix.support_matrix_by_board() +modules_support_matrix = shared_bindings_matrix.support_matrix_by_board(board_data=board_data) modules_support_matrix_reverse = defaultdict(list) for board, matrix_info in modules_support_matrix.items(): for module in matrix_info["modules"]: diff --git a/docs/README.md b/docs/README.md index cddc45b03b3..fb29feb7c21 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,6 +23,23 @@ In `circuitpython/`, build the docs: You'll find the index page at `_build/html/index.html`. +### Building the PDF + +The PDF build also needs LaTeX and `rsvg-convert`. On Debian or Ubuntu, install them with: + + sudo apt install latexmk librsvg2-bin texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra + +Then build the PDF: + + make latexpdf + +You'll find it at `_build/latex/CircuitPython.pdf`. + +`pdflatex`'s output is verbose, with thousands of inconsequential warnings, so it goes to +`_build/latex/CircuitPython.log` instead of the console. To see it on the console anyway: + + make latexpdf LATEXMKOPTS= + ### More flexibility Running `make` by itself will list out the multiple doc generating commands available. @@ -38,8 +55,9 @@ All commands will, by default, run with `-E` (forces a rebuild from scratch of d # will turn OFF the force rebuild and make it doubly verbose when running make html FORCE= VERBOSE="-v -v" -You can also pass other options to sphinx by using `SPHINXOPTS`. +You can also pass other options to sphinx by using `SPHINXOPTS`. It replaces the default +options, `-W --keep-going -j auto`, so include any of those you still want: - make html SPHINXOPTS="-T" + make html SPHINXOPTS="-W --keep-going -j auto -T" For more flexibility and customization, take a look at the Makefile for all variables you can pass in and overwrite. diff --git a/tools/board_stubs/build_board_specific_stubs/board_stub_builder.py b/tools/board_stubs/build_board_specific_stubs/board_stub_builder.py index fb6219f373b..7c80f0e476d 100644 --- a/tools/board_stubs/build_board_specific_stubs/board_stub_builder.py +++ b/tools/board_stubs/build_board_specific_stubs/board_stub_builder.py @@ -160,7 +160,6 @@ def create_board_stubs(board_id, records, mappings, board_filename): boards_file.write(f"Board stub for {mappings['board_name']}\n") boards_file.write(f" - port: {mappings['port']}\n") boards_file.write(f" - board_id: {board_id}\n") - boards_file.write(f" - NVM size: {mappings['nvm_size']}\n") boards_file.write(f" - Included modules: {included_modules}\n") boards_file.write(f" - Frozen libraries: {frozen_libraries}\n") boards_file.write('"""\n\n') @@ -261,20 +260,27 @@ def process(board_mappings, export_dir): print(f" - {board}") -def build_stubs(circuitpython_dir, circuitpython_org_dir, export_dir, version="8.2.9"): +def build_stubs( + circuitpython_dir, circuitpython_org_dir, export_dir, version="8.2.9", board_data_path=None +): if circuitpython_dir[-1] != "/": circuitpython_dir = circuitpython_dir + "/" sys.path.append(circuitpython_dir) - from docs import shared_bindings_matrix + from tools import shared_bindings_matrix if not os.path.exists(export_dir): os.makedirs(export_dir) + collected = shared_bindings_matrix.collect_board_data() + if board_data_path: + # conf.py reads this so it doesn't have to collect the same data again. + shared_bindings_matrix.write_board_data(board_data_path, collected) + libraries = {} if circuitpython_org_dir is None: libraries = shared_bindings_matrix.support_matrix_by_board( - use_branded_name=False, withurl=False + use_branded_name=False, withurl=False, board_data=collected ) else: with open(f"{circuitpython_org_dir}/_data/files.json") as libraries_file: @@ -306,38 +312,16 @@ def build_stubs(circuitpython_dir, circuitpython_org_dir, export_dir, version="8 board_mappings[board]["pins_filename"] = pins_path - nvm_size = "Unknown" - with open(f"{port_path}/mpconfigport.h") as get_name: - port_contents = get_name.read() - port_nvm_re = re.search( - r"(?<=#define CIRCUITPY_INTERNAL_NVM_SIZE)\s+(.+)", port_contents - ) - if port_nvm_re: - nvm_size = port_nvm_re.group(1).strip() - - board_name = board - with open(f"{board_path}/mpconfigboard.h") as get_name: - board_contents = get_name.read() - board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", board_contents) - if board_name_re: - board_name = board_name_re.group(1).strip('"') - - port_nvm_re = re.search( - r"(?<=#define CIRCUITPY_INTERNAL_NVM_SIZE)\s+(.+)", port_contents - ) - if port_nvm_re: - nvm_size = port_nvm_re.group(1).strip() - - nvm_size_re = re.search(r"^[0-9\(\) *]*$", nvm_size) - if nvm_size_re: - nvm_size = eval(nvm_size_re.group(0)) - - board_mappings[board]["board_name"] = board_name - board_mappings[board]["nvm_size"] = nvm_size + board_mappings[board]["board_name"] = collected[lookup]["branded_name"] board_mappings[board]["libraries"] = libraries.get(board, None) process(board_mappings, export_dir) if __name__ == "__main__": - build_stubs("./", None, "circuitpython-stubs/board_definitions/") + build_stubs( + "./", + None, + "circuitpython-stubs/board_definitions/", + board_data_path="circuitpython-stubs/board_data.json", + ) diff --git a/tools/board_stubs/circuitpython_setboard/__init__.py b/tools/board_stubs/circuitpython_setboard/__init__.py index 69a405405b8..e5fb2d7c973 100644 --- a/tools/board_stubs/circuitpython_setboard/__init__.py +++ b/tools/board_stubs/circuitpython_setboard/__init__.py @@ -74,13 +74,12 @@ def set_board(): # Board stub for ... # - port: ... # - board_id: ... - # - NVM size: ... # - Included modules: ... # - Frozen libraries: ... # lines = get_doc_or_exit(board).split("\n") - port = lines[2].split("-")[1].split(":")[1].strip() + port = lines[2].split(":", 1)[1].strip() if looking_for not in board.name.lower() and looking_for not in port.lower(): continue diff --git a/tools/board_summaries.py b/tools/board_summaries.py index 3ea87e68d55..741c26dfdc2 100644 --- a/tools/board_summaries.py +++ b/tools/board_summaries.py @@ -22,9 +22,6 @@ # import re -import sys - -sys.path.append("../docs") from shared_bindings_matrix import support_matrix_by_board @@ -185,7 +182,7 @@ def write_csvs(rows=1000, present="1", absent="0"): "frozen": frozen_incidence_matrix_csvs(s, rows=rows, present=present, absent=absent), "pins": board_pins_matrix_csvs(s, rows=rows), } - for key, values in csvs: + for key, values in csvs.items(): for i in range(len(values)): filename = f"{key}_{i}.csv" print(f"writing {filename}") diff --git a/tools/board_to_port.py b/tools/board_to_port.py index 325105f9873..44acdcc2842 100644 --- a/tools/board_to_port.py +++ b/tools/board_to_port.py @@ -5,10 +5,7 @@ # SPDX-License-Identifier: MIT import sys -from pathlib import Path -docs = Path(__file__).parent.parent / "docs" -sys.path.append(str(docs)) from shared_bindings_matrix import get_board_mapping board = sys.argv[1] diff --git a/tools/build_board_info.py b/tools/build_board_info.py index bd9452b2626..24531f516b8 100755 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -19,7 +19,6 @@ sys.path.append("adabot") import adabot.github_requests as github -sys.path.append("../docs") from shared_bindings_matrix import ( SUPPORTED_PORTS, support_matrix_by_board, diff --git a/tools/build_release_files.py b/tools/build_release_files.py index 4394cf931d9..d2018d3b95c 100755 --- a/tools/build_release_files.py +++ b/tools/build_release_files.py @@ -16,7 +16,6 @@ import json import tomllib -sys.path.append("../docs") from shared_bindings_matrix import get_settings_from_makefile TOP = pathlib.Path(__file__).resolve().parent.parent diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index 971583e28d5..d5928bff694 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -35,7 +35,6 @@ top_dir = tools_dir.parent sys.path.insert(0, str(tools_dir / "adabot")) -sys.path.insert(0, str(top_dir / "docs")) import build_board_info from shared_bindings_matrix import ( @@ -49,9 +48,11 @@ "conf.py", "docs", "tests", + "tools/board_stubs/", "tools/ci_changes_per_commit.py", "tools/ci_check_duplicate_usb_vid_pid.py", "tools/ci_set_matrix.py", + "tools/shared_bindings_matrix.py", ".github/workflows/run-tests.yml", ".github/workflows/run-zephyr-tests.yml", ".github/workflows/build-board-custom.yml", @@ -66,8 +67,8 @@ } PATTERN_DOCS = ( - r"^(?:\.github|docs|extmod\/ulab)|" - r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|\.readthedocs\.yml|conf\.py|requirements-doc\.txt)$|" + r"^(?:\.github|docs|extmod\/ulab|tools\/board_stubs\/)|" + r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|tools\/shared_bindings_matrix\.py|\.readthedocs\.yml|conf\.py|requirements-doc\.txt)$|" r"(?:-stubs|\.(?:md|MD|mk|rst|RST)|/Makefile)$" ) @@ -75,21 +76,28 @@ # The Zephyr tests build native_sim and the two bsim boards out of the shared sources, so a # change confined to these cannot reach them: another port, a translation, a frozen library -# (this port has none), documentation, the unix test suite or the autogen PR workflow. +# (this port has none), documentation, the board stub tools, the unix test suite or the +# autogen PR workflow. PATTERN_ZEPHYR_TESTS_IGNORE = re.compile( - r"^(?:docs|frozen|locale|tests)/|^ports/(?!zephyr-cp/)" - r"|^\.github/workflows/zephyr-autogen-pr\.yml$" + r"^(?:docs|frozen|locale|tests|tools/board_stubs)/|^ports/(?!zephyr-cp/)" + r"|^\.github/workflows/zephyr-autogen-pr\.yml$|^tools/shared_bindings_matrix\.py$" ) -# Files that can't affect the unix coverage tests: other ports and the documentation. -# The tests build nothing from ports/ except ports/unix. frozen/ is not on this list, -# because run-tests.py puts the frozen asyncio and Ticks libraries on the module search path. -PATTERN_TESTS_IGNORE = re.compile(r"^docs/|^ports/(?!unix/)") +# Files that can't affect the unix coverage tests: other ports and the documentation, +# including the docs' support matrix code and the board stub tools. The tests build nothing +# from ports/ except ports/unix. frozen/ is not on this list, because run-tests.py puts the +# frozen asyncio and Ticks libraries on the module search path. +PATTERN_TESTS_IGNORE = re.compile( + r"^(?:docs|tools/board_stubs)/|^ports/(?!unix/)|^tools/shared_bindings_matrix\.py$" +) -# Files that can't affect mpy-cross: ports, frozen libraries, the documentation and the tests. -# The board builds don't need the mpy-cross and mpy-cross-mac jobs. They use the mpy-cross -# that the scheduler job builds. -PATTERN_MPY_CROSS_IGNORE = re.compile(r"^(?:docs|frozen|ports|tests)/") +# Files that can't affect mpy-cross: ports, frozen libraries, the documentation (including +# the support matrix code and the board stub tools) and the tests. The board builds don't +# need the mpy-cross and mpy-cross-mac jobs. They use the mpy-cross that the scheduler job +# builds. +PATTERN_MPY_CROSS_IGNORE = re.compile( + r"^(?:docs|frozen|ports|tests|tools/board_stubs)/|^tools/shared_bindings_matrix\.py$" +) # Zephyr boards don't use make, so their module tables can't be computed here. Each # board's build writes autogen_board_info.toml next to its circuitpython.toml and that diff --git a/docs/shared_bindings_matrix.py b/tools/shared_bindings_matrix.py similarity index 63% rename from docs/shared_bindings_matrix.py rename to tools/shared_bindings_matrix.py index b80566283ac..c92487a4ca9 100644 --- a/docs/shared_bindings_matrix.py +++ b/tools/shared_bindings_matrix.py @@ -318,173 +318,201 @@ def lookup_setting(settings, key, default=""): return value -def support_matrix_by_board( - use_branded_name=True, - withurl=True, - add_port=False, - add_chips=False, - add_pins=False, - add_branded_name=False, -): - """Compiles a list of the available core modules available for each - board. +def get_branded_name(board_id, board_directory, autogen_board_info): + """Return the board's product name, falling back to its board id.""" + if autogen_board_info: + # Many zephyr-cp boards share a name with a native board, so tell them apart. + return autogen_board_info["name"] + " (Zephyr)" + with open(board_directory / "mpconfigboard.h") as f: + board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", f.read()) + if not board_name_re: + return board_id + branded_name = board_name_re.group(1).strip('"') + if '"' in branded_name: # sometimes the closing " is not at line end + branded_name = branded_name[: branded_name.index('"')] + return branded_name + + +def get_mcu_and_flash(board_directory, autogen_board_info): + """Return the board's MCU name and its external flash chips as a quoted, comma-separated string. + + zephyr-cp boards don't record either yet, so they get empty strings. + """ + if autogen_board_info: + return "", "" + with open(board_directory / "mpconfigboard.h") as f: + mcu_re = re.search(r"(?<=MICROPY_HW_MCU_NAME)\s+(.+)", f.read()) + mcu = "" + if mcu_re: + mcu = mcu_re.group(1).strip('"') + if '"' in mcu: # in case the closing " is not at line end + mcu = mcu[: mcu.index('"')] + with open(board_directory / "mpconfigboard.mk") as f: + flash_re = re.search(r"(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)", f.read()) + flash = "" + if flash_re: + # Multiple flash chips are written in several ways. Normalize them to + # a quoted, comma-separated string. + flash = '"' + flash_re.group(1).replace('"', "") + '"' + return mcu, flash + + +def get_pins(board_directory): + """Return the board's [board_pin, chip_pin] pairs from pins.c.""" + try: + with open(board_directory / "pins.c") as f: + pin_lines = f.readlines() + except FileNotFoundError: # silabs and zephyr-cp boards have no pins.c + return [] + pins = [] + for line in pin_lines: + if pin_re := re.search(r"QSTR_([^\)]+).+pin_([^\)]+)", line): + pins.append([pin_re.group(1), pin_re.group(2)]) + return pins + + +def get_board_modules(settings, autogen_board_info, base): + """Return the sorted names of the modules enabled on the board.""" + if autogen_board_info: + modules = [k for k, enabled in autogen_board_info["modules"].items() if enabled] + else: + modules = [ + info["name"] + for info in base.values() + if int(lookup_setting(settings, info["key"], "0")) + ] + return sorted(modules) + + +def get_board_extensions(board_id, settings): + """Return the file extensions the board's build produces, such as ["uf2"].""" + if "CIRCUITPY_BUILD_EXTENSIONS" not in settings: + raise OSError(f"Board extensions undefined: {board_id}.") + extensions = settings["CIRCUITPY_BUILD_EXTENSIONS"] + if isinstance(extensions, str): + extensions = [extension.strip() for extension in extensions.split(",")] + return extensions + + +def collect_board_data(): + """Gather what support_matrix_by_board() needs about every board, keyed by board id. + + Aliases are left out; support_matrix_by_board() adds them. The result holds + only JSON types, so it can be saved and reused. + + This runs make once for each board outside zephyr-cp, which takes a while. """ base = build_module_map() - def support_matrix(arg): + def collect(arg): board_id, board_info = arg port = board_info["port"] board_directory = board_info["directory"] - port_dir = board_directory.parent.parent - if port != "zephyr-cp": + if port == "zephyr-cp": + with (board_directory / "circuitpython.toml").open("rb") as f: + settings = tomllib.load(f) + with (board_directory / "autogen_board_info.toml").open("rb") as f: + autogen_board_info = tomllib.load(f) + else: + port_dir = board_directory.parent.parent settings = get_settings_from_makefile(str(port_dir), board_directory.name) autogen_board_info = None - else: - circuitpython_toml_fn = board_directory / "circuitpython.toml" - with circuitpython_toml_fn.open("rb") as f: - settings = tomllib.load(f) - autogen_board_info_fn = board_directory / "autogen_board_info.toml" - with autogen_board_info_fn.open("rb") as f: - autogen_board_info = tomllib.load(f) + frozen_libraries = [] + if "FROZEN_MPY_DIRS" in settings: + frozen_libraries = [ + list(library) + for library in sorted( + frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"], withurl=True) + ) + ] + + mcu, flash = get_mcu_and_flash(board_directory, autogen_board_info) + return board_id, { + "port": port, + "branded_name": get_branded_name(board_id, board_directory, autogen_board_info), + "mcu": mcu, + "flash": flash, + "pins": get_pins(board_directory), + "modules": get_board_modules(settings, autogen_board_info, base), + "extensions": get_board_extensions(board_id, settings), + # [name, repository url] pairs + "frozen_libraries": frozen_libraries, + } - if use_branded_name or add_branded_name: - if autogen_board_info: - # Many zephyr-cp boards share a name with a native board, so tell them apart. - branded_name = autogen_board_info["name"] + " (Zephyr)" - else: - with open(board_directory / "mpconfigboard.h") as get_name: - board_contents = get_name.read() - board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", board_contents) - if board_name_re: - branded_name = board_name_re.group(1).strip('"') - if '"' in branded_name: # sometimes the closing " is not at line end - branded_name = branded_name[: branded_name.index('"')] - board_name = branded_name - - if use_branded_name: - board_name = branded_name - else: - board_name = board_id + real_boards = [ + (board_id, board_info) + for board_id, board_info in get_board_mapping().items() + if not board_info.get("alias", False) + ] + with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor: + return dict(executor.map(collect, real_boards)) - if add_chips: - with open(board_directory / "mpconfigboard.h") as get_name: - board_contents = get_name.read() - mcu_re = re.search(r"(?<=MICROPY_HW_MCU_NAME)\s+(.+)", board_contents) - if mcu_re: - mcu = mcu_re.group(1).strip('"') - if '"' in mcu: # in case the closing " is not at line end - mcu = mcu[: mcu.index('"')] - else: - mcu = "" - with open(board_directory / "mpconfigboard.mk") as get_name: - board_contents = get_name.read() - flash_re = re.search(r"(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)", board_contents) - if flash_re: - # deal with the variability in the way multiple flash chips - # are denoted. We want them to end up as a quoted, - # comma separated string - flash = flash_re.group(1).replace('"', "") - flash = f'"{flash}"' - else: - flash = "" - if add_pins: - pins = [] - try: - with open(board_directory / "pins.c") as get_name: - pin_lines = get_name.readlines() - except FileNotFoundError: # silabs boards have no pins.c - pass - else: - for p in pin_lines: - pin_re = re.search(r"QSTR_([^\)]+).+pin_([^\)]+)", p) - if pin_re: - board_pin = pin_re.group(1) - chip_pin = pin_re.group(2) - pins.append((board_pin, chip_pin)) - - board_modules = [] - if autogen_board_info: - autogen_modules = autogen_board_info["modules"] - for k in autogen_modules: - if autogen_modules[k]: - board_modules.append(k) - else: - for module in base: - key = base[module]["key"] - if int(lookup_setting(settings, key, "0")): - board_modules.append(base[module]["name"]) - board_modules.sort() - - if "CIRCUITPY_BUILD_EXTENSIONS" in settings: - board_extensions = settings["CIRCUITPY_BUILD_EXTENSIONS"] - if isinstance(board_extensions, str): - board_extensions = [extension.strip() for extension in board_extensions.split(",")] - else: - raise OSError(f"Board extensions undefined: {board_name}.") +def write_board_data(path, board_data): + """Save the output of collect_board_data() as JSON.""" + # Keep the board order: when boards share a product name, the last one wins. + with open(path, "w") as f: + json.dump(board_data, f, indent=1) - frozen_modules = [] - if "FROZEN_MPY_DIRS" in settings: - frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"], withurl) - if frozen_modules: - frozen_modules.sort() - # generate alias boards too +def read_board_data(path): + """Return board data saved by write_board_data(), or None if path doesn't exist.""" + try: + with open(path) as f: + return json.load(f) + except FileNotFoundError: + return None + + +def support_matrix_by_board( + use_branded_name=True, + withurl=True, + add_port=False, + add_chips=False, + add_pins=False, + add_branded_name=False, + board_data=None, +): + """Return each board's modules, frozen libraries and build extensions. + + Aliases get their own entries. Keys are board ids, or product names if + use_branded_name is set. The add_* flags add more fields. - board_info = { - "modules": board_modules, - "frozen_libraries": frozen_modules, - "extensions": board_extensions, + board_data is the output of collect_board_data(). If it is None, it is collected here. + """ + if board_data is None: + board_data = collect_board_data() + + def board_entry(data): + entry = { + "modules": data["modules"], + "frozen_libraries": [ + tuple(library) if withurl else library[0] for library in data["frozen_libraries"] + ], + "extensions": data["extensions"], } if add_branded_name: - board_info["branded_name"] = branded_name + entry["branded_name"] = data["branded_name"] if add_port: - board_info["port"] = port + entry["port"] = data["port"] if add_chips: - board_info["mcu"] = mcu - board_info["flash"] = flash + entry["mcu"] = data["mcu"] + entry["flash"] = data["flash"] if add_pins: - board_info["pins"] = pins - board_matrix = [(board_name, board_info)] - if board_id in ALIASES_BY_BOARD: - for alias in ALIASES_BY_BOARD[board_id]: - if use_branded_name: - if alias in ALIASES_BRAND_NAMES: - alias = ALIASES_BRAND_NAMES[alias] - else: - alias = alias.replace("_", " ").title() - board_info = { - "modules": board_modules, - "frozen_libraries": frozen_modules, - "extensions": board_extensions, - } - if add_branded_name: - board_info["branded_name"] = branded_name - if add_port: - board_info["port"] = port - if add_chips: - board_info["mcu"] = mcu - board_info["flash"] = flash - if add_pins: - board_info["pins"] = pins - board_matrix.append((alias, board_info)) - - return board_matrix # this is now a list of (board,modules) - - board_mapping = get_board_mapping() - real_boards = [] - for board in board_mapping: - if not board_mapping[board].get("alias", False): - real_boards.append((board, board_mapping[board])) - executor = ThreadPoolExecutor(max_workers=os.cpu_count()) - mapped_exec = executor.map(support_matrix, real_boards) - # flatmap with comprehensions - boards = dict( - sorted([board for matrix in mapped_exec for board in matrix], key=lambda x: x[0]) - ) - - return boards + entry["pins"] = [tuple(pin) for pin in data["pins"]] + return entry + + boards = [] + for board_id, data in board_data.items(): + boards.append((data["branded_name"] if use_branded_name else board_id, board_entry(data))) + for alias in ALIASES_BY_BOARD.get(board_id, []): + if use_branded_name: + alias = ALIASES_BRAND_NAMES.get(alias, alias.replace("_", " ").title()) + boards.append((alias, board_entry(data))) + + # Several boards can share a product name; the last one listed wins. + return dict(sorted(boards, key=lambda board: board[0])) if __name__ == "__main__":