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