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 86*8a0d1e8bSBarry Smithremove_from_toctrees = ['manualpages/*/[A-Z]*','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 957c561f09SBarry Smithhtml_static_path = ['_static', html_logo_light, html_logo_dark] 967c561f09SBarry Smith 977c561f09SBarry Smith# use much smaller font for h1, h2 etc. They are absurdly large in the standard style 987c561f09SBarry Smith# https://pydata-sphinx-theme.readthedocs.io/en/v0.12.0/user_guide/styling.html 997c561f09SBarry Smithhtml_css_files = [ 1007c561f09SBarry Smith 'css/custom.css', 1017c561f09SBarry Smith] 10280dc5c2eSToby Isaac 103ee12ae39SPatrick Sananhtml_theme_options = { 104ee12ae39SPatrick Sanan "icon_links": [ 105ee12ae39SPatrick Sanan { 106ee12ae39SPatrick Sanan "name": "GitLab", 107ee12ae39SPatrick Sanan "url": "https://gitlab.com/petsc/petsc", 108ee12ae39SPatrick Sanan "icon": "fab fa-gitlab", 109ee12ae39SPatrick Sanan }, 110ee12ae39SPatrick Sanan ], 111ee12ae39SPatrick Sanan "use_edit_page_button": True, 112ffebb2dfSPatrick Sanan "footer_items": ["copyright", "sphinx-version", "last-updated"], 113d1f92df0SBarry Smith# "secondary_sidebar_items" : ["edit-this-page"], 1148a663d8cSBarry Smith "header_links_before_dropdown": 9, 11580dc5c2eSToby Isaac "logo": { 11680dc5c2eSToby Isaac "image_light": os.path.basename(html_logo_light), 11780dc5c2eSToby Isaac "image_dark": os.path.basename(html_logo_dark) 11880dc5c2eSToby Isaac } 119ee12ae39SPatrick Sanan} 120ee12ae39SPatrick Sanan 121d3edb92dSPatrick Sanantry: 122d3edb92dSPatrick Sanan git_ref = subprocess.check_output(["git", "rev-parse", "HEAD"]).rstrip() 123d3edb92dSPatrick Sanan git_ref_release = subprocess.check_output(["git", "rev-parse", "origin/release"]).rstrip() 124d3edb92dSPatrick Sanan edit_branch = "release" if git_ref == git_ref_release else "main" 125d3edb92dSPatrick Sananexcept subprocess.CalledProcessError: 126d3edb92dSPatrick Sanan print("WARNING: determining branch for page edit links failed") 127d3edb92dSPatrick Sanan edit_branch = "main" 128d3edb92dSPatrick Sanan 129ee12ae39SPatrick Sananhtml_context = { 130ee12ae39SPatrick Sanan "github_url": "https://gitlab.com", 131ee12ae39SPatrick Sanan "github_user": "petsc", 132ee12ae39SPatrick Sanan "github_repo": "petsc", 133d3edb92dSPatrick Sanan "github_version": edit_branch, 134ee12ae39SPatrick Sanan "doc_path": "doc", 135ee12ae39SPatrick Sanan} 136ee12ae39SPatrick Sanan 13780dc5c2eSToby Isaachtml_logo = html_logo_light 138fc1137abSPatrick Sananhtml_favicon = os.path.join('images', 'logos', 'PETSc_TAO_logos', 'PETSc', 'petsc_favicon.png') 13996b7068eSPatrick Sananhtml_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')' 140ee12ae39SPatrick Sanan 141ee12ae39SPatrick Sanan 14296b7068eSPatrick Sanan# -- Options for LaTeX output -------------------------------------------------- 143ee12ae39SPatrick Sananlatex_engine = 'xelatex' 144ee12ae39SPatrick Sanan 14596b7068eSPatrick Sanan# How to arrange the documents into LaTeX files, building only the manual. 146ee12ae39SPatrick Sananlatex_documents = [ 14773fdd05bSBarry Smith ('manual/index', 'manual.tex', 'PETSc/TAO Users Manual', author, 'manual', False) 148ee12ae39SPatrick Sanan ] 149ee12ae39SPatrick Sanan 150ee12ae39SPatrick Sananlatex_additional_files = [ 15173fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneLogo.pdf', 15273fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf', 15373fdd05bSBarry Smith 'images/manual/anl_tech_report/ArgonneReportTemplatePage2.pdf', 15473fdd05bSBarry Smith 'manual/anl_tech_report/first.inc', 15573fdd05bSBarry Smith 'manual/anl_tech_report/last.inc', 156ee12ae39SPatrick Sanan] 157ee12ae39SPatrick Sanan 158ee12ae39SPatrick Sananlatex_elements = { 159ee12ae39SPatrick Sanan 'maketitle': r'\newcommand{\techreportversion}{%s}' % version + 160ee12ae39SPatrick Sananr''' 161ee12ae39SPatrick Sanan\input{first.inc} 162ee12ae39SPatrick Sanan''', 163ee12ae39SPatrick Sanan 'printindex': r''' 164ee12ae39SPatrick Sanan\printindex 165ee12ae39SPatrick Sanan\input{last.inc} 166ee12ae39SPatrick Sanan''', 167ee12ae39SPatrick Sanan 'fontpkg': r''' 168ee12ae39SPatrick Sanan\setsansfont{DejaVu Sans} 169ee12ae39SPatrick Sanan\setmonofont{DejaVu Sans Mono} 1701b671caaSPatrick Sanan''', 1711b671caaSPatrick Sanan 'tableofcontents' : r'' 172ee12ae39SPatrick Sanan} 173ee12ae39SPatrick Sanan 174ee12ae39SPatrick Sanan 17596b7068eSPatrick Sanan# -- Setup and event callbacks ------------------------------------------------- 176ee12ae39SPatrick Sanan 17775662446SPatrick Sanandef setup(app): 17875662446SPatrick Sanan app.connect('builder-inited', builder_init_handler) 17975662446SPatrick Sanan app.connect('build-finished', build_finished_handler) 18002f5a9aaSPatrick Sanan 18102f5a9aaSPatrick Sanan 18202f5a9aaSPatrick Sanandef builder_init_handler(app): 18375662446SPatrick Sanan if app.builder.name.endswith('html'): 184b8a29d3aSPatrick Sanan _build_classic_docs(app, 'pre') 185589e537fSPatrick Sanan _copy_classic_docs(app, None, '.', 'pre') 1865becb6a3SPatrick Sanan _update_htmlmap_links(app) 18702f5a9aaSPatrick Sanan 18802f5a9aaSPatrick Sanan 18902f5a9aaSPatrick Sanandef build_finished_handler(app, exception): 19075662446SPatrick Sanan if app.builder.name.endswith('html'): 191b8a29d3aSPatrick Sanan _build_classic_docs(app, 'post') 192589e537fSPatrick Sanan _copy_classic_docs(app, exception, app.outdir, 'post') 1931540e0edSPatrick Sanan _fix_links(app, exception) 194c9f6b0acSPatrick Sanan _fix_man_page_edit_links(app, exception) 19595216c61SPatrick Sanan if app.builder.name == 'dirhtml': 19695216c61SPatrick Sanan _add_man_page_redirects(app, exception) 19730f5c8b0SPatrick Sanan if app.builder.name == 'html': 19828cbf9b2SBarry Smith print("==========================================================================") 19928cbf9b2SBarry Smith print(" open %s/index.html in your browser to view the documentation " % app.outdir) 20028cbf9b2SBarry Smith print("==========================================================================") 20102f5a9aaSPatrick Sanan 20295216c61SPatrick Sanandef _add_man_page_redirects(app, exception): 20395216c61SPatrick Sanan if exception is None: 20495216c61SPatrick Sanan print("============================================") 20595216c61SPatrick Sanan print(" Adding man pages redirects") 20695216c61SPatrick Sanan print("============================================") 20795216c61SPatrick Sanan add_man_page_redirects.add_man_page_redirects(app.outdir) 2087553d27dSPatrick Sanan 20975662446SPatrick Sanandef _build_classic_docs(app, stage): 210862e4a30SBarry Smith '''Builds the .md versions of the manual pages and the .html version of the source code''' 21175662446SPatrick Sanan build_classic_docs.main(stage) 21275662446SPatrick Sanan 21375662446SPatrick Sanan 21475662446SPatrick Sanandef _copy_classic_docs(app, exception, destination, stage): 21575662446SPatrick Sanan if exception is None: 2165becb6a3SPatrick Sanan print("============================================") 21775662446SPatrick Sanan print(" Copying classic docs (%s)" % stage) 21875662446SPatrick Sanan print("============================================") 21975662446SPatrick Sanan build_classic_docs.copy_classic_docs(destination, stage) 22075662446SPatrick Sanan 221c9f6b0acSPatrick Sanandef _fix_man_page_edit_links(app, exception): 222c9f6b0acSPatrick Sanan if exception is None: 223c9f6b0acSPatrick Sanan print("============================================") 224c9f6b0acSPatrick Sanan print(" Fixing man page edit links") 225c9f6b0acSPatrick Sanan print("============================================") 226c9f6b0acSPatrick Sanan fix_man_page_edit_links.fix_man_page_edit_links(app.outdir) 227c9f6b0acSPatrick Sanan 228862e4a30SBarry Smith# 229862e4a30SBarry Smith# The following two scripts are needed because the Sphinx html and dirhtml builds save the output html 230862e4a30SBarry Smith# files at different levels of the directory hierarchy. file.rst -> file.html with html but 231862e4a30SBarry Smith# file.rst -> file/index.html with dirhtml and we want both to work correctly using relative links. 232862e4a30SBarry Smith 233862e4a30SBarry Smithdef _fix_links(app, exception): 234862e4a30SBarry Smith """We need to manage our own relative paths in the User's Manual for the source code files which 235862e4a30SBarry Smith are auto-generated by c2html outside of Sphinx so Sphinx cannot directly handle those links for use. 236862e4a30SBarry Smith We use the string PETSC_DOC_OUT_ROOT_PLACEHOLDER in URLs in the Sphinx .rst files as a stand in 237862e4a30SBarry Smith for the root directory that needs to be constructed based on if the Sphinx build is html or dirhtml 238862e4a30SBarry Smith """ 239862e4a30SBarry Smith if exception is None: 240862e4a30SBarry Smith print("============================================") 241862e4a30SBarry Smith print(" Fixing relative links") 242862e4a30SBarry Smith print("============================================") 243862e4a30SBarry Smith make_links_relative.make_links_relative(app.outdir) 244862e4a30SBarry Smith 245c9f6b0acSPatrick Sanan 24675662446SPatrick Sanandef _update_htmlmap_links(app): 247862e4a30SBarry Smith """htmlmap maps from manualpage names to relative locations in the generated documentation directory 248862e4a30SBarry Smith hierarchy. The format of the directory location needs to be different for the Sphinx html and dirhtml 249862e4a30SBarry Smith builds 250862e4a30SBarry Smith """ 25175662446SPatrick Sanan print("============================================") 25275662446SPatrick Sanan print(" Updating htmlmap") 2535becb6a3SPatrick Sanan print("============================================") 2545becb6a3SPatrick Sanan update_htmlmap_links.update_htmlmap_links(app.builder) 255