xref: /aosp_15_r20/external/pytorch/docs/cpp/source/conf.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#
2# PyTorch documentation build configuration file, created by
3# sphinx-quickstart on Fri Dec 23 13:31:47 2016.
4#
5# This file is execfile()d with the current directory set to its
6# containing dir.
7#
8# Note that not all possible configuration values are present in this
9# autogenerated file.
10#
11# All configuration values have a default; values that are commented out
12# serve to show the default.
13
14# If extensions (or modules to document with autodoc) are in another directory,
15# add these directories to sys.path here. If the directory is relative to the
16# documentation root, use os.path.abspath to make it absolute, like shown here.
17#
18# NB: C++ API doc generation using doxygen / breathe / exhale is currently only
19# enabled on nightlies (and not trunk or on PRs) due to OOM errors in CI.
20# See https://github.com/pytorch/pytorch/issues/79992.
21
22import os
23import textwrap
24
25
26# sys.path.insert(0, os.path.abspath('.'))
27
28
29# -- General configuration ------------------------------------------------
30
31# If your documentation needs a minimal Sphinx version, state it here.
32#
33needs_sphinx = "3.1.2"
34run_doxygen = os.environ.get("RUN_DOXYGEN", "false") == "true"
35
36# Add any Sphinx extension module names here, as strings. They can be
37# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
38# ones.
39extensions = [
40    "sphinx.ext.intersphinx",
41] + (["breathe", "exhale"] if run_doxygen else [])
42
43intersphinx_mapping = {"pytorch": ("https://pytorch.org/docs/main", None)}
44
45# Setup absolute paths for communicating with breathe / exhale where
46# items are expected / should be trimmed by.
47# This file is {repo_root}/docs/cpp/source/conf.py
48this_file_dir = os.path.abspath(os.path.dirname(__file__))
49doxygen_xml_dir = os.path.join(
50    os.path.dirname(this_file_dir),  # {repo_root}/docs/cpp
51    "build",  # {repo_root}/docs/cpp/build
52    "xml",  # {repo_root}/docs/cpp/build/xml
53)
54repo_root = os.path.dirname(  # {repo_root}
55    os.path.dirname(  # {repo_root}/docs
56        os.path.dirname(  # {repo_root}/docs/cpp
57            this_file_dir  # {repo_root}/docs/cpp/source
58        )
59    )
60)
61
62breathe_projects = {"PyTorch": doxygen_xml_dir}
63breathe_default_project = "PyTorch"
64
65# Setup the exhale extension
66exhale_args = {
67    ############################################################################
68    # These arguments are required.                                            #
69    ############################################################################
70    "containmentFolder": "./api",
71    "rootFileName": "library_root.rst",
72    "rootFileTitle": "Library API",
73    "doxygenStripFromPath": repo_root,
74    ############################################################################
75    # Suggested optional arguments.                                            #
76    ############################################################################
77    "createTreeView": True,
78    "exhaleExecutesDoxygen": True,
79    "exhaleUseDoxyfile": True,
80    "verboseBuild": True,
81    ############################################################################
82    # HTML Theme specific configurations.                                      #
83    ############################################################################
84    # Fix broken Sphinx RTD Theme 'Edit on GitHub' links
85    # Search for 'Edit on GitHub' on the FAQ:
86    #     http://exhale.readthedocs.io/en/latest/faq.html
87    "pageLevelConfigMeta": ":github_url: https://github.com/pytorch/pytorch",
88    ############################################################################
89    # Individual page layout example configuration.                            #
90    ############################################################################
91    # Example of adding contents directives on custom kinds with custom title
92    "contentsTitle": "Page Contents",
93    "kindsWithContentsDirectives": ["class", "file", "namespace", "struct"],
94    # Exclude PIMPL files from class hierarchy tree and namespace pages.
95    "listingExclude": [r".*Impl$"],
96    ############################################################################
97    # Main library page layout example configuration.                          #
98    ############################################################################
99    "afterTitleDescription": textwrap.dedent(
100        """
101        Welcome to the developer reference for the PyTorch C++ API.
102    """
103    ),
104}
105
106# Tell sphinx what the primary language being documented is.
107primary_domain = "cpp"
108
109# Tell sphinx what the pygments highlight language should be.
110highlight_language = "cpp"
111
112# Add any paths that contain templates here, relative to this directory.
113# templates_path = ['_templates']
114
115# The suffix(es) of source filenames.
116# You can specify multiple suffix as a list of string:
117#
118# source_suffix = ['.rst', '.md']
119source_suffix = ".rst"
120
121# The master toctree document.
122master_doc = "index"
123
124# General information about the project.
125project = "PyTorch"
126copyright = "2024, PyTorch Contributors"
127author = "PyTorch Contributors"
128
129# The version info for the project you're documenting, acts as replacement for
130# |version| and |release|, also used in various other places throughout the
131# built documents.
132#
133# The short X.Y version.
134# TODO: change to [:2] at v1.0
135version = "main"
136# The full version, including alpha/beta/rc tags.
137# TODO: verify this works as expected
138release = "main"
139
140# The language for content autogenerated by Sphinx. Refer to documentation
141# for a list of supported languages.
142#
143# This is also used if you do content translation via gettext catalogs.
144# Usually you set "language" from the command line for these cases.
145language = None
146
147# List of patterns, relative to source directory, that match files and
148# directories to ignore when looking for source files.
149# This patterns also effect to html_static_path and html_extra_path
150exclude_patterns = []
151
152# The name of the Pygments (syntax highlighting) style to use.
153pygments_style = "sphinx"
154
155# If true, `todo` and `todoList` produce output, else they produce nothing.
156todo_include_todos = True
157
158# -- Options for HTML output ----------------------------------------------
159
160# The theme to use for HTML and HTML Help pages.  See the documentation for
161# a list of builtin themes.
162#
163html_theme = "pytorch_sphinx_theme"
164
165# Theme options are theme-specific and customize the look and feel of a theme
166# further.  For a list of options available for each theme, see the
167# documentation.
168#
169html_theme_options = {
170    "canonical_url": "https://pytorch.org/docs/stable/",
171    "pytorch_project": "docs",
172    "collapse_navigation": False,
173    "display_version": True,
174    "logo_only": True,
175}
176
177# NOTE: sharing python docs resources
178html_logo = os.path.join(
179    repo_root, "docs", "source", "_static", "img", "pytorch-logo-dark-unstable.png"
180)
181
182# Add any paths that contain custom static files (such as style sheets) here,
183# relative to this directory. They are copied after the builtin static files,
184# so a file named "default.css" will overwrite the builtin "default.css".
185# NOTE: sharing python docs resources
186html_static_path = [os.path.join(repo_root, "docs", "cpp", "source", "_static")]
187
188
189# Called automatically by Sphinx, making this `conf.py` an "extension".
190def setup(app):
191    # NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
192    # and can be moved outside of this function (and the setup(app) function
193    # can be deleted).
194    html_css_files = ["cpp_theme.css"]
195
196    # In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
197    # `add_stylesheet` (deprecated in 1.8).
198    add_css = getattr(app, "add_css_file", app.add_stylesheet)
199    for css_file in html_css_files:
200        add_css(css_file)
201
202
203# -- Options for HTMLHelp output ------------------------------------------
204
205# Output file base name for HTML help builder.
206# htmlhelp_basename = 'PyTorchdoc'
207
208
209# -- Options for LaTeX output ---------------------------------------------
210
211latex_elements = {
212    # The paper size ('letterpaper' or 'a4paper').
213    #
214    # 'papersize': 'letterpaper',
215    # The font size ('10pt', '11pt' or '12pt').
216    #
217    # 'pointsize': '10pt',
218    # Additional stuff for the LaTeX preamble.
219    #
220    # 'preamble': '',
221    # Latex figure (float) alignment
222    #
223    # 'figure_align': 'htbp',
224}
225
226# Grouping the document tree into LaTeX files. List of tuples
227# (source start file, target name, title,
228#  author, documentclass [howto, manual, or own class]).
229latex_documents = [
230    (
231        master_doc,
232        "pytorch.tex",
233        "PyTorch Documentation",
234        "Torch Contributors",
235        "manual",
236    ),
237]
238
239
240# -- Options for manual page output ---------------------------------------
241
242# One entry per manual page. List of tuples
243# (source start file, name, description, authors, manual section).
244man_pages = [(master_doc, "PyTorch", "PyTorch Documentation", [author], 1)]
245
246
247# -- Options for Texinfo output -------------------------------------------
248
249# Grouping the document tree into Texinfo files. List of tuples
250# (source start file, target name, title, author,
251#  dir menu entry, description, category)
252texinfo_documents = [
253    (
254        master_doc,
255        "PyTorch",
256        "PyTorch Documentation",
257        author,
258        "PyTorch",
259        "One line description of project.",
260        "Miscellaneous",
261    ),
262]
263