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