1# Configuration file for the Sphinx documentation builder. 2# 3# For information on options, see 4# http://www.sphinx-doc.org/en/master/config 5# 6# You may also find it helpful to run "sphinx-quickstart" in a scratch 7# directory and read the comments in the automatically-generated conf.py file. 8 9import os 10import sys 11import subprocess 12import re 13import datetime 14 15sys.path.append(os.getcwd()) 16sys.path.append(os.path.abspath('./ext')) 17 18import add_man_page_redirects 19import build_classic_docs 20import make_links_relative 21import update_htmlmap_links 22 23 24if not os.path.isdir("images"): 25 print("-----------------------------------------------------------------------------") 26 print("ERROR") 27 print("images directory does not seem to exist.") 28 print("To clone the required repository, try") 29 print(" make images") 30 print("-----------------------------------------------------------------------------") 31 raise Exception("Aborting because images missing") 32 33 34# -- Project information ------------------------------------------------------- 35 36project = 'PETSc' 37copyright = '1991-%d, UChicago Argonne, LLC and the PETSc Development Team' % datetime.date.today().year 38author = 'The PETSc Development Team' 39 40with open(os.path.join('..', 'include', 'petscversion.h'),'r') as version_file: 41 buf = version_file.read() 42 petsc_release_flag = re.search(' PETSC_VERSION_RELEASE[ ]*([0-9]*)',buf).group(1) 43 major_version = re.search(' PETSC_VERSION_MAJOR[ ]*([0-9]*)',buf).group(1) 44 minor_version = re.search(' PETSC_VERSION_MINOR[ ]*([0-9]*)',buf).group(1) 45 subminor_version = re.search(' PETSC_VERSION_SUBMINOR[ ]*([0-9]*)',buf).group(1) 46 47 git_describe_version = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8') 48 if petsc_release_flag == '0': 49 version = git_describe_version 50 release = git_describe_version 51 else: 52 version = '.'.join([major_version, minor_version]) 53 release = '.'.join([major_version,minor_version,subminor_version]) 54 55 56# -- General configuration ----------------------------------------------------- 57 58needs_sphinx='3.5' 59nitpicky = True # checks internal links. For external links, use "make linkcheck" 60master_doc = 'index' 61templates_path = ['_templates'] 62exclude_patterns = ['_build*', 'images', 'Thumbs.db', '.DS_Store'] 63highlight_language = 'c' 64numfig = True 65 66# -- Extensions ---------------------------------------------------------------- 67 68extensions = [ 69 'sphinx_copybutton', 70 'sphinx_panels', 71 'sphinxcontrib.bibtex', 72 'sphinxcontrib.katex', 73 'sphinxcontrib.rsvgconverter', 74 'myst_parser', 75 'html5_petsc', 76 'sphinx_remove_toctrees', 77] 78 79copybutton_prompt_text = '$ ' 80 81bibtex_bibfiles = ['petsc.bib'] 82 83myst_enable_extensions = ["dollarmath", "amsmath", "deflist"] 84 85remove_from_toctrees = ['docs/manualpages/*'] 86 87# -- Options for HTML output --------------------------------------------------- 88 89html_theme = 'pydata_sphinx_theme' 90 91html_theme_options = { 92 "icon_links": [ 93 { 94 "name": "GitLab", 95 "url": "https://gitlab.com/petsc/petsc", 96 "icon": "fab fa-gitlab", 97 }, 98 ], 99 "use_edit_page_button": True, 100 "footer_items": ["copyright", "sphinx-version", "last-updated"], 101} 102 103try: 104 git_ref = subprocess.check_output(["git", "rev-parse", "HEAD"]).rstrip() 105 git_ref_release = subprocess.check_output(["git", "rev-parse", "origin/release"]).rstrip() 106 edit_branch = "release" if git_ref == git_ref_release else "main" 107except subprocess.CalledProcessError: 108 print("WARNING: determining branch for page edit links failed") 109 edit_branch = "main" 110 111html_context = { 112 "github_url": "https://gitlab.com", 113 "github_user": "petsc", 114 "github_repo": "petsc", 115 "github_version": edit_branch, 116 "doc_path": "doc", 117} 118 119html_logo = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc-TAO', 'web', 'PETSc-TAO_RGB.svg') 120html_favicon = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc', 'petsc_favicon.png') 121html_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')' 122 123 124 125# -- Options for LaTeX output -------------------------------------------------- 126latex_engine = 'xelatex' 127 128# How to arrange the documents into LaTeX files, building only the manual. 129latex_documents = [ 130 ('docs/manual/index', 'manual.tex', 'PETSc/TAO Users Manual', author, 'manual', False) 131 ] 132 133latex_additional_files = [ 134 'images/docs/manual/anl_tech_report/ArgonneLogo.pdf', 135 'images/docs/manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf', 136 'images/docs/manual/anl_tech_report/ArgonneReportTemplatePage2.pdf', 137 'docs/manual/anl_tech_report/first.inc', 138 'docs/manual/anl_tech_report/last.inc', 139] 140 141latex_elements = { 142 'maketitle': r'\newcommand{\techreportversion}{%s}' % version + 143r''' 144\input{first.inc} 145''', 146 'printindex': r''' 147\printindex 148\input{last.inc} 149''', 150 'fontpkg': r''' 151\setsansfont{DejaVu Sans} 152\setmonofont{DejaVu Sans Mono} 153''', 154 'tableofcontents' : r'' 155} 156 157 158# -- Setup and event callbacks ------------------------------------------------- 159 160def setup(app): 161 app.connect('builder-inited', builder_init_handler) 162 app.connect('build-finished', build_finished_handler) 163 164 165def builder_init_handler(app): 166 if app.builder.name.endswith('html'): 167 _build_classic_docs(app, 'pre') 168 _copy_classic_docs(app, None, '.', 'pre') 169 _update_htmlmap_links(app) 170 171 172def build_finished_handler(app, exception): 173 if app.builder.name.endswith('html'): 174 _build_classic_docs(app, 'post') 175 _copy_classic_docs(app, exception, app.outdir, 'post') 176 _fix_links(app, exception) 177 if app.builder.name == 'dirhtml': 178 _add_man_page_redirects(app, exception) 179 if app.builder.name == 'html': 180 print("==========================================================================") 181 print(" open %s/index.html in your browser to view the documentation " % app.outdir) 182 print("==========================================================================") 183 184def _add_man_page_redirects(app, exception): 185 if exception is None: 186 print("============================================") 187 print(" Adding man pages redirects") 188 print("============================================") 189 add_man_page_redirects.add_man_page_redirects(app.outdir) 190 191def _build_classic_docs(app, stage): 192 build_classic_docs.main(stage) 193 194 195def _copy_classic_docs(app, exception, destination, stage): 196 if exception is None: 197 print("============================================") 198 print(" Copying classic docs (%s)" % stage) 199 print("============================================") 200 build_classic_docs.copy_classic_docs(destination, stage) 201 202 203def _fix_links(app, exception): 204 if exception is None: 205 print("============================================") 206 print(" Fixing relative links") 207 print("============================================") 208 make_links_relative.make_links_relative(app.outdir) 209 210 211def _update_htmlmap_links(app): 212 print("============================================") 213 print(" Updating htmlmap") 214 print("============================================") 215 update_htmlmap_links.update_htmlmap_links(app.builder) 216