conf.py 11.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# pybind11 documentation build configuration file, created by
# sphinx-quickstart on Sun Oct 11 19:23:48 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
17
import re
18
import shlex
19
import subprocess
20
import sys
21
22
23
from pathlib import Path

DIR = Path(__file__).parent.resolve()
24
25
26
27

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
28
# sys.path.insert(0, os.path.abspath('.'))
29
30
31
32

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
33
# needs_sphinx = '1.0'
34
35
36
37

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
38
39
40
41
42
extensions = [
    "breathe",
    "sphinxcontrib.rsvgconverter",
    "sphinxcontrib.moderncmakedomain",
]
43

44
45
46
breathe_projects = {"pybind11": ".build/doxygenxml/"}
breathe_default_project = "pybind11"
breathe_domain_by_extension = {"h": "cpp"}
47
48

# Add any paths that contain templates here, relative to this directory.
49
templates_path = [".templates"]
50
51
52
53

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md']
54
source_suffix = ".rst"
55
56

# The encoding of source files.
57
# source_encoding = 'utf-8-sig'
58
59

# The master toctree document.
60
master_doc = "index"
61
62

# General information about the project.
63
64
65
project = "pybind11"
copyright = "2017, Wenzel Jakob"
author = "Wenzel Jakob"
66
67
68
69

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
70
71
72
73
74
75
76

# Read the listed version
with open("../pybind11/_version.py") as f:
    code = compile(f.read(), "../pybind11/_version.py", "exec")
loc = {}
exec(code, loc)

77
# The full version, including alpha/beta/rc tags.
78
version = loc["__version__"]
79
80
81
82
83
84
85
86
87
88

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
89
# today = ''
90
# Else, today_fmt is used as the format for a strftime call.
91
# today_fmt = '%B %d, %Y'
92
93
94

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
95
exclude_patterns = [".build", "release.rst"]
96
97
98

# The reST default role (used for this markup: `text`) to use for all
# documents.
99
default_role = "any"
100
101

# If true, '()' will be appended to :func: etc. cross-reference text.
102
# add_function_parentheses = True
103
104
105

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
106
# add_module_names = True
107
108
109

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
110
# show_authors = False
111
112

# The name of the Pygments (syntax highlighting) style to use.
113
# pygments_style = 'monokai'
114
115

# A list of ignored prefixes for module index sorting.
116
# modindex_common_prefix = []
117
118

# If true, keep warnings as "system message" paragraphs in the built documents.
119
# keep_warnings = False
120
121
122
123
124
125
126
127
128
129

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.

130
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
131
132
133

if not on_rtd:  # only import and set the theme if we're building docs locally
    import sphinx_rtd_theme
134
135

    html_theme = "sphinx_rtd_theme"
136
    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
137

138
    html_context = {"css_files": ["_static/theme_overrides.css"]}
139
140
else:
    html_context = {
141
142
143
144
        "css_files": [
            "//media.readthedocs.org/css/sphinx_rtd_theme.css",
            "//media.readthedocs.org/css/readthedocs-doc-embed.css",
            "_static/theme_overrides.css",
Wenzel Jakob's avatar
Wenzel Jakob committed
145
146
        ]
    }
147
148
149
150

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
151
# html_theme_options = {}
152
153

# Add any paths that contain custom themes here, relative to this directory.
154
# html_theme_path = []
155
156

# The name for this set of Sphinx documents.  If None, it defaults to
157
# "<project> v<version> documentation".
158
# html_title = None
159
160

# A shorter title for the navigation bar.  Default is the same as html_title.
161
# html_short_title = None
162
163
164

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
165
# html_logo = None
166
167
168
169

# The name of an image file (within the static path) to use as favicon of the
# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
170
# html_favicon = None
171
172
173
174

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
175
html_static_path = ["_static"]
176
177
178
179

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
180
# html_extra_path = []
181
182
183

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
184
# html_last_updated_fmt = '%b %d, %Y'
185
186
187

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
188
# html_use_smartypants = True
189
190

# Custom sidebar templates, maps document names to template names.
191
# html_sidebars = {}
192
193
194

# Additional templates that should be rendered to pages, maps page names to
# template names.
195
# html_additional_pages = {}
196
197

# If false, no module index is generated.
198
# html_domain_indices = True
199
200

# If false, no index is generated.
201
# html_use_index = True
202
203

# If true, the index is split into individual pages for each letter.
204
# html_split_index = False
205
206

# If true, links to the reST sources are added to the pages.
207
# html_show_sourcelink = True
208
209

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
210
# html_show_sphinx = True
211
212

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
213
# html_show_copyright = True
214
215
216
217

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it.  The value of this option must be the
# base URL from which the finished HTML is served.
218
# html_use_opensearch = ''
219
220

# This is the file name suffix for HTML files (e.g. ".xhtml").
221
# html_file_suffix = None
222
223
224
225
226

# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
#   'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
#   'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
227
# html_search_language = 'en'
228
229
230

# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value
231
# html_search_options = {'type': 'default'}
232
233
234

# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
235
# html_search_scorer = 'scorer.js'
236
237

# Output file base name for HTML help builder.
238
htmlhelp_basename = "pybind11doc"
239
240
241

# -- Options for LaTeX output ---------------------------------------------

242
243
latex_engine = "pdflatex"

244
latex_elements = {
245
246
    # The paper size ('letterpaper' or 'a4paper').
    # 'papersize': 'letterpaper',
Henry Schreiner's avatar
Henry Schreiner committed
247
    #
248
249
    # The font size ('10pt', '11pt' or '12pt').
    # 'pointsize': '10pt',
Henry Schreiner's avatar
Henry Schreiner committed
250
    #
251
    # Additional stuff for the LaTeX preamble.
Henry Schreiner's avatar
Henry Schreiner committed
252
253
    # remove blank pages (between the title page and the TOC, etc.)
    "classoptions": ",openany,oneside",
254
    "preamble": r"""
Henry Schreiner's avatar
Henry Schreiner committed
255
256
\usepackage{fontawesome}
\usepackage{textgreek}
257
\DeclareUnicodeCharacter{00A0}{}
Henry Schreiner's avatar
Henry Schreiner committed
258
259
260
261
262
263
\DeclareUnicodeCharacter{2194}{\faArrowsH}
\DeclareUnicodeCharacter{1F382}{\faBirthdayCake}
\DeclareUnicodeCharacter{1F355}{\faAdjust}
\DeclareUnicodeCharacter{0301}{'}
\DeclareUnicodeCharacter{03C0}{\textpi}

264
265
266
""",
    # Latex figure (float) alignment
    # 'figure_align': 'htbp',
267
268
269
270
271
272
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
273
    (master_doc, "pybind11.tex", "pybind11 Documentation", "Wenzel Jakob", "manual"),
274
275
276
277
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Wenzel Jakob's avatar
Wenzel Jakob committed
278
# latex_logo = 'pybind11-logo.png'
279
280
281

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
282
# latex_use_parts = False
283
284

# If true, show page references after internal links.
285
# latex_show_pagerefs = False
286
287

# If true, show URL addresses after external links.
288
# latex_show_urls = False
289
290

# Documents to append as an appendix to all manuals.
291
# latex_appendices = []
292
293

# If false, no module index is generated.
294
# latex_domain_indices = True
295
296
297
298
299
300


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
301
man_pages = [(master_doc, "pybind11", "pybind11 Documentation", [author], 1)]
302
303

# If true, show URL addresses after external links.
304
# man_show_urls = False
305
306
307
308
309
310
311
312


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
313
314
315
316
317
318
319
320
321
    (
        master_doc,
        "pybind11",
        "pybind11 Documentation",
        author,
        "pybind11",
        "One line description of project.",
        "Miscellaneous",
    ),
322
323
324
]

# Documents to append as an appendix to all manuals.
325
# texinfo_appendices = []
326
327

# If false, no module index is generated.
328
# texinfo_domain_indices = True
329
330

# How to display URL addresses: 'footnote', 'no', or 'inline'.
331
# texinfo_show_urls = 'footnote'
332
333

# If true, do not generate a @detailmenu in the "Top" node's menu.
334
# texinfo_no_detailmenu = False
335

336
337
primary_domain = "cpp"
highlight_language = "cpp"
338
339
340


def generate_doxygen_xml(app):
341
    build_dir = os.path.join(app.confdir, ".build")
342
343
344
345
    if not os.path.exists(build_dir):
        os.mkdir(build_dir)

    try:
346
347
        subprocess.call(["doxygen", "--version"])
        retcode = subprocess.call(["doxygen"], cwd=app.confdir)
348
349
350
351
352
353
        if retcode < 0:
            sys.stderr.write("doxygen error code: {}\n".format(-retcode))
    except OSError as e:
        sys.stderr.write("doxygen execution failed: {}\n".format(e))


354
355
356
357
358
def prepare(app):
    with open(DIR.parent / "README.rst") as f:
        contents = f.read()

    if app.builder.name == "latex":
359
360
361
362
        # Remove badges and stuff from start
        contents = contents[contents.find(r".. start") :]

        # Filter out section titles for index.rst for LaTeX
363
364
365
366
367
368
369
370
371
372
        contents = re.sub(r"^(.*)\n[-~]{3,}$", r"**\1**", contents, flags=re.MULTILINE)

    with open(DIR / "readme.rst", "w") as f:
        f.write(contents)


def clean_up(app, exception):
    (DIR / "readme.rst").unlink()


373
def setup(app):
374
375

    # Add hook for building doxygen xml when needed
376
    app.connect("builder-inited", generate_doxygen_xml)
377
378
379
380
381
382

    # Copy the readme in
    app.connect("builder-inited", prepare)

    # Clean up the generated readme
    app.connect("build-finished", clean_up)