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