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