| 1 |
# pylint: disable=invalid-name |
| 2 |
# Requires Python 3.6+ |
| 3 |
# Ref: https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 4 |
"""Configuration for the Sphinx documentation generator.""" |
| 5 |
|
| 6 |
import sys |
| 7 |
from functools import partial |
| 8 |
from pathlib import Path |
| 9 |
from typing import Mapping |
| 10 |
|
| 11 |
from sphinx.application import Sphinx |
| 12 |
|
| 13 |
from setuptools_scm import get_version |
| 14 |
|
| 15 |
|
| 16 |
# -- Path setup -------------------------------------------------------------- |
| 17 |
|
| 18 |
PROJECT_ROOT_DIR = Path(__file__).parents[1].resolve() |
| 19 |
PROJECT_SRC_DIR = PROJECT_ROOT_DIR / 'src' |
| 20 |
get_scm_version = partial(get_version, root=PROJECT_ROOT_DIR) |
| 21 |
|
| 22 |
# If extensions (or modules to document with autodoc) are in another directory, |
| 23 |
# add these directories to sys.path here. If the directory is relative to the |
| 24 |
# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 25 |
|
| 26 |
|
| 27 |
sys.path.insert(0, str(PROJECT_SRC_DIR)) |
| 28 |
|
| 29 |
|
| 30 |
# -- Project information ----------------------------------------------------- |
| 31 |
|
| 32 |
github_url = 'https://github.com' |
| 33 |
github_repo_org = 'sphinx-contrib' |
| 34 |
github_repo_name = 'sphinxcontrib-towncrier' |
| 35 |
github_repo_slug = f'{github_repo_org}/{github_repo_name}' |
| 36 |
github_repo_url = f'{github_url}/{github_repo_slug}' |
| 37 |
github_sponsors_url = f'{github_url}/sponsors' |
| 38 |
|
| 39 |
project = github_repo_name |
| 40 |
author = 'Sviatoslav Sydorenko' |
| 41 |
copyright = f'2021, {author}' # pylint: disable=redefined-builtin |
| 42 |
|
| 43 |
# The short X.Y version |
| 44 |
version = '.'.join( |
| 45 |
get_scm_version( |
| 46 |
local_scheme='no-local-version', |
| 47 |
).split('.')[:3], |
| 48 |
) |
| 49 |
|
| 50 |
# The full version, including alpha/beta/rc tags |
| 51 |
release = get_scm_version() |
| 52 |
|
| 53 |
rst_epilog = f""" |
| 54 |
.. |project| replace:: {project} |
| 55 |
""" |
| 56 |
|
| 57 |
|
| 58 |
# -- General configuration --------------------------------------------------- |
| 59 |
|
| 60 |
extensions = [ |
| 61 |
# Built-in extensions: |
| 62 |
'sphinx.ext.autodoc', |
| 63 |
'sphinx.ext.autosectionlabel', # autocreate section targets for refs |
| 64 |
'sphinx.ext.doctest', |
| 65 |
'sphinx.ext.extlinks', |
| 66 |
'sphinx.ext.intersphinx', |
| 67 |
'sphinx.ext.todo', |
| 68 |
'sphinx.ext.coverage', |
| 69 |
'sphinx.ext.viewcode', |
| 70 |
|
| 71 |
# Third-party extensions: |
| 72 |
'myst_parser', # extended markdown; https://pypi.org/project/myst-parser/ |
| 73 |
'sphinxcontrib.apidoc', |
| 74 |
|
| 75 |
# Tree-local extensions: |
| 76 |
'sphinxcontrib.towncrier.ext', # provides `.. towncrier-draft-entries::` |
| 77 |
] |
| 78 |
|
| 79 |
# Add any paths that contain templates here, relative to this directory. |
| 80 |
templates_path = ['_templates'] |
| 81 |
|
| 82 |
# The language for content autogenerated by Sphinx. Refer to documentation |
| 83 |
# for a list of supported languages. |
| 84 |
# |
| 85 |
# This is also used if you do content translation via gettext catalogs. |
| 86 |
# Usually you set "language" from the command line for these cases. |
| 87 |
language = 'en' |
| 88 |
|
| 89 |
# List of patterns, relative to source directory, that match files and |
| 90 |
# directories to ignore when looking for source files. |
| 91 |
# This pattern also affects html_static_path and html_extra_path. |
| 92 |
exclude_patterns = [ |
| 93 |
'_build', 'Thumbs.db', '.DS_Store', # <- Defaults |
| 94 |
'changelog-fragments/**', # Towncrier-managed change notes |
| 95 |
] |
| 96 |
|
| 97 |
|
| 98 |
# -- Options for HTML output ------------------------------------------------- |
| 99 |
|
| 100 |
html_theme = 'furo' |
| 101 |
|
| 102 |
html_show_sphinx = True |
| 103 |
|
| 104 |
|
| 105 |
# -- Extension configuration ------------------------------------------------- |
| 106 |
|
| 107 |
# -- Options for intersphinx extension --------------------------------------- |
| 108 |
|
| 109 |
intersphinx_mapping = { |
| 110 |
'python': ('https://docs.python.org/3', None), |
| 111 |
'rtd': ('https://docs.rtfd.io/en/stable', None), |
| 112 |
'setuptools': ('https://setuptools.rtfd.io/en/latest', None), |
| 113 |
'sphinx': ('https://www.sphinx-doc.org/en/master', None), |
| 114 |
} |
| 115 |
|
| 116 |
# -- Options for todo extension ---------------------------------------------- |
| 117 |
|
| 118 |
# If true, `todo` and `todoList` produce output, else they produce nothing. |
| 119 |
todo_include_todos = True |
| 120 |
|
| 121 |
# -- Options for sphinxcontrib.apidoc extension ------------------------------ |
| 122 |
|
| 123 |
apidoc_excluded_paths = [] |
| 124 |
apidoc_extra_args = [ |
| 125 |
'--implicit-namespaces', |
| 126 |
'--private', # include “_private” modules |
| 127 |
] |
| 128 |
apidoc_module_dir = str(PROJECT_SRC_DIR / 'sphinxcontrib') |
| 129 |
apidoc_module_first = False |
| 130 |
apidoc_output_dir = 'pkg' |
| 131 |
apidoc_separate_modules = True |
| 132 |
apidoc_toc_file = None |
| 133 |
|
| 134 |
# -- Options for extlinks extension ------------------------------------------ |
| 135 |
|
| 136 |
extlinks = { |
| 137 |
'issue': (f'{github_repo_url}/issues/%s', '#%s'), # noqa: WPS323 |
| 138 |
'pr': (f'{github_repo_url}/pull/%s', 'PR #%s'), # noqa: WPS323 |
| 139 |
'commit': (f'{github_repo_url}/commit/%s', '%s'), # noqa: WPS323 |
| 140 |
'gh': (f'{github_url}/%s', 'GitHub: %s'), # noqa: WPS323 |
| 141 |
'user': (f'{github_sponsors_url}/%s', '@%s'), # noqa: WPS323 |
| 142 |
} |
| 143 |
|
| 144 |
# -- Options for linkcheck builder ------------------------------------------- |
| 145 |
|
| 146 |
linkcheck_ignore = [ |
| 147 |
r'http://localhost:\d+/', # local URLs |
| 148 |
] |
| 149 |
linkcheck_workers = 25 |
| 150 |
|
| 151 |
# Ref: |
| 152 |
# * https://github.com/djungelorm/sphinx-tabs/issues/26#issuecomment-422160463 |
| 153 |
sphinx_tabs_valid_builders = ['linkcheck'] # prevent linkcheck warning |
| 154 |
|
| 155 |
# -- Options for autosectionlabel extension ---------------------------------- |
| 156 |
|
| 157 |
# Ref: |
| 158 |
# * https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html |
| 159 |
autosectionlabel_maxdepth = 2 # mitigate Towncrier nested subtitles collision |
| 160 |
|
| 161 |
# -- Options for towncrier_draft extension ----------------------------------- |
| 162 |
|
| 163 |
# mode is one of 'draft', 'sphinx-version' or 'sphinx-release' |
| 164 |
towncrier_draft_autoversion_mode = 'draft' |
| 165 |
towncrier_draft_include_empty = True |
| 166 |
towncrier_draft_working_directory = PROJECT_ROOT_DIR |
| 167 |
# Not yet supported: |
| 168 |
towncrier_draft_config_path = 'pyproject.toml' # relative to cwd |
| 169 |
|
| 170 |
# -- Strict mode ------------------------------------------------------------- |
| 171 |
|
| 172 |
# Ref: python-attrs/attrs#571 |
| 173 |
default_role = 'any' |
| 174 |
|
| 175 |
nitpicky = True |
| 176 |
_py_class_role = 'py:class' |
| 177 |
nitpick_ignore = [ |
| 178 |
# NOTE: Docutils does not have any intersphinx-compatible site |
| 179 |
(_py_class_role, 'docutils.nodes.Node'), |
| 180 |
(_py_class_role, 'docutils.nodes.document'), |
| 181 |
(_py_class_role, 'docutils.statemachine.State'), |
| 182 |
(_py_class_role, 'docutils.nodes.Node'), |
| 183 |
] |
| 184 |
|
| 185 |
|
| 186 |
def setup(app: Sphinx) -> Mapping[str, str]: |
| 187 |
"""Set up extra Sphinx extension integrations.""" |
| 188 |
# NOTE: Sphinx doesn't seem to expose its :event: role at the moment. |
| 189 |
# NOTE: This hack re-declares the event type locally. |
| 190 |
# Ref: https://github.com/sphinx-doc/sphinx/issues/8987 |
| 191 |
app.add_object_type('event', 'event') |
| 192 |
|
| 193 |
return { |
| 194 |
'parallel_read_safe': True, |
| 195 |
'parallel_write_safe': True, |
| 196 |
'version': 'builtin', |
| 197 |
} |