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# This file was generated by running "sphinx-quickstart" and then modified 7 8import os 9import sys 10import subprocess 11import re 12import datetime 13 14sys.path.append(os.getcwd()) 15sys.path.append(os.path.abspath('./ext')) 16 17import add_man_page_redirects 18import build_classic_docs 19import fix_man_page_edit_links 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/*/*','docs/changes/2*','docs/changes/3*'] 86 87# -- Options for HTML output --------------------------------------------------- 88 89html_theme = 'pydata_sphinx_theme' 90 91html_logo_light = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc-TAO', 'web', 'PETSc-TAO_RGB.svg') 92html_logo_dark = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc-TAO', 'web', 'PETSc-TAO_RGB_white.svg') 93 94html_static_path = [html_logo_light, html_logo_dark] 95 96html_theme_options = { 97 "icon_links": [ 98 { 99 "name": "GitLab", 100 "url": "https://gitlab.com/petsc/petsc", 101 "icon": "fab fa-gitlab", 102 }, 103 ], 104 "use_edit_page_button": True, 105 "footer_items": ["copyright", "sphinx-version", "last-updated"], 106 "page_sidebar_items" : ["edit-this-page"], 107 "logo": { 108 "image_light": os.path.basename(html_logo_light), 109 "image_dark": os.path.basename(html_logo_dark) 110 } 111} 112 113try: 114 git_ref = subprocess.check_output(["git", "rev-parse", "HEAD"]).rstrip() 115 git_ref_release = subprocess.check_output(["git", "rev-parse", "origin/release"]).rstrip() 116 edit_branch = "release" if git_ref == git_ref_release else "main" 117except subprocess.CalledProcessError: 118 print("WARNING: determining branch for page edit links failed") 119 edit_branch = "main" 120 121html_context = { 122 "github_url": "https://gitlab.com", 123 "github_user": "petsc", 124 "github_repo": "petsc", 125 "github_version": edit_branch, 126 "doc_path": "doc", 127} 128 129html_logo = html_logo_light 130html_favicon = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc', 'petsc_favicon.png') 131html_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')' 132 133 134# -- Options for LaTeX output -------------------------------------------------- 135latex_engine = 'xelatex' 136 137# How to arrange the documents into LaTeX files, building only the manual. 138latex_documents = [ 139 ('docs/manual/index', 'manual.tex', 'PETSc/TAO Users Manual', author, 'manual', False) 140 ] 141 142latex_additional_files = [ 143 'images/docs/manual/anl_tech_report/ArgonneLogo.pdf', 144 'images/docs/manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf', 145 'images/docs/manual/anl_tech_report/ArgonneReportTemplatePage2.pdf', 146 'docs/manual/anl_tech_report/first.inc', 147 'docs/manual/anl_tech_report/last.inc', 148] 149 150latex_elements = { 151 'maketitle': r'\newcommand{\techreportversion}{%s}' % version + 152r''' 153\input{first.inc} 154''', 155 'printindex': r''' 156\printindex 157\input{last.inc} 158''', 159 'fontpkg': r''' 160\setsansfont{DejaVu Sans} 161\setmonofont{DejaVu Sans Mono} 162''', 163 'tableofcontents' : r'' 164} 165 166 167# -- Setup and event callbacks ------------------------------------------------- 168 169def setup(app): 170 app.connect('builder-inited', builder_init_handler) 171 app.connect('build-finished', build_finished_handler) 172 173 174def builder_init_handler(app): 175 if app.builder.name.endswith('html'): 176 _build_classic_docs(app, 'pre') 177 _copy_classic_docs(app, None, '.', 'pre') 178 _update_htmlmap_links(app) 179 180 181def build_finished_handler(app, exception): 182 if app.builder.name.endswith('html'): 183 _build_classic_docs(app, 'post') 184 _copy_classic_docs(app, exception, app.outdir, 'post') 185 _fix_links(app, exception) 186 _fix_man_page_edit_links(app, exception) 187 if app.builder.name == 'dirhtml': 188 _add_man_page_redirects(app, exception) 189 if app.builder.name == 'html': 190 print("==========================================================================") 191 print(" open %s/index.html in your browser to view the documentation " % app.outdir) 192 print("==========================================================================") 193 194def _add_man_page_redirects(app, exception): 195 if exception is None: 196 print("============================================") 197 print(" Adding man pages redirects") 198 print("============================================") 199 add_man_page_redirects.add_man_page_redirects(app.outdir) 200 201def _build_classic_docs(app, stage): 202 '''Builds the .md versions of the manual pages and the .html version of the source code''' 203 build_classic_docs.main(stage) 204 205 206def _copy_classic_docs(app, exception, destination, stage): 207 if exception is None: 208 print("============================================") 209 print(" Copying classic docs (%s)" % stage) 210 print("============================================") 211 build_classic_docs.copy_classic_docs(destination, stage) 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# 221# The following two scripts are needed because the Sphinx html and dirhtml builds save the output html 222# files at different levels of the directory hierarchy. file.rst -> file.html with html but 223# file.rst -> file/index.html with dirhtml and we want both to work correctly using relative links. 224 225def _fix_links(app, exception): 226 """We need to manage our own relative paths in the User's Manual for the source code files which 227 are auto-generated by c2html outside of Sphinx so Sphinx cannot directly handle those links for use. 228 We use the string PETSC_DOC_OUT_ROOT_PLACEHOLDER in URLs in the Sphinx .rst files as a stand in 229 for the root directory that needs to be constructed based on if the Sphinx build is html or dirhtml 230 """ 231 if exception is None: 232 print("============================================") 233 print(" Fixing relative links") 234 print("============================================") 235 make_links_relative.make_links_relative(app.outdir) 236 237 238def _update_htmlmap_links(app): 239 """htmlmap maps from manualpage names to relative locations in the generated documentation directory 240 hierarchy. The format of the directory location needs to be different for the Sphinx html and dirhtml 241 builds 242 """ 243 print("============================================") 244 print(" Updating htmlmap") 245 print("============================================") 246 update_htmlmap_links.update_htmlmap_links(app.builder) 247