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_version_header 19import genteamtable 20import build_classic_docs 21import make_links_relative 22 23 24# -- Project information ------------------------------------------------------- 25 26project = 'PETSc' 27copyright = '1991-%d, UChicago Argonne, LLC and the PETSc Development Team' % datetime.date.today().year 28author = 'The PETSc Development Team' 29 30with open(os.path.join('..', 'include', 'petscversion.h'),'r') as version_file: 31 buf = version_file.read() 32 petsc_release_flag = re.search(' PETSC_VERSION_RELEASE[ ]*([0-9]*)',buf).group(1) 33 major_version = re.search(' PETSC_VERSION_MAJOR[ ]*([0-9]*)',buf).group(1) 34 minor_version = re.search(' PETSC_VERSION_MINOR[ ]*([0-9]*)',buf).group(1) 35 subminor_version = re.search(' PETSC_VERSION_SUBMINOR[ ]*([0-9]*)',buf).group(1) 36 37 git_describe_version = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8') 38 if petsc_release_flag == '0': 39 version = git_describe_version 40 release = git_describe_version 41 else: 42 version = '.'.join([major_version, minor_version]) 43 release = '.'.join([major_version,minor_version,subminor_version]) 44 45 46# -- General configuration ----------------------------------------------------- 47 48needs_sphinx='3.5' 49nitpicky = True # checks internal links. For external links, use "make linkcheck" 50master_doc = 'index' 51templates_path = ['_templates'] 52exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 53highlight_language = 'c' 54numfig = True 55 56# -- Extensions ---------------------------------------------------------------- 57 58extensions = [ 59 'sphinx_copybutton', 60 'sphinxcontrib.bibtex', 61 'sphinxcontrib.katex', 62 'sphinxcontrib.rsvgconverter', 63 'html5_petsc', 64] 65 66copybutton_prompt_text = r"[>]{1,3}" 67copybutton_prompt_is_regexp = True 68 69bibtex_bibfiles = [ 70 os.path.join('..', 'src', 'docs', 'tex', 'petsc.bib'), 71 os.path.join('..', 'src', 'docs', 'tex', 'petscapp.bib'), 72 os.path.join('..', 'src', 'docs', 'tao_tex', 'tao.bib'), 73 os.path.join('..', 'src', 'docs', 'tao_tex', 'manual', 'mathprog.bib'), 74 ] 75 76 77# -- Options for HTML output --------------------------------------------------- 78 79html_theme = 'pydata_sphinx_theme' 80 81html_theme_options = { 82 "icon_links": [ 83 { 84 "name": "GitLab", 85 "url": "https://gitlab.com/petsc/petsc", 86 "icon": "fab fa-gitlab", 87 }, 88 ], 89 "use_edit_page_button": True, 90 "footer_items": ["copyright", "sphinx-version", "last-updated"], 91} 92 93html_context = { 94 "github_url": "https://gitlab.com", 95 "github_user": "petsc", 96 "github_repo": "petsc", 97 "github_version": "release", 98 "doc_path": "doc", 99} 100 101html_static_path = ['_static'] 102html_logo = os.path.join('..', 'src', 'docs', 'website','images','PETSc-TAO_RGB.svg') 103html_favicon = os.path.join('..', 'src', 'docs', 'website','images','PETSc_RGB-logo.png') 104html_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')' 105 106 107 108# -- Options for LaTeX output -------------------------------------------------- 109latex_engine = 'xelatex' 110 111# How to arrange the documents into LaTeX files, building only the manual. 112latex_documents = [ 113 ('docs/manual/index', 'manual.tex', 'PETSc/TAO Users Manual', author, 'manual', False) 114 ] 115 116latex_additional_files = [ 117 'docs/manual/anl_tech_report/ArgonneLogo.pdf', 118 'docs/manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf', 119 'docs/manual/anl_tech_report/ArgonneReportTemplatePage2.pdf', 120 'docs/manual/anl_tech_report/first.inc', 121 'docs/manual/anl_tech_report/last.inc', 122] 123 124latex_elements = { 125 'maketitle': r'\newcommand{\techreportversion}{%s}' % version + 126r''' 127\input{first.inc} 128''', 129 'printindex': r''' 130\printindex 131\input{last.inc} 132''', 133 'fontpkg': r''' 134\setsansfont{DejaVu Sans} 135\setmonofont{DejaVu Sans Mono} 136''', 137 'tableofcontents' : r'' 138} 139 140 141# -- Setup and event callbacks ------------------------------------------------- 142 143# Trigger a build of the "classic" docs 144def _build_classic_docs(app): 145 build_classic_docs.main() 146 147 148def _generate_team_table(app): 149 print("============================================") 150 print(" Generating team table from conf.py ") 151 print("============================================") 152 genDirName = "generated" 153 cwdPath = os.path.dirname(os.path.realpath(__file__)) 154 genDirPath = os.path.join(cwdPath, genDirName) 155 genteamtable.main(genDirPath, builderName = app.builder.name) 156 157 158def builder_init_handler(app): 159 _generate_team_table(app) 160 _build_classic_docs(app) 161 162 163def _add_version_header(app, exception): 164 if exception is None and app.builder.name.endswith('html'): 165 print("============================================") 166 print(" Adding version to classic man pages, from conf.py") 167 print("============================================") 168 add_version_header.add_version_header(os.path.join(app.outdir, "docs", "manualpages"), release) 169 170 171def _copy_classic_docs(app, exception): 172 if exception is None and app.builder.name.endswith('html'): 173 print("============================================") 174 print(" Copying classic docs from conf.py ") 175 print("============================================") 176 build_classic_docs.copy_classic_docs(app.outdir) 177 178 179def _fix_links(app, exception): 180 if exception is None and app.builder.name.endswith('html'): 181 print("============================================") 182 print(" Fixing relative links from conf.py ") 183 print("============================================") 184 make_links_relative.make_links_relative(app.outdir) 185 186 187def build_finished_handler(app, exception): 188 _fix_links(app, exception) 189 _copy_classic_docs(app, exception) 190 _add_version_header(app, exception) 191 192 193def setup(app): 194 app.connect('builder-inited', builder_init_handler) 195 app.connect('build-finished', build_finished_handler) 196 app.add_css_file('css/pop-up.css') 197 app.add_css_file('css/petsc-team-container.css') 198