conf.py 5.49 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
# -*- coding: utf-8 -*-
Patrick Labatut's avatar
Patrick Labatut committed
2
3
4
5
6
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
facebook-github-bot's avatar
facebook-github-bot committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# flake8: noqa

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# 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.
#
import os
import sys

import mock
from recommonmark.parser import CommonMarkParser
from recommonmark.states import DummyStateMachine
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.ext.autodoc import between

29

facebook-github-bot's avatar
facebook-github-bot committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Monkey patch to fix recommonmark 0.4 doc reference issues.
orig_run_role = DummyStateMachine.run_role


def run_role(self, name, options=None, content=None):
    if name == "doc":
        name = "any"
    return orig_run_role(self, name, options, content)


DummyStateMachine.run_role = run_role


StandaloneHTMLBuilder.supported_image_types = [
    "image/svg+xml",
    "image/gif",
    "image/png",
    "image/jpeg",
]

# -- Path setup --------------------------------------------------------------


sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath("../pytorch3d"))
sys.path.insert(0, os.path.abspath("../../"))

DEPLOY = os.environ.get("READTHEDOCS") == "True"
needs_sphinx = "1.7"


try:
    import torch  # noqa
except ImportError:
    for m in [
        "torch",
        "torchvision",
        "torch.nn",
        "torch.autograd",
        "torch.autograd.function",
        "torch.nn.modules",
        "torch.nn.modules.utils",
        "torch.utils",
        "torch.utils.data",
        "torchvision",
        "torchvision.ops",
    ]:
        sys.modules[m] = mock.Mock(name=m)

for m in ["cv2", "scipy", "numpy", "pytorch3d._C", "np.eye", "np.zeros"]:
    sys.modules[m] = mock.Mock(name=m)

# -- Project information -----------------------------------------------------

project = "PyTorch3D"
copyright = "2019, facebookresearch"
author = "facebookresearch"

Nikhila Ravi's avatar
Nikhila Ravi committed
88
# The short X.Y version
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
89
version = "0.2.0"
Nikhila Ravi's avatar
Nikhila Ravi committed
90

facebook-github-bot's avatar
facebook-github-bot committed
91
# The full version, including alpha/beta/rc tags
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
92
release = version
facebook-github-bot's avatar
facebook-github-bot committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

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

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.

extensions = [
    "sphinx_markdown_tables",
    "sphinx.ext.autodoc",
    "sphinx.ext.mathjax",
    "sphinx.ext.napoleon",
    "sphinx.ext.intersphinx",
    "sphinx.ext.todo",
    "sphinx.ext.coverage",
    "sphinx.ext.viewcode",
    "sphinx.ext.githubpages",
]

# -- Configurations for plugins ------------
napoleon_google_docstring = True
napoleon_include_init_with_doc = True
napoleon_include_special_with_doc = True
napoleon_numpy_docstring = False
# napoleon_use_param = False
napoleon_use_rtype = False
autodoc_inherit_docstrings = False
autodoc_member_order = "bysource"

source_parsers = {".md": CommonMarkParser}


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

# The master toctree document.
master_doc = "index"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "build", "README.md"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

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

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

# 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".
html_static_path = ["_static"]

html_theme_options = {"collapse_navigation": True}


def url_resolver(url):
    if ".html" not in url:
        url = url.replace("../", "")
162
        return "https://github.com/facebookresearch/pytorch3d/blob/master/" + url
facebook-github-bot's avatar
facebook-github-bot committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    else:
        if DEPLOY:
            return "http://pytorch3d.readthedocs.io/" + url
        else:
            return "/" + url


def setup(app):
    # Add symlink to root README
    if DEPLOY:
        import subprocess

        subprocess.call(["ln", "-s", "../README.md", "overview.md"])

    from recommonmark.transform import AutoStructify

    app.add_config_value(
        "recommonmark_config",
        {
            "url_resolver": url_resolver,
            "auto_toc_tree_section": "Contents",
            "enable_math": True,
            "enable_inline_math": True,
            "enable_eval_rst": True,
            "enable_auto_toc_tree": True,
        },
        True,
    )

    # Register a sphinx.ext.autodoc.between listener to ignore everything
    # between lines that contain the word IGNORE
194
    app.connect("autodoc-process-docstring", between("^.*IGNORE.*$", exclude=True))
facebook-github-bot's avatar
facebook-github-bot committed
195
196
197
    app.add_transform(AutoStructify)

    return app