# Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # 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. # import os import sys import os.path import json import datetime from sphinx.builders.html import StandaloneHTMLBuilder # -- Project information ----------------------------------------------------- # TODO # WHAT TO DO ABOUT COPYRIGHTS - this is for all the docs! not the cof.py file itself! # current_year = datetime.datetime.now().year current_day = datetime.datetime.now().strftime("%Y/%m/%d") copyright = '{}, XMOS Ltd'.format(current_year) # maybe make this a range but not sure where to start from author = 'XMOS Ltd' xmos_trademarks = 'XMOS, XCORE, VocalFusion and the XMOS logo' xmos_disclaimer = f'''XMOS Ltd. is the owner or licensee of this design, code, or Information (collectively, the “Information”) and is providing it to you “AS IS” with no warranty of any kind, express or implied and shall have no liability in relation to its use. XMOS Ltd makes no representation that the Information, or any particular implementation thereof, is or will be free from any claims of infringement and again, shall have no liability in relation to any such claims. { xmos_trademarks } are registered trademarks of XMOS Ltd. in the United Kingdom and other countries and may not be used without written permission. Company and product names mentioned in this document are the trademarks or registered trademarks of their respective owners. ''' # ---------------------------------------------- # conf files path conf_files_dir = os.path.dirname(__file__) # Set DEV_MODE from env var DEV_MODE = os.getenv('DEV', False) if DEV_MODE: todo_include_todos = True # Get repo structure from env vars repo = os.path.realpath(os.getenv('REPO', '..')) doc_dir = repo + '/' + os.getenv('DOC_DIR', 'doc') doxy_dir = os.getenv('DOXYGEN_OUTPUT', doc_dir + "/_build/_doxygen") template_dir = os.getenv('TEMPLATE_DIR', doc_dir + "/_templates") # to set project name and version which show up below the XMOS logo title = os.getenv('TITLE', '') project = os.getenv('PROJECT', '') release = os.getenv('VERSION', '') # only look for settings file if env vars don't provide version if title=='' or project=='' or release=='': settingsFile = repo + '/settings.json' data = {} if os.path.isfile(settingsFile): with open(settingsFile) as infile: data = json.load(infile) title = data.get('title', 'TMP') if title=='' else title project = data.get('project', 'TMP') if project=='' else project release = data.get('version', 'TBD') if release=='' else release # set derivative variables for sphinx to use if release == 'TBD': version = 'TBD' else: version = release.rpartition('.')[0] # set rst substitutions # version/release done automatically rst_prolog = f""" .. |project| replace:: {project} .. |title| replace:: {title} """ # ---------------------------------------------- StandaloneHTMLBuilder.supported_image_types = [ 'image/svg+xml', 'image/gif', 'image/png', 'image/jpeg', ] # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.todo', 'sphinx_copybutton', 'sphinx_inline_tabs', 'breathe', 'sphinx.ext.autosectionlabel', 'sphinxcontrib.wavedrom', 'myst_parser', 'sphinx.ext.mathjax', ] myst_enable_extensions = [ "dollarmath"] # Breathe Configuration breathe_projects = {title: doxy_dir + '/xml/'} breathe_default_project = title # Add support for Sphinx domains: # https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#the-c-domain breathe_domain_by_extension = { "h" : "c" } # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # Generate disclaimer rst for inclusion into top-level TOC # ./doc/_templates/disclaimer.rst with open(template_dir + '/disclaimer.rst' , "w") as outFile: outFile.write("Copyright & Disclaimer\n") outFile.write("======================\n\n") outFile.write("Copyright © " + copyright) outFile.write("\n\n") outFile.write(xmos_disclaimer) # 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. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.venv', '.github', 'README*', '**/README*', 'CHANGELOG*', '**/CHANGELOG*', 'LICENSE*', '**/LICENSE*', 'CONTRIBUTIONS*', '**/CONTRIBUTIONS*', 'COPYRIGHTS*', '**/COPYRIGHTS*'] # Append any exclude patterns specified by caller # User specified exclude patterns are handy when a repo # contains submodules that contain .rst files one wants # to ignore. exclude_patterns_fn = os.getenv('EXCLUDE_PATTERNS') if exclude_patterns_fn: with open(exclude_patterns_fn) as exclude_patterns_file: for line in exclude_patterns_file: if not line.startswith('#'): exclude_patterns.append(line.strip()) # Wavedrom config # https://pypi.org/project/sphinxcontrib-wavedrom/ render_using_wavedrompy = True # use python implementation so no npm/node wavedrom_html_jsinline = False # always generate images even for html # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'furo' # Override the default format that adds the word "documentation" to the project and release html_title = '{} {}'.format(title, release) # Add the last updated on html_last_updated_fmt = '%b %d, %Y' # Don't copy the rst sources into the output folder html_copy_source = False # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = [doc_dir + '/src_html', conf_files_dir] html_css_files = ['custom.css'] html_logo = conf_files_dir + '/xmos_logo.png' xmos_grey_dark = '#464749' xmos_grey_light = '#D1D3D4' xmos_blue_dark = '#1399DB' xmos_blue_light = '#44BBF1' xmos_green_dark = '#99DA07' xmos_green_light = '#B8E720' html_theme_options = { 'sidebar_hide_name' : False, 'light_css_variables': { 'color-brand-primary': xmos_blue_dark, 'color-brand-content': xmos_blue_dark, }, 'dark_css_variables': { 'color-brand-primary': xmos_blue_dark, 'color-brand-content': xmos_blue_dark, } } html_sidebars = {'**':[ 'sidebar/brand.html', 'sidebar/search.html', 'sidebar/scroll-start.html', 'sidebar/navigation.html', 'sidebar/scroll-end.html', 'sidebar/variant-selector.html' ]} # -- Options for latex output ------------------------------------------------ # Include xmos specific style files # latex_additional_files = [conf_files_dir + '/xcore.cls'] # Include xmos specific style files tex_dir = os.path.join(conf_files_dir, "tex_inputs") latex_additional_files = [os.path.join(tex_dir, f) for f in os.listdir(tex_dir)] latex_logo = conf_files_dir + '/xmos_logo.png' latex_engine = "pdflatex" # "xelatex" latex_toc_depth = os.getenv('LATEX_TOC_DEPTH', '3') latex_preamble = rf""" \newcommand{{\licenseeTrademark}}{{{xmos_disclaimer}}} \usepackage{{xmos}} % toc settings in sphinx hook \renewcommand{{\sphinxtableofcontentshook}}{{ \renewcommand{{\contentsname}}{{Table of Contents}} \setcounter{{tocdepth}}{{{latex_toc_depth}}} }} """ # https://www.sphinx-doc.org/en/master/latex.html latex_elements = { "papersize": "a4paper", "pointsize": "10pt", "fontpkg": r""" \usepackage[sfdefault,light]{roboto} \renewcommand{\familydefault}{\sfdefault} """, "fncychap": "", # "fncychap": "\\usepackage[Sonny]{fncychap}", "preamble": latex_preamble, "atendofbody": "", "figure_align": "H", # openany/oneside reduce blank pages "extraclassoptions": "oneside,onecolumn,article,9pt", # "openany,oneside", # "oneside,onecolumn,article,10pt", "inputenc": "\\usepackage[utf8]{inputenc}", "cmappkg": "\\usepackage{cmap}", "maketitle": rf""" \thispagestyle{{titlestyle}} \hypersetup{{ pdftitle = {{{title}}}, colorlinks = true, linkcolor = xmosblue, citecolor = xmosblue, urlcolor = xmosblue, }} \noindent\\[15cm]{{\huge\sffamily \thetitle}}\\\vspace*{{1mm}}{{\xmosblue\rule{{2.5cm}}{{2mm}}}} \\[1mm]Release: {release} \\[1mm]Publication Date: {current_day} \\[0.1cm] """, "releasename": "", # Release "tableofcontents": """ \\tocchapterstyle \\sphinxtableofcontents \\normalchapterstyle""", "transition": "\n\n\\bigskip\\hrule\\bigskip\n\n", "makeindex": "\\makeindex", "printindex": "\\printindex", "extrapackages": "\\usepackage{longtable}", "sphinxsetup": r"verbatimwithframe=false, hmargin={0.8in,1in}, vmargin={1in,1in}, marginpar=0.5in", } # Choose which get written as separate pdfs latex_documents = [] seen = [] for root, dirs, files in os.walk(doc_dir): # check for all index.rst if 'index.rst' in files: # skip top level if root==repo: continue # skip if we've already seen a level above this # ie dont add userguide/something/index if we already have userguide/index if any(s in root for s in seen): continue seen.append(root) doc_title = root.split('/')[-1] doc_type = 'manual' # https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-latex_documents latex_documents.append(( root.replace(repo+'/', '')+'/index', doc_title + '.tex', title + ' - ' + doc_title.replace('_', ' ').title(), author, doc_type, False, )) # Set URLS ignored by linkcheck linkcheck_ignore = [ "http://127.0.0.1:\d+/?", "http://localhost:\d+/?", ] # -- Options for sphinx_copybutton ------------------------------------------- copybutton_prompt_text = r"\$ |\(gdb\) " copybutton_prompt_is_regexp = True #My setup for figures numfig = True numfig_secnum_depth = 1 autosectionlabel_prefix_document = True