Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
conf.py 9.53 KiB
Newer Older
# BeagleBoard.org documentation build configuration file.
# 
# References: 
# https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/conf.py
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys
import re
import yaml
from pathlib import Path
Deepak Khatri's avatar
Deepak Khatri committed
import pydata_sphinx_theme
from sphinx.ext.imgconverter import ImagemagickConverter

# -- Project information --
project = 'BeagleBoard Docs'
copyright = '2024, BeagleBoard.org Foundation'
author = 'BeagleBoard.org Foundation'

Deepak Khatri's avatar
Deepak Khatri committed
ImagemagickConverter.conversion_rules.append(('image/webp', 'image/png'))
sys.path.append(str(Path(".").resolve()))

# Add latest images to rst_epilog
rst_epilog =""
Deepak Khatri's avatar
Deepak Khatri committed
rst_epilog_path = "_static/epilog/"
for (dirpath, dirnames, filenames) in os.walk(rst_epilog_path):
    for filename in filenames:
        with open(dirpath + filename) as f:
            rst_epilog += f.read()

# Configure PDF build and sidebar links
latex_documents = []
pdf_paths = []
Deepak Khatri's avatar
Deepak Khatri committed
oshw_details = []
with open('conf.yml', 'r') as conf_file:
    conf_data = yaml.safe_load(conf_file)

    pdf_build_all = True
    pdf_build = []
    if(conf_data["pdf_build"] != "all"):
Deepak Khatri's avatar
Deepak Khatri committed
        for name in conf_data["pdf_build"].split(","):
            pdf_build.append(name.lstrip())
        pdf_build_all = False

    for type, data in conf_data.items():
        # Boards
        if(type == "boards"):
            for board, data in conf_data["boards"].items():
                name = board
                path = data['path']
                pdf = data.get('pdf', False)
                
Deepak Khatri's avatar
Deepak Khatri committed
                # PDF build details
                if(pdf and (name in pdf_build or pdf_build_all)):
                    pdf_paths.append(path)
                    tex_name = '-'.join(path.split('/')[1:])
                    latex_documents.append((path+"/index", tex_name+".tex", "", author, "manual"))
Deepak Khatri's avatar
Deepak Khatri committed
                # OSHW mark details
                oshw_data = data.get('oshw', False)
                if oshw_data:
                    for oshw_mark_file in data['oshw'].split(','):
                        if oshw_mark_file.endswith('.svg'):
                            board, oshw_id = oshw_mark_file.lstrip().split(".")[0].split('_')
                            oshw_details.append([board, path, oshw_id])
Deepak Khatri's avatar
Deepak Khatri committed
# -- General configuration --
sys.path.append(os.path.abspath("./_ext"))

extensions = [
    "callouts",
    "sphinxcontrib.rsvgconverter",
    "sphinxcontrib.images",
    "sphinx.ext.imgconverter",
Mark Yoder's avatar
Mark Yoder committed
    "sphinx.ext.todo",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx_tabs.tabs",
    "sphinx_copybutton",
    "sphinxcontrib.youtube",
#graphviz_output_format = 'svg'

breathe_projects = {"librobotcontrol": "projects/librobotcontrol/docs/xml"}
breathe_default_project = "librobotcontrol"

exhale_args = {
    "containmentFolder": "./projects/librobotcontrol",
    "rootFileName": "index.rst",
    "rootFileTitle": "Robot Control Library",
    "createTreeView": True,
    "exhaleExecutesDoxygen": False,
    "doxygenStripFromPath": ".",
    "verboseBuild": False,
}

primary_domain = 'cpp'
highlight_language = 'cpp'

todo_include_todos = True
Deepak Khatri's avatar
Deepak Khatri committed
# Update (HTML) supported_image_types selection priority order
from sphinx.builders.html import StandaloneHTMLBuilder
StandaloneHTMLBuilder.supported_image_types = ['image/webp', 'image/jpg', 'image/jpeg', 'image/svg+xml', 'image/png', 'image/gif']
Deepak Khatri's avatar
Deepak Khatri committed
# Update (PDF) supported_image_types selection priority order
from sphinx.builders.latex import LaTeXBuilder
LaTeXBuilder.supported_image_types = ['application/pdf', 'image/jpg', 'image/jpeg', 'image/png']

templates_path = ['_templates']

Deepak Khatri's avatar
Deepak Khatri committed
source_suffix = ['.rst']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
Deepak Khatri's avatar
Deepak Khatri committed
templates_path = ['_templates']
Ayush Singh's avatar
Ayush Singh committed
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'env', ".venv"]
Deepak Khatri's avatar
Deepak Khatri committed
html_theme = 'pydata_sphinx_theme'
Deepak Khatri's avatar
Deepak Khatri committed
html_static_path = ["_static"]
Deepak Khatri's avatar
Deepak Khatri committed
html_logo = "_static/images/logo.svg"
html_favicon = "_static/images/boris.svg"
html_sourcelink_suffix = ""
html_last_updated_fmt = ""
html_theme_path = [pydata_sphinx_theme.Path()]
Deepak Khatri's avatar
Deepak Khatri committed
html_title = "BeagleBoard Documentation"
html_baseurl = "docs.beagleboard.io"
Deepak Khatri's avatar
Deepak Khatri committed
html_css_files = [
    'css/custom.css',
]

Deepak Khatri's avatar
Deepak Khatri committed
# html_sidebars = {
Deepak Khatri's avatar
Deepak Khatri committed

Deepak Khatri's avatar
Deepak Khatri committed
# }
Deepak Khatri's avatar
Deepak Khatri committed

html_theme_options = {
    "external_links": [
        {
            "url": "https://www.beagleboard.org/about",
            "name": "About",
        },
        {
            "url": "https://www.beagleboard.org/donate",
            "name": "Donate",
        },
        {
            "url": "https://gsoc.beagleboard.org/",
            "name": "GSoC",
        },
        {
            "url": "https://forum.beagleboard.org/c/faq",
            "name": "FAQ",
        },
    ],
Deepak Khatri's avatar
Deepak Khatri committed
    # "header_links_before_dropdown": 4,
Deepak Khatri's avatar
Deepak Khatri committed
    "show_prev_next": True,
    "icon_links": [
        {
            "name": "OpenBeagle",
            "url": "https://openbeagle.org/",
            "icon": "fa-brands fa-gitlab",
            "attributes": {"target": "_blank"},
        },
        {
            "name": "Docs",
            "url": "https://docs.beagleboard.org/",
            "icon": "fa-solid fa-book",
            "attributes": {"target": "_blank"},
        },
        {
            "name": "Discord",
            "url": "https://bbb.io/discord",
Deepak Khatri's avatar
Deepak Khatri committed
            "icon": "fa-brands fa-discord",
            "attributes": {"target": "_blank"},
        },
        {
            "name": "Forum",
            "url": "https://forum.beagleboard.org/",
Deepak Khatri's avatar
Deepak Khatri committed
            "icon": "fa-brands fa-discourse",
            "attributes": {"target": "_blank"},
        },
        {
            "name": "BeagleBoard.org",
            "url": "https://www.beagleboard.org",
            "icon": "_static/images/boris.svg",
            "type": "local",
            "attributes": {"target": "_blank"},
        }
    ],
    "use_edit_page_button": True,
    "show_toc_level": 1,
    "navbar_align": "right",
Deepak Khatri's avatar
Deepak Khatri committed
    "show_nav_level": 1,
    "announcement": "Welcome to new site for BeagleBoard.org docs!",
Deepak Khatri's avatar
Deepak Khatri committed
    # "show_version_warning_banner": True,
    "navbar_center": ["navbar-nav"],
    "navbar_start": ["navbar-logo"],
    "navbar_end": ["theme-switcher", "navbar-icon-links"],
    # "navbar_persistent": ["search-button"],
    "footer_start": ["copyright"],
    "footer_center": ["cc-by-sa"],
Deepak Khatri's avatar
Deepak Khatri committed
    "footer_end": ["last-updated"],
    # "content_footer_items": ["last-updated"],
    "secondary_sidebar_items": {
Deepak Khatri's avatar
Deepak Khatri committed
        "**": ["page-toc", "edit-this-page", "sourcelink","pdf","oshw"]
Deepak Khatri's avatar
Deepak Khatri committed
}
Deepak Khatri's avatar
Deepak Khatri committed
# parse version from 'VERSION' file
with open("VERSION") as f:
    m = re.match(
        (
            r"^VERSION_MAJOR\s*=\s*(\d+)$\n"
            + r"^VERSION_MINOR\s*=\s*(\d+)$\n"
            + r"^PATCHLEVEL\s*=\s*(\d+)$\n"
            + r"^VERSION_TWEAK\s*=\s*\d+$\n"
            + r"^EXTRAVERSION\s*=\s*(.*)$"
        ),
        f.read(),
        re.MULTILINE,
    )

    if not m:
        sys.stderr.write("Warning: Could not extract docs version\n")
        version = "Unknown"
    else:
        major, minor, patch, extra = m.groups(1)
        version = ".".join((major, minor, patch))
        release_version = ".".join((major, minor))
        if extra:
            version += "-" + extra

release = version
# Variables here holds default settings
Jason Kridner's avatar
Jason Kridner committed
pages_url = "https://docs.beagleboard.io"
Deepak Khatri's avatar
Deepak Khatri committed
pages_slug = ""
gitlab_user = "docs"
gitlab_version = "main"
Deepak Khatri's avatar
Deepak Khatri committed
gitlab_url = "https://openbeagle.org"
gitlab_repo = "docs.beagleboard.io"
Deepak Khatri's avatar
Deepak Khatri committed
docs_url = "https://docs.beagleboard.io"
# parse pages details from 'PAGES' file
with open("PAGES") as f:
    m = re.match(
        (
            r"^PAGES_URL\s*=\s*(\S+)$\n"
            + r"^PAGES_SLUG\s*=\s*(\S+)$\n"
            + r"^GITLAB_USER\s*=\s*(\S+)$\n"
            + r"^PROJECT_BRANCH\s*=\s*(\S+)$\n"
            + r"^GITLAB_HOST\s*=\s*(\S+)$\n"
            + r"^PROJECT_REPO\s*=\s*(\S+)$\n"
        ),
        f.read(),
        re.MULTILINE,
    )

    if not m:
        sys.stderr.write("Warning: Could not extract pages information\n")
    else:
        url, slug, user, branch, host, repo = m.groups(1)
        slug = "latest" if slug == "main" else slug
        pages_url = url
        pages_slug = slug
        gitlab_user = user
        gitlab_version = branch
        gitlab_url = host
        gitlab_repo = repo
        docs_url = "/".join((url, slug))
Deepak Khatri's avatar
Deepak Khatri committed
html_context = {
Deepak Khatri's avatar
Deepak Khatri committed
    "display_gitlab": True,
Deepak Khatri's avatar
Deepak Khatri committed
    "gitlab_url": gitlab_url,
    "gitlab_user": gitlab_user,
    "gitlab_repo": gitlab_repo,
    "gitlab_version": gitlab_version,
Deepak Khatri's avatar
Deepak Khatri committed
    "doc_path": "",
    #"use_edit_page_button": True,
    #"edit_page_url_template": "https://openbeagle.org/XXXX/{{ file_name }}",
Deepak Khatri's avatar
Deepak Khatri committed
    "conf_py_path": "",
    "show_license": True,
    "pages_url": pages_url,
Deepak Khatri's avatar
Deepak Khatri committed
    "pages_slug": pages_slug,
    "docs_url": docs_url,
Deepak Khatri's avatar
Deepak Khatri committed
    "edit_page_url_template": "{{ my_vcs_site }}{{ file_name }}",
    "edit_page_provider_name": "OpenBeagle",
    "my_vcs_site": "https://openbeagle.org/docs/docs.beagleboard.io/-/edit/main/",
Deepak Khatri's avatar
Deepak Khatri committed
    "oshw_details": oshw_details,
    "pdf_paths": pdf_paths
Deepak Khatri's avatar
Deepak Khatri committed
# -- Options for LaTeX output --
Deepak Khatri's avatar
Deepak Khatri committed
latex_engine = "xelatex"
latex_logo = "_static/images/logo-latex.pdf"
latex_elements = {
    "papersize": "a4paper",
    "maketitle": open("_static/latex/title.tex").read(),
    "preamble": open("_static/latex/preamble.tex").read(),
    "sphinxsetup": ",".join(
        (
            "verbatimwithframe=false",
            "VerbatimColor={HTML}{f0f2f4}",
            "InnerLinkColor={HTML}{2980b9}",
            "warningBgColor={HTML}{e9a499}",
            "warningborder=0pt",
            r"HeaderFamily=\rmfamily\bfseries",
        )
    ),