doc: move 'board.inc' generation 'boards.py'

This commit is contained in:
umarcor 2022-01-12 01:52:55 +01:00
parent 4be407a379
commit 57e9860b43
2 changed files with 46 additions and 24 deletions

39
doc/boards.py Normal file
View File

@ -0,0 +1,39 @@
from pathlib import Path
from dataclasses import dataclass
from yaml import load as yaml_load, Loader as yaml_loader, dump as yaml_dump
from tabulate import tabulate
ROOT = Path(__file__).resolve().parent
@dataclass
class Board:
ID: str
Description: str = None
URL: str = None
FPGA: str = None
Memory: str = None
Flash: str = None
def ReadDataFromYAML():
with (ROOT / 'boards.yml').open('r', encoding='utf-8') as fptr:
data = [Board(**item) for item in yaml_load(fptr, yaml_loader)]
return data
def DataToTable(data, tablefmt: str = "rst"):
return tabulate(
[
[
item.ID,
f"`{item.Description} <{item.URL}>`__",
item.FPGA,
item.Memory,
item.Flash
] for item in data
],
headers=["Board name", "Description", "FPGA", "Memory", "Flash"],
tablefmt=tablefmt
)

View File

@ -5,10 +5,15 @@ from os.path import abspath
from pathlib import Path
from json import loads
ROOT = Path(__file__).resolve().parent
sys_path.insert(0, abspath("."))
from boards import ReadDataFromYAML, DataToTable
# -- General configuration ------------------------------------------------
extensions = [
@ -102,29 +107,7 @@ extlinks = {
"ghsrc": ("https://github.com/trabucayre/openFPGALoader/blob/master/%s", None),
}
# -- Read board data from boards.yml
from dataclasses import dataclass
from yaml import load as yaml_load, Loader as yaml_loader, dump as yaml_dump
from tabulate import tabulate
@dataclass
class Board:
ID: str
Description: str = None
URL: str = None
FPGA: str = None
Memory: str = None
Flash: str = None
with (ROOT / 'boards.yml').open('r', encoding='utf-8') as fptr:
data = [Board(**item) for item in yaml_load(fptr, yaml_loader)]
table = tabulate(
[[item.ID, f"`{item.Description} <{item.URL}>`__", item.FPGA, item.Memory, item.Flash] for item in data],
headers=["Board name", "Description", "FPGA", "Memory", "Flash"],
tablefmt="rst"
)
# -- Generate partial board compatibility page (`board.inc`) with data from `boards.yml`
with (ROOT / "compatibility/boards.inc").open("w", encoding="utf-8") as wptr:
wptr.write(table)
wptr.write(DataToTable(ReadDataFromYAML()))