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