|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# This file is execfile()d with the current directory set to its |
| 4 | +# containing dir. |
| 5 | +# |
| 6 | +# Note that not all possible configuration values are present in this |
| 7 | +# autogenerated file. |
| 8 | +# |
| 9 | +# All configuration values have a default; values that are commented out |
| 10 | +# serve to show the default. |
| 11 | + |
| 12 | +# If extensions (or modules to document with autodoc) are in another directory, |
| 13 | +# add these directories to sys.path here. If the directory is relative to the |
| 14 | +# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 15 | +# |
| 16 | +import os |
| 17 | +import sys |
| 18 | +import sphinx_rtd_theme |
| 19 | + |
| 20 | +# Assumes substitutions.py and version_list.py are in the parent dir of doc-builder |
| 21 | +# pylint: disable=wrong-import-position |
| 22 | +dir2add = os.path.join(os.path.dirname(__file__), os.pardir) |
| 23 | +sys.path.insert(0, dir2add) |
| 24 | +import substitutions as subs # pylint: disable=import-error |
| 25 | +from version_list import VERSION_LIST # pylint: disable=import-error |
| 26 | + |
| 27 | + |
| 28 | +# -- General configuration ------------------------------------------------ |
| 29 | + |
| 30 | +# If your documentation needs a minimal Sphinx version, state it here. |
| 31 | +# |
| 32 | +# needs_sphinx = '1.0' |
| 33 | + |
| 34 | +# Add any Sphinx extension module names here, as strings. They can be |
| 35 | +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 36 | +# ones. |
| 37 | +extensions = ['sphinx.ext.intersphinx', |
| 38 | + 'sphinx.ext.autodoc', |
| 39 | + 'sphinx.ext.todo', |
| 40 | + 'sphinx.ext.coverage', |
| 41 | + 'sphinx.ext.githubpages', |
| 42 | + 'sphinx_mdinclude', |
| 43 | + ] |
| 44 | + |
| 45 | +# Add any paths that contain templates here, relative to this directory. |
| 46 | +if os.environ["templates_path"]: |
| 47 | + templates_path = [os.environ["templates_path"]] |
| 48 | + if not all(os.path.isdir(x) for x in templates_path): |
| 49 | + raise RuntimeError(f"Some member of templates_path does not exist: {templates_path}") |
| 50 | + |
| 51 | +# The suffix(es) of source filenames. |
| 52 | +# You can specify multiple suffix as a list of string: |
| 53 | +# |
| 54 | +source_suffix = ['.rst', '.md'] |
| 55 | +# source_suffix = '.rst' |
| 56 | + |
| 57 | +# The master toctree document. |
| 58 | +source_start_file = 'index' |
| 59 | + |
| 60 | +# Save standard Sphinx substitution vars separately |
| 61 | +project = subs.project |
| 62 | +copyright = subs.copyright # pylint: disable=redefined-builtin |
| 63 | +author = subs.author |
| 64 | +version = subs.version |
| 65 | +release = subs.release |
| 66 | + |
| 67 | +# version_label is not a standard sphinx variable, so we need some custom rst to allow |
| 68 | +# pages to use it. We need a separate replacement for the bolded version because it |
| 69 | +# doesn't work to have variable replacements within formatting. |
| 70 | +rst_epilog = """ |
| 71 | +.. |version_label| replace:: {version_label} |
| 72 | +.. |version_label_bold| replace:: **{version_label}** |
| 73 | +""".format(version_label=subs.version_label) |
| 74 | + |
| 75 | +# The language for content autogenerated by Sphinx. Refer to documentation |
| 76 | +# for a list of supported languages. |
| 77 | +# |
| 78 | +# This is also used if you do content translation via gettext catalogs. |
| 79 | +# Usually you set "language" from the command line for these cases. |
| 80 | +language = "en" |
| 81 | + |
| 82 | +# List of patterns, relative to source directory, that match files and |
| 83 | +# directories to ignore when looking for source files. |
| 84 | +# This patterns also effect to html_static_path and html_extra_path |
| 85 | +exclude_patterns = [] |
| 86 | + |
| 87 | +# The name of the Pygments (syntax highlighting) style to use. |
| 88 | +pygments_style = 'sphinx' |
| 89 | + |
| 90 | +# If true, `todo` and `todoList` produce output, else they produce nothing. |
| 91 | +todo_include_todos = True |
| 92 | + |
| 93 | +# -- Options for HTML output ---------------------------------------------- |
| 94 | + |
| 95 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 96 | +# a list of builtin themes. |
| 97 | +# |
| 98 | +html_theme = 'sphinx_rtd_theme' |
| 99 | + |
| 100 | +# Theme options are theme-specific and customize the look and feel of a theme |
| 101 | +# further. For a list of options available for each theme, see the |
| 102 | +# documentation. |
| 103 | + |
| 104 | +# Add any paths that contain custom static files (such as style sheets) here, |
| 105 | +# relative to this directory. They are copied after the builtin static files, |
| 106 | +# so a file named "default.css" will overwrite the builtin "default.css". |
| 107 | +html_static_path = [os.environ["html_static_path"]] |
| 108 | + |
| 109 | + |
| 110 | +# -- Options for HTMLHelp output ------------------------------------------ |
| 111 | + |
| 112 | +if getattr(subs, "htmlhelp", False): |
| 113 | + htmlhelp_basename = subs.htmlhelp["basename"] |
| 114 | + |
| 115 | + |
| 116 | +# -- Options for LaTeX output --------------------------------------------- |
| 117 | +if getattr(subs, "latex", False): |
| 118 | + |
| 119 | + latex_elements = { |
| 120 | + # The paper size ('letterpaper' or 'a4paper'). |
| 121 | + # |
| 122 | + # 'papersize': 'letterpaper', |
| 123 | + |
| 124 | + # The font size ('10pt', '11pt' or '12pt'). |
| 125 | + # |
| 126 | + # 'pointsize': '10pt', |
| 127 | + |
| 128 | + # Additional stuff for the LaTeX preamble. |
| 129 | + # |
| 130 | + 'preamble': '\\usepackage{hyperref}', |
| 131 | + |
| 132 | + 'fncychap': '\\usepackage[Conny]{fncychap}', |
| 133 | + |
| 134 | + # Latex figure (float) alignment |
| 135 | + # |
| 136 | + # 'figure_align': 'htbp', |
| 137 | + } |
| 138 | + |
| 139 | + # Grouping the document tree into LaTeX files. List of tuples |
| 140 | + # (source start file, target name, title, |
| 141 | + # author, documentclass [howto, manual, or own class]). |
| 142 | + latex_documents = [( |
| 143 | + source_start_file, |
| 144 | + subs.latex["target_name"], |
| 145 | + subs.latex["title"], |
| 146 | + author, |
| 147 | + subs.latex["category"], |
| 148 | + )] |
| 149 | + |
| 150 | + |
| 151 | +# Options for manual page and Texinfo output |
| 152 | +if getattr(subs, "mantex", False): |
| 153 | + |
| 154 | + # One entry per manual page. List of tuples |
| 155 | + # (source start file, name, title, authors, manual section). |
| 156 | + man_pages = [ |
| 157 | + (source_start_file, subs.mantex["name"], subs.mantex["title"], [author], 1), |
| 158 | + ] |
| 159 | + |
| 160 | + if getattr(subs, "tex", False): |
| 161 | + # Grouping the document tree into Texinfo files. List of tuples |
| 162 | + # (source start file, target name, title, author, |
| 163 | + # dir menu entry, description, category) |
| 164 | + texinfo_documents = [( |
| 165 | + source_start_file, |
| 166 | + subs.mantex["name"], |
| 167 | + subs.mantex["title"], |
| 168 | + author, |
| 169 | + subs.tex["dirmenu_entry"], |
| 170 | + subs.tex["description"], |
| 171 | + subs.tex["category"]), |
| 172 | + ] |
| 173 | + |
| 174 | +# Example configuration for intersphinx: refer to the Python standard library. |
| 175 | +intersphinx_mapping = {'python': ('https://docs.python.org/', None)} |
| 176 | + |
| 177 | +numfig = True |
| 178 | +numfig_format = {'figure': 'Figure %s', |
| 179 | + 'table': 'Table %s', |
| 180 | + 'code-block': 'Code %s', |
| 181 | + 'section': '%s', |
| 182 | + } |
| 183 | +numfig_secnum_depth = 2 |
| 184 | + |
| 185 | +def setup(app): |
| 186 | + app.add_css_file('css/custom.css') |
| 187 | + |
| 188 | +try: |
| 189 | + html_context |
| 190 | +except NameError: |
| 191 | + html_context = dict() |
| 192 | + |
| 193 | +html_context["display_lower_left"] = True |
| 194 | + |
| 195 | +# Whether to show the version dropdown. If not set as environment variable, or environment variable |
| 196 | +# is Python-falsey, do not show it. |
| 197 | +version_dropdown = os.environ.get("version_dropdown") |
| 198 | + |
| 199 | +if version_dropdown: |
| 200 | + html_context["current_version"] = os.environ["version_display_name"] |
| 201 | + |
| 202 | + html_context["versions"] = [] |
| 203 | + pages_root = os.environ["pages_root"] |
| 204 | + for this_version in VERSION_LIST: |
| 205 | + html_context["versions"].append([ |
| 206 | + this_version.display_name, |
| 207 | + os.path.join(pages_root, this_version.subdir()), |
| 208 | + ]) |
0 commit comments