1ee12ae39SPatrick Sanan# Configuration file for the Sphinx documentation builder. 2ee12ae39SPatrick Sanan# 396b7068eSPatrick Sanan# For information on options, see 4ee12ae39SPatrick Sanan# http://www.sphinx-doc.org/en/master/config 5ee12ae39SPatrick Sanan# 6862e4a30SBarry Smith# This file was generated by running "sphinx-quickstart" and then modified 796b7068eSPatrick Sanan 8ee12ae39SPatrick Sananimport os 9ee12ae39SPatrick Sananimport sys 10ee12ae39SPatrick Sananimport subprocess 11ee12ae39SPatrick Sananimport re 12ee12ae39SPatrick Sananimport datetime 13ee12ae39SPatrick Sanan 14ee12ae39SPatrick Sanansys.path.append(os.getcwd()) 15ee12ae39SPatrick Sanansys.path.append(os.path.abspath('./ext')) 16ee12ae39SPatrick Sanan 1795216c61SPatrick Sananimport add_man_page_redirects 1802f5a9aaSPatrick Sananimport build_classic_docs 19c9f6b0acSPatrick Sananimport fix_man_page_edit_links 2002f5a9aaSPatrick Sananimport make_links_relative 215becb6a3SPatrick Sananimport update_htmlmap_links 2202f5a9aaSPatrick Sanan 2302f5a9aaSPatrick Sanan 24e6bab0d2SPatrick Sananif not os.path.isdir("images"): 25e6bab0d2SPatrick Sanan print("-----------------------------------------------------------------------------") 26e6bab0d2SPatrick Sanan print("ERROR") 27e6bab0d2SPatrick Sanan print("images directory does not seem to exist.") 28e6bab0d2SPatrick Sanan print("To clone the required repository, try") 29e6bab0d2SPatrick Sanan print(" make images") 30e6bab0d2SPatrick Sanan print("-----------------------------------------------------------------------------") 31e6bab0d2SPatrick Sanan raise Exception("Aborting because images missing") 32e6bab0d2SPatrick Sanan 33e6bab0d2SPatrick Sanan 3496b7068eSPatrick Sanan# -- Project information ------------------------------------------------------- 35ee12ae39SPatrick Sanan 36ee12ae39SPatrick Sananproject = 'PETSc' 37ee12ae39SPatrick Sanancopyright = '1991-%d, UChicago Argonne, LLC and the PETSc Development Team' % datetime.date.today().year 38ee12ae39SPatrick Sananauthor = 'The PETSc Development Team' 39ee12ae39SPatrick Sanan 40404447afSPatrick Sananwith open(os.path.join('..', 'include', 'petscversion.h'),'r') as version_file: 41ee12ae39SPatrick Sanan buf = version_file.read() 42ee12ae39SPatrick Sanan petsc_release_flag = re.search(' PETSC_VERSION_RELEASE[ ]*([0-9]*)',buf).group(1) 43ee12ae39SPatrick Sanan major_version = re.search(' PETSC_VERSION_MAJOR[ ]*([0-9]*)',buf).group(1) 44ee12ae39SPatrick Sanan minor_version = re.search(' PETSC_VERSION_MINOR[ ]*([0-9]*)',buf).group(1) 45ee12ae39SPatrick Sanan subminor_version = re.search(' PETSC_VERSION_SUBMINOR[ ]*([0-9]*)',buf).group(1) 46ee12ae39SPatrick Sanan 47ffebb2dfSPatrick Sanan git_describe_version = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8') 48ee12ae39SPatrick Sanan if petsc_release_flag == '0': 49ffebb2dfSPatrick Sanan version = git_describe_version 50ffebb2dfSPatrick Sanan release = git_describe_version 51ee12ae39SPatrick Sanan else: 52ee12ae39SPatrick Sanan version = '.'.join([major_version, minor_version]) 53ee12ae39SPatrick Sanan release = '.'.join([major_version,minor_version,subminor_version]) 54ee12ae39SPatrick Sanan 55ee12ae39SPatrick Sanan 5696b7068eSPatrick Sanan# -- General configuration ----------------------------------------------------- 5796b7068eSPatrick Sanan 5866c9fbddSBarry Smith# The information on the next line must also be the same in requirements.txt 59d1f92df0SBarry Smithneeds_sphinx='5.3' 6096b7068eSPatrick Sanannitpicky = True # checks internal links. For external links, use "make linkcheck" 61ee12ae39SPatrick Sananmaster_doc = 'index' 62ee12ae39SPatrick Sanantemplates_path = ['_templates'] 6366c9fbddSBarry Smithexclude_patterns = ['_build*', 'images', 'Thumbs.db', '.DS_Store','community/meetings/pre-2023'] 6496b7068eSPatrick Sananhighlight_language = 'c' 6596b7068eSPatrick Sanannumfig = True 66ee12ae39SPatrick Sanan 6796b7068eSPatrick Sanan# -- Extensions ---------------------------------------------------------------- 68ee12ae39SPatrick Sanan 694b6f941bSPatrick Sananextensions = [ 704b6f941bSPatrick Sanan 'sphinx_copybutton', 714a3b3e5fSJed Brown 'sphinx_design', 724b6f941bSPatrick Sanan 'sphinxcontrib.bibtex', 734b6f941bSPatrick Sanan 'sphinxcontrib.katex', 744b6f941bSPatrick Sanan 'sphinxcontrib.rsvgconverter', 758f2bcf5fSPatrick Sanan 'myst_parser', 764b6f941bSPatrick Sanan 'html5_petsc', 774707091fSPatrick Sanan 'sphinx_remove_toctrees', 784b6f941bSPatrick Sanan] 794b6f941bSPatrick Sanan 80f3c6b5cdSPatrick Sanancopybutton_prompt_text = '$ ' 814b6f941bSPatrick Sanan 8254129d2fSPatrick Sananbibtex_bibfiles = ['petsc.bib'] 834b6f941bSPatrick Sanan 848f2bcf5fSPatrick Sananmyst_enable_extensions = ["dollarmath", "amsmath", "deflist"] 858f2bcf5fSPatrick Sanan 8673fdd05bSBarry Smithremove_from_toctrees = ['manualpages/*/*','changes/2*','changes/3*'] 874707091fSPatrick Sanan 8896b7068eSPatrick Sanan# -- Options for HTML output --------------------------------------------------- 89ee12ae39SPatrick Sanan 90ee12ae39SPatrick Sananhtml_theme = 'pydata_sphinx_theme' 91ee12ae39SPatrick Sanan 9280dc5c2eSToby Isaachtml_logo_light = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc-TAO', 'web', 'PETSc-TAO_RGB.svg') 9380dc5c2eSToby Isaachtml_logo_dark = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc-TAO', 'web', 'PETSc-TAO_RGB_white.svg') 9480dc5c2eSToby Isaac 9580dc5c2eSToby Isaachtml_static_path = [html_logo_light, html_logo_dark] 9680dc5c2eSToby Isaac 97ee12ae39SPatrick Sananhtml_theme_options = { 98ee12ae39SPatrick Sanan "icon_links": [ 99ee12ae39SPatrick Sanan { 100ee12ae39SPatrick Sanan "name": "GitLab", 101ee12ae39SPatrick Sanan "url": "https://gitlab.com/petsc/petsc", 102ee12ae39SPatrick Sanan "icon": "fab fa-gitlab", 103ee12ae39SPatrick Sanan }, 104ee12ae39SPatrick Sanan ], 105ee12ae39SPatrick Sanan "use_edit_page_button": True, 106ffebb2dfSPatrick Sanan "footer_items": ["copyright", "sphinx-version", "last-updated"], 107d1f92df0SBarry Smith# "secondary_sidebar_items" : ["edit-this-page"], 108*8a663d8cSBarry Smith "header_links_before_dropdown": 9, 10980dc5c2eSToby Isaac "logo": { 11080dc5c2eSToby Isaac "image_light": os.path.basename(html_logo_light), 11180dc5c2eSToby Isaac "image_dark": os.path.basename(html_logo_dark) 11280dc5c2eSToby Isaac } 113ee12ae39SPatrick Sanan} 114ee12ae39SPatrick Sanan 115d3edb92dSPatrick Sanantry: 116d3edb92dSPatrick Sanan git_ref = subprocess.check_output(["git", "rev-parse", "HEAD"]).rstrip() 117d3edb92dSPatrick Sanan git_ref_release = subprocess.check_output(["git", "rev-parse", "origin/release"]).rstrip() 118d3edb92dSPatrick Sanan edit_branch = "release" if git_ref == git_ref_release else "main" 119d3edb92dSPatrick Sananexcept subprocess.CalledProcessError: 120d3edb92dSPatrick Sanan print("WARNING: determining branch for page edit links failed") 121d3edb92dSPatrick Sanan edit_branch = "main" 122d3edb92dSPatrick Sanan 123ee12ae39SPatrick Sananhtml_context = { 124ee12ae39SPatrick Sanan "github_url": "https://gitlab.com", 125ee12ae39SPatrick Sanan "github_user": "petsc", 126ee12ae39SPatrick Sanan "github_repo": "petsc", 127d3edb92dSPatrick Sanan "github_version": edit_branch, 128ee12ae39SPatrick Sanan "doc_path": "doc", 129ee12ae39SPatrick Sanan} 130ee12ae39SPatrick Sanan 13180dc5c2eSToby Isaachtml_logo = html_logo_light 132fc1137abSPatrick Sananhtml_favicon = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc', 'petsc_favicon.png') 13396b7068eSPatrick Sananhtml_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')' 134ee12ae39SPatrick Sanan 135ee12ae39SPatrick Sanan 13696b7068eSPatrick Sanan# -- Options for LaTeX output -------------------------------------------------- 137ee12ae39SPatrick Sananlatex_engine = 'xelatex' 138ee12ae39SPatrick Sanan 13996b7068eSPatrick Sanan# How to arrange the documents into LaTeX files, building only the manual. 140ee12ae39SPatrick Sananlatex_documents = [ 14173fdd05bSBarry Smith ('manual/index', 'manual.tex', 'PETSc/TAO Users Manual', author, 'manual', False) 142ee12ae39SPatrick Sanan ] 143ee12ae39SPatrick Sanan 144ee12ae39SPatrick Sananlatex_additional_files = [ 14573fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneLogo.pdf', 14673fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf', 14773fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneReportTemplatePage2.pdf', 14873fdd05bSBarry Smith 'manual/anl_tech_report/first.inc', 14973fdd05bSBarry Smith 'manual/anl_tech_report/last.inc', 150ee12ae39SPatrick Sanan] 151ee12ae39SPatrick Sanan 152ee12ae39SPatrick Sananlatex_elements = { 153ee12ae39SPatrick Sanan 'maketitle': r'\newcommand{\techreportversion}{%s}' % version + 154ee12ae39SPatrick Sananr''' 155ee12ae39SPatrick Sanan\input{first.inc} 156ee12ae39SPatrick Sanan''', 157ee12ae39SPatrick Sanan 'printindex': r''' 158ee12ae39SPatrick Sanan\printindex 159ee12ae39SPatrick Sanan\input{last.inc} 160ee12ae39SPatrick Sanan''', 161ee12ae39SPatrick Sanan 'fontpkg': r''' 162ee12ae39SPatrick Sanan\setsansfont{DejaVu Sans} 163ee12ae39SPatrick Sanan\setmonofont{DejaVu Sans Mono} 1641b671caaSPatrick Sanan''', 1651b671caaSPatrick Sanan 'tableofcontents' : r'' 166ee12ae39SPatrick Sanan} 167ee12ae39SPatrick Sanan 168ee12ae39SPatrick Sanan 16996b7068eSPatrick Sanan# -- Setup and event callbacks ------------------------------------------------- 170ee12ae39SPatrick Sanan 17175662446SPatrick Sanandef setup(app): 17275662446SPatrick Sanan app.connect('builder-inited', builder_init_handler) 17375662446SPatrick Sanan app.connect('build-finished', build_finished_handler) 17402f5a9aaSPatrick Sanan 17502f5a9aaSPatrick Sanan 17602f5a9aaSPatrick Sanandef builder_init_handler(app): 17775662446SPatrick Sanan if app.builder.name.endswith('html'): 178b8a29d3aSPatrick Sanan _build_classic_docs(app, 'pre') 179589e537fSPatrick Sanan _copy_classic_docs(app, None, '.', 'pre') 1805becb6a3SPatrick Sanan _update_htmlmap_links(app) 18102f5a9aaSPatrick Sanan 18202f5a9aaSPatrick Sanan 18302f5a9aaSPatrick Sanandef build_finished_handler(app, exception): 18475662446SPatrick Sanan if app.builder.name.endswith('html'): 185b8a29d3aSPatrick Sanan _build_classic_docs(app, 'post') 186589e537fSPatrick Sanan _copy_classic_docs(app, exception, app.outdir, 'post') 1871540e0edSPatrick Sanan _fix_links(app, exception) 188c9f6b0acSPatrick Sanan _fix_man_page_edit_links(app, exception) 18995216c61SPatrick Sanan if app.builder.name == 'dirhtml': 19095216c61SPatrick Sanan _add_man_page_redirects(app, exception) 19130f5c8b0SPatrick Sanan if app.builder.name == 'html': 19228cbf9b2SBarry Smith print("==========================================================================") 19328cbf9b2SBarry Smith print(" open %s/index.html in your browser to view the documentation " % app.outdir) 19428cbf9b2SBarry Smith print("==========================================================================") 19502f5a9aaSPatrick Sanan 19695216c61SPatrick Sanandef _add_man_page_redirects(app, exception): 19795216c61SPatrick Sanan if exception is None: 19895216c61SPatrick Sanan print("============================================") 19995216c61SPatrick Sanan print(" Adding man pages redirects") 20095216c61SPatrick Sanan print("============================================") 20195216c61SPatrick Sanan add_man_page_redirects.add_man_page_redirects(app.outdir) 2027553d27dSPatrick Sanan 20375662446SPatrick Sanandef _build_classic_docs(app, stage): 204862e4a30SBarry Smith '''Builds the .md versions of the manual pages and the .html version of the source code''' 20575662446SPatrick Sanan build_classic_docs.main(stage) 20675662446SPatrick Sanan 20775662446SPatrick Sanan 20875662446SPatrick Sanandef _copy_classic_docs(app, exception, destination, stage): 20975662446SPatrick Sanan if exception is None: 2105becb6a3SPatrick Sanan print("============================================") 21175662446SPatrick Sanan print(" Copying classic docs (%s)" % stage) 21275662446SPatrick Sanan print("============================================") 21375662446SPatrick Sanan build_classic_docs.copy_classic_docs(destination, stage) 21475662446SPatrick Sanan 215c9f6b0acSPatrick Sanandef _fix_man_page_edit_links(app, exception): 216c9f6b0acSPatrick Sanan if exception is None: 217c9f6b0acSPatrick Sanan print("============================================") 218c9f6b0acSPatrick Sanan print(" Fixing man page edit links") 219c9f6b0acSPatrick Sanan print("============================================") 220c9f6b0acSPatrick Sanan fix_man_page_edit_links.fix_man_page_edit_links(app.outdir) 221c9f6b0acSPatrick Sanan 222862e4a30SBarry Smith# 223862e4a30SBarry Smith# The following two scripts are needed because the Sphinx html and dirhtml builds save the output html 224862e4a30SBarry Smith# files at different levels of the directory hierarchy. file.rst -> file.html with html but 225862e4a30SBarry Smith# file.rst -> file/index.html with dirhtml and we want both to work correctly using relative links. 226862e4a30SBarry Smith 227862e4a30SBarry Smithdef _fix_links(app, exception): 228862e4a30SBarry Smith """We need to manage our own relative paths in the User's Manual for the source code files which 229862e4a30SBarry Smith are auto-generated by c2html outside of Sphinx so Sphinx cannot directly handle those links for use. 230862e4a30SBarry Smith We use the string PETSC_DOC_OUT_ROOT_PLACEHOLDER in URLs in the Sphinx .rst files as a stand in 231862e4a30SBarry Smith for the root directory that needs to be constructed based on if the Sphinx build is html or dirhtml 232862e4a30SBarry Smith """ 233862e4a30SBarry Smith if exception is None: 234862e4a30SBarry Smith print("============================================") 235862e4a30SBarry Smith print(" Fixing relative links") 236862e4a30SBarry Smith print("============================================") 237862e4a30SBarry Smith make_links_relative.make_links_relative(app.outdir) 238862e4a30SBarry Smith 239c9f6b0acSPatrick Sanan 24075662446SPatrick Sanandef _update_htmlmap_links(app): 241862e4a30SBarry Smith """htmlmap maps from manualpage names to relative locations in the generated documentation directory 242862e4a30SBarry Smith hierarchy. The format of the directory location needs to be different for the Sphinx html and dirhtml 243862e4a30SBarry Smith builds 244862e4a30SBarry Smith """ 24575662446SPatrick Sanan print("============================================") 24675662446SPatrick Sanan print(" Updating htmlmap") 2475becb6a3SPatrick Sanan print("============================================") 2485becb6a3SPatrick Sanan update_htmlmap_links.update_htmlmap_links(app.builder) 249