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
This commit is contained in:
Neradoc 2022-07-21 03:08:51 +02:00
parent eabe8b971a
commit f472996e80
2 changed files with 49 additions and 42 deletions

View File

@ -32,7 +32,7 @@ from concurrent.futures import ThreadPoolExecutor
SUPPORTED_PORTS = ['atmel-samd', 'broadcom', 'cxd56', 'espressif', 'litex', 'mimxrt10xx', 'nrf', 'raspberrypi', 'stm'] SUPPORTED_PORTS = ['atmel-samd', 'broadcom', 'cxd56', 'espressif', 'litex', 'mimxrt10xx', 'nrf', 'raspberrypi', 'stm']
aliases_by_board = { ALIASES_BY_BOARD = {
"circuitplayground_express": [ "circuitplayground_express": [
"circuitplayground_express_4h", "circuitplayground_express_4h",
"circuitplayground_express_digikey_pycon2019", "circuitplayground_express_digikey_pycon2019",
@ -43,7 +43,7 @@ aliases_by_board = {
"pewpew10": ["pewpew13"], "pewpew10": ["pewpew13"],
} }
aliases_brand_names = { ALIASES_BRAND_NAMES = {
"circuitplayground_express_4h": "circuitplayground_express_4h":
"Adafruit Circuit Playground Express 4-H", "Adafruit Circuit Playground Express 4-H",
"circuitplayground_express_digikey_pycon2019": "circuitplayground_express_digikey_pycon2019":
@ -58,7 +58,7 @@ aliases_brand_names = {
"PewPew 13", "PewPew 13",
} }
additional_modules = { ADDITIONAL_MODULES = {
"fontio": "CIRCUITPY_DISPLAYIO", "fontio": "CIRCUITPY_DISPLAYIO",
"terminalio": "CIRCUITPY_DISPLAYIO", "terminalio": "CIRCUITPY_DISPLAYIO",
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE", "adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
@ -66,7 +66,7 @@ additional_modules = {
"usb": "CIRCUITPY_USB_HOST", "usb": "CIRCUITPY_USB_HOST",
} }
frozen_excludes = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"] FROZEN_EXCLUDES = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
"""Files and dirs at the root of a frozen directory that should be ignored. """Files and dirs at the root of a frozen directory that should be ignored.
This is the same list as in the preprocess_frozen_modules script.""" This is the same list as in the preprocess_frozen_modules script."""
@ -74,7 +74,7 @@ repository_urls = {}
"""Cache of repository URLs for frozen modules.""" """Cache of repository URLs for frozen modules."""
def get_circuitpython_root_dir(): def get_circuitpython_root_dir():
""" The path to the root './circuitpython' directory """ The path to the root './circuitpython' directory.
""" """
file_path = pathlib.Path(__file__).resolve() file_path = pathlib.Path(__file__).resolve()
root_dir = file_path.parent.parent root_dir = file_path.parent.parent
@ -82,12 +82,40 @@ def get_circuitpython_root_dir():
return root_dir return root_dir
def get_shared_bindings(): def get_shared_bindings():
""" Get a list of modules in shared-bindings based on folder names """ Get a list of modules in shared-bindings based on folder names.
""" """
shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings" shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings"
return [item.name for item in shared_bindings_dir.iterdir()] + ["binascii", "errno", "json", "re", "ulab"] return [item.name for item in shared_bindings_dir.iterdir()] + ["binascii", "errno", "json", "re", "ulab"]
def get_board_mapping():
"""
Compiles the list of boards from the directories, with aliases and mapping
to the port.
"""
boards = {}
for port in SUPPORTED_PORTS:
board_path = os.path.join("../ports", port, "boards")
for board_path in os.scandir(board_path):
if board_path.is_dir():
board_files = os.listdir(board_path.path)
board_id = board_path.name
aliases = ALIASES_BY_BOARD.get(board_path.name, [])
boards[board_id] = {
"port": port,
"download_count": 0,
"aliases": aliases,
}
for alias in aliases:
boards[alias] = {
"port": port,
"download_count": 0,
"alias": True,
"aliases": [],
}
return boards
def read_mpconfig(): def read_mpconfig():
""" Open 'circuitpy_mpconfig.mk' and return the contents. """ Open 'circuitpy_mpconfig.mk' and return the contents.
""" """
@ -112,8 +140,8 @@ def build_module_map():
full_build = False full_build = False
for module in modules: for module in modules:
full_name = module full_name = module
if module in additional_modules: if module in ADDITIONAL_MODULES:
search_identifier = additional_modules[module] search_identifier = ADDITIONAL_MODULES[module]
else: else:
search_identifier = 'CIRCUITPY_'+module.lstrip("_").upper() search_identifier = 'CIRCUITPY_'+module.lstrip("_").upper()
re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)" re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)"
@ -211,14 +239,14 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
$(TOP)/frozen/circuitpython-stage/meowbit $(TOP)/frozen/circuitpython-stage/meowbit
Python modules are at the root of the path, and are python files or directories Python modules are at the root of the path, and are python files or directories
containing python files. Except the ones in the frozen_excludes list. containing python files. Except the ones in the FROZEN_EXCLUDES list.
""" """
frozen_modules = [] frozen_modules = []
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")): for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
source_dir = get_circuitpython_root_dir() / frozen_path[7:] source_dir = get_circuitpython_root_dir() / frozen_path[7:]
url_repository = get_repository_url(source_dir) url_repository = get_repository_url(source_dir)
for sub in source_dir.glob("*"): for sub in source_dir.glob("*"):
if sub.name in frozen_excludes: if sub.name in FROZEN_EXCLUDES:
continue continue
if sub.name.endswith(".py"): if sub.name.endswith(".py"):
if withurl: if withurl:
@ -279,7 +307,10 @@ def support_matrix_by_board(use_branded_name=True, withurl=True):
board_modules.sort() board_modules.sort()
if "CIRCUITPY_BUILD_EXTENSIONS" in settings: if "CIRCUITPY_BUILD_EXTENSIONS" in settings:
board_extensions = settings["CIRCUITPY_BUILD_EXTENSIONS"] board_extensions = [
extension.strip() for extension in
settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",")
]
else: else:
raise OSError(f"Board extensions undefined: {board_name}.") raise OSError(f"Board extensions undefined: {board_name}.")
@ -297,11 +328,11 @@ def support_matrix_by_board(use_branded_name=True, withurl=True):
"extensions": board_extensions, "extensions": board_extensions,
} }
)] )]
if entry.name in aliases_by_board: if entry.name in ALIASES_BY_BOARD:
for alias in aliases_by_board[entry.name]: for alias in ALIASES_BY_BOARD[entry.name]:
if use_branded_name: if use_branded_name:
if alias in aliases_brand_names: if alias in ALIASES_BRAND_NAMES:
alias = aliases_brand_names[alias] alias = ALIASES_BRAND_NAMES[alias]
else: else:
alias = alias.replace("_"," ").title() alias = alias.replace("_"," ").title()
board_matrix.append(( board_matrix.append((

View File

@ -19,11 +19,11 @@ import adabot.github_requests as github
sys.path.append("../docs") sys.path.append("../docs")
from shared_bindings_matrix import ( from shared_bindings_matrix import (
SUPPORTED_PORTS, SUPPORTED_PORTS,
aliases_by_board,
support_matrix_by_board, support_matrix_by_board,
get_board_mapping,
) )
language_allow_list = set( LANGUAGE_ALLOW_LIST = set(
[ [
"ID", "ID",
"de_DE", "de_DE",
@ -52,34 +52,10 @@ def get_languages(list_all=False):
if f.name.endswith(".po"): if f.name.endswith(".po"):
languages.add(f.name[:-3]) languages.add(f.name[:-3])
if not list_all: if not list_all:
languages = languages & language_allow_list languages = languages & LANGUAGE_ALLOW_LIST
return sorted(list(languages), key=str.casefold) return sorted(list(languages), key=str.casefold)
def get_board_mapping():
boards = {}
for port in SUPPORTED_PORTS:
board_path = os.path.join("../ports", port, "boards")
for board_path in os.scandir(board_path):
if board_path.is_dir():
board_files = os.listdir(board_path.path)
board_id = board_path.name
aliases = aliases_by_board.get(board_path.name, [])
boards[board_id] = {
"port": port,
"download_count": 0,
"aliases": aliases,
}
for alias in aliases:
boards[alias] = {
"port": port,
"download_count": 0,
"alias": True,
"aliases": [],
}
return boards
def get_version_info(): def get_version_info():
version = None version = None
sha = git("rev-parse", "--short", "HEAD").stdout.decode("utf-8") sha = git("rev-parse", "--short", "HEAD").stdout.decode("utf-8")