xref: /petsc/doc/conf.py (revision 87a1cfaee0b956dcbad93d36e585ffb4e074ab51)
1# Configuration file for the Sphinx documentation builder.
2#
3# Much of this file was generated automatically with sphinx-quickstart
4#
5# This file only contains a selection of the most common options. For a full
6# list see the documentation:
7# http://www.sphinx-doc.org/en/master/config
8
9# -- Path setup --------------------------------------------------------------
10
11# If extensions (or modules to document with autodoc) are in another directory,
12# add these directories to sys.path here. If the directory is relative to the
13# documentation root, use os.path.abspath to make it absolute, like shown here.
14#
15import os
16import sys
17import subprocess
18import re
19import datetime
20
21sys.path.append(os.getcwd())
22sys.path.append(os.path.abspath('./ext'))
23
24# -- Sphinx Version and Config -----------------------------------------------
25# Sphinx will error and refuse to build if not equal to version
26needs_sphinx='3.5'
27
28# Sphinx-build fails for any broken __internal__ links. For external use make linkcheck.
29nitpicky = True
30
31# -- Project information -----------------------------------------------------
32
33project = 'PETSc'
34copyright = '1991-%d, UChicago Argonne, LLC and the PETSc Development Team' % datetime.date.today().year
35author = 'The PETSc Development Team'
36
37# Allow todo's to be emitted, turn off for build!
38todo_include_todos=True
39todo_emit_warnings=True
40
41# Little copy-and-paste button by code blocks, from sphinx_copybutton package
42# https://sphinx-copybutton.readthedocs.io/en/latest/
43copybutton_prompt_text = r"[>]{1,3}"
44copybutton_prompt_is_regexp = True
45
46with open(os.path.join('..', 'include', 'petscversion.h'),'r') as version_file:
47    buf = version_file.read()
48    petsc_release_flag = re.search(' PETSC_VERSION_RELEASE[ ]*([0-9]*)',buf).group(1)
49    major_version      = re.search(' PETSC_VERSION_MAJOR[ ]*([0-9]*)',buf).group(1)
50    minor_version      = re.search(' PETSC_VERSION_MINOR[ ]*([0-9]*)',buf).group(1)
51    subminor_version   = re.search(' PETSC_VERSION_SUBMINOR[ ]*([0-9]*)',buf).group(1)
52    patch_version      = re.search(' PETSC_VERSION_PATCH[ ]*([0-9]*)',buf).group(1)
53
54
55    git_describe_version = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8')
56    if petsc_release_flag == '0':
57        version = git_describe_version
58        release = git_describe_version
59    else:
60        version = '.'.join([major_version, minor_version])
61        release = '.'.join([major_version,minor_version,subminor_version])
62
63# -- General configuration ---------------------------------------------------
64
65extensions = [
66    'sphinx_copybutton',
67    'sphinx.ext.todo',
68    'sphinxcontrib.bibtex',
69    'sphinxcontrib.katex',
70    'sphinxcontrib.rsvgconverter',
71    'html5_petsc',
72]
73
74master_doc = 'index'
75# Add any paths that contain templates here, relative to this directory.
76templates_path = ['_templates']
77
78# List of patterns, relative to source directory, that match files and
79# directories to ignore when looking for source files.
80# This pattern also affects html_static_path and html_extra_path.
81exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
82
83
84# -- Options for HTML output -------------------------------------------------
85
86html_theme = 'pydata_sphinx_theme'
87
88html_theme_options = {
89    "icon_links": [
90        {
91            "name": "GitLab",
92            "url": "https://gitlab.com/petsc/petsc",
93            "icon": "fab fa-gitlab",
94        },
95    ],
96    "use_edit_page_button": True,
97    "footer_items": ["copyright", "sphinx-version", "last-updated"],
98}
99
100# The theme uses "github" here, but it works for GitLab
101html_context = {
102    "github_url": "https://gitlab.com",
103    "github_user": "petsc",
104    "github_repo": "petsc",
105    "github_version": "main",
106    "doc_path": "doc",
107}
108
109# Add any paths that contain custom static files (such as style sheets) here,
110# relative to this directory. They are copied after the builtin static files,
111# so a file named "default.css" will overwrite the builtin "default.css".
112html_static_path = ['_static']
113
114html_logo = os.path.join('..', 'src', 'docs', 'website','images','PETSc-TAO_RGB.svg')
115html_favicon = os.path.join('..', 'src', 'docs', 'website','images','PETSc_RGB-logo.png')
116
117# Extra preprocessing for included "classic" docs
118import build_classic_docs
119html_extra_dir = build_classic_docs.main()
120
121# Additional files that are simply copied over with an HTML build
122html_extra_path = [html_extra_dir]
123
124html_last_updated_fmt = r'%Y-%m-%dT%H:%M:%S%z (' + git_describe_version + ')'
125
126# -- Options for LaTeX output --------------------------------------------
127
128bibtex_bibfiles = [
129        os.path.join('..', 'src', 'docs', 'tex', 'petsc.bib'),
130        os.path.join('..', 'src', 'docs', 'tex', 'petscapp.bib'),
131        ]
132latex_engine = 'xelatex'
133
134# Specify how to arrange the documents into LaTeX files.
135# This allows building only the manual.
136latex_documents = [
137        ('manual/index', 'manual.tex', 'PETSc Users Manual', author, 'manual', False)
138        ]
139
140latex_additional_files = [
141    'manual/anl_tech_report/ArgonneLogo.pdf',
142    'manual/anl_tech_report/ArgonneReportTemplateLastPage.pdf',
143    'manual/anl_tech_report/ArgonneReportTemplatePage2.pdf',
144    'manual/anl_tech_report/first.inc',
145    'manual/anl_tech_report/last.inc',
146]
147
148latex_elements = {
149    'maketitle': r'\newcommand{\techreportversion}{%s}' % version +
150r'''
151\input{first.inc}
152\sphinxmaketitle
153''',
154    'printindex': r'''
155\printindex
156\input{last.inc}
157''',
158    'fontpkg': r'''
159\setsansfont{DejaVu Sans}
160\setmonofont{DejaVu Sans Mono}
161'''
162}
163
164
165# -- General Config Options ---------------------------------------------------
166
167# Set default highlighting language
168highlight_language = 'c'
169autosummary_generate = True
170numfig = True
171
172# We must check what kind of builder the app uses to adjust
173def builder_init_handler(app):
174    import genteamtable
175    print("============================================")
176    print("    GENERATING TEAM TABLE FROM CONF.PY      ")
177    print("============================================")
178    genDirName = "generated"
179    cwdPath = os.path.dirname(os.path.realpath(__file__))
180    genDirPath = os.path.join(cwdPath, genDirName)
181    if "PETSC_GITLAB_PRIVATE_TOKEN" in os.environ:
182        token = os.environ["PETSC_GITLAB_PRIVATE_TOKEN"]
183    else:
184        token = None
185    genteamtable.main(genDirPath, token, app.builder.name)
186    return None
187
188# Supposedly the safer way to add additional css files. Setting html_css_files will
189# overwrite previous versions of the variable that some extension may have set. This will
190# add our css files in addition to it.
191def setup(app):
192    # Register the builder_init_handler to be called __after__ app.builder has been initialized
193    app.connect('builder-inited', builder_init_handler)
194    app.add_css_file('css/pop-up.css')
195    app.add_css_file('css/petsc-team-container.css')
196