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