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 subprocess
19
import sys
20
21
22
from pathlib import Path

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

# 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.
27
# sys.path.insert(0, os.path.abspath('.'))
28
29
30
31

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

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

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

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

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

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

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

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

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

# 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.
69
70
71
72
73
74
75

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

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

# 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:
88
# today = ''
89
# Else, today_fmt is used as the format for a strftime call.
90
# today_fmt = '%B %d, %Y'
91
92
93

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

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

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

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

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

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

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

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

# 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.

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

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

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

137
    html_context = {"css_files": ["_static/theme_overrides.css"]}
138
139
else:
    html_context = {
140
141
142
143
        "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
144
145
        ]
    }
146
147
148
149

# 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.
150
# html_theme_options = {}
151
152

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

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

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

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

# 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.
169
# html_favicon = None
170
171
172
173

# 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".
174
html_static_path = ["_static"]
175
176
177
178

# 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.
179
# html_extra_path = []
180
181
182

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

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

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

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

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

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

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

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

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

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

# 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.
217
# html_use_opensearch = ''
218
219

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

# 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'
226
# html_search_language = 'en'
227
228
229

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

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

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

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

241
242
latex_engine = "pdflatex"

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

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

# 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 = [
272
    (master_doc, "pybind11.tex", "pybind11 Documentation", "Wenzel Jakob", "manual"),
273
274
275
276
]

# 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
277
# latex_logo = 'pybind11-logo.png'
278
279
280

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

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

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

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

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


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

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

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


# -- 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 = [
312
313
314
315
316
317
318
319
320
    (
        master_doc,
        "pybind11",
        "pybind11 Documentation",
        author,
        "pybind11",
        "One line description of project.",
        "Miscellaneous",
    ),
321
322
323
]

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

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

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

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

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


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

    try:
345
346
        subprocess.call(["doxygen", "--version"])
        retcode = subprocess.call(["doxygen"], cwd=app.confdir)
347
348
349
350
351
352
        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))


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

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

        # Filter out section titles for index.rst for LaTeX
362
363
364
365
366
367
368
369
370
371
        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()


372
def setup(app):
373
374

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

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

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