a b/docs/source/conf.py
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#
4
# ANTsPy documentation build configuration file, created by
5
# sphinx-quickstart on Fri Dec 23 13:31:47 2016.
6
#
7
# This file is execfile()d with the current directory set to its
8
# containing dir.
9
#
10
# Note that not all possible configuration values are present in this
11
# autogenerated file.
12
#
13
# All configuration values have a default; values that are commented out
14
# serve to show the default.
15
16
# If extensions (or modules to document with autodoc) are in another directory,
17
# add these directories to sys.path here. If the directory is relative to the
18
# documentation root, use os.path.abspath to make it absolute, like shown here.
19
#
20
21
import os
22
import sys
23
import shutil
24
25
on_rtd = os.environ.get('READTHEDOCS') == 'True'
26
27
    # add package to local path
28
sys.path.insert(0, os.path.abspath('../../'))
29
autodoc_mock_imports = ['_tkinter', 'matplotlib']
30
if on_rtd:
31
    # replace lib __init__ with empty init file since RTD cant handle C++ extensions
32
    os.makedirs('../../ants/lib', exist_ok=True)
33
    shutil.copyfile('emptyinit.py', '../../ants/lib/__init__.py')
34
35
import ants
36
import numpy as np
37
import sphinx_rtd_theme
38
39
40
# -- General configuration ------------------------------------------------
41
42
# If your documentation needs a minimal Sphinx version, state it here.
43
#
44
# needs_sphinx = '1.0'
45
46
# Add any Sphinx extension module names here, as strings. They can be
47
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
48
# ones.
49
extensions = [
50
    'sphinx.ext.autodoc',
51
    'sphinx.ext.autosummary',
52
    'sphinx.ext.doctest',
53
    'sphinx.ext.intersphinx',
54
    'sphinx.ext.todo',
55
    'sphinx.ext.coverage',
56
    'sphinx.ext.mathjax',
57
    'sphinx.ext.napoleon',
58
    'sphinx.ext.viewcode',
59
]
60
61
napoleon_use_ivar = True
62
63
# Add any paths that contain templates here, relative to this directory.
64
templates_path = ['_templates']
65
66
# The suffix(es) of source filenames.
67
# You can specify multiple suffix as a list of string:
68
#
69
# source_suffix = ['.rst', '.md']
70
source_suffix = '.rst'
71
72
# The master toctree document.
73
master_doc = 'index'
74
75
# General information about the project.
76
project = 'ANTsPy'
77
copyright = '2017-2024, ANTs Contributors'
78
author = 'ANTs Contributors'
79
80
# The version info for the project you're documenting, acts as replacement for
81
# |version| and |release|, also used in various other places throughout the
82
# built documents.
83
#
84
# Default values for local builds
85
version = 'local'
86
release = 'local'
87
88
# Determine if we are on Read the Docs
89
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
90
91
if on_rtd:
92
    rtd_version = os.environ.get('READTHEDOCS_VERSION', 'local')
93
    rtd_version_type = os.environ.get('READTHEDOCS_VERSION_TYPE', 'branch')
94
95
    if rtd_version_type == 'tag':
96
        version = rtd_version.lstrip('v')
97
        release = f'release {version}'
98
    elif rtd_version_type == 'branch' and rtd_version == 'latest':
99
        version = 'dev'
100
        release = f'dev ({rtd_version})'
101
    else:
102
        version = rtd_version
103
        release = rtd_version
104
105
# The language for content autogenerated by Sphinx. Refer to documentation
106
# for a list of supported languages.
107
#
108
# This is also used if you do content translation via gettext catalogs.
109
# Usually you set "language" from the command line for these cases.
110
language = None
111
112
# List of patterns, relative to source directory, that match files and
113
# directories to ignore when looking for source files.
114
# This patterns also effect to html_static_path and html_extra_path
115
exclude_patterns = []
116
117
# The name of the Pygments (syntax highlighting) style to use.
118
pygments_style = 'sphinx'
119
120
# If true, `todo` and `todoList` produce output, else they produce nothing.
121
todo_include_todos = True
122
123
124
# -- Options for HTML output ----------------------------------------------
125
126
# The theme to use for HTML and HTML Help pages.  See the documentation for
127
# a list of builtin themes.
128
#
129
html_theme = 'alabaster'
130
#html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
131
132
# Theme options are theme-specific and customize the look and feel of a theme
133
# further.  For a list of options available for each theme, see the
134
# documentation.
135
#
136
#html_theme_options = {
137
#    'collapse_navigation': False,
138
#    'display_version': True,
139
#    'logo_only': True,
140
#}
141
142
html_logo = '_static/img/antspy-logo.png'
143
144
# Add any paths that contain custom static files (such as style sheets) here,
145
# relative to this directory. They are copied after the builtin static files,
146
# so a file named "default.css" will overwrite the builtin "default.css".
147
html_static_path = ['_static']
148
149
#html_style_path = '_static/css/ants_theme.css'
150
#html_context = {
151
#    'css_files': [
152
#        'https://fonts.googleapis.com/css?family=Lato',
153
#        '_static/css/ants_theme.css'
154
#    ],
155
#}
156
157
158
# -- Options for HTMLHelp output ------------------------------------------
159
160
# Output file base name for HTML help builder.
161
htmlhelp_basename = 'ANTsPydoc'
162
163
164
# -- Options for LaTeX output ---------------------------------------------
165
166
167
168
# -- Options for manual page output ---------------------------------------
169
170
# One entry per manual page. List of tuples
171
# (source start file, name, description, authors, manual section).
172
man_pages = [
173
    (master_doc, 'ANTsPy', 'ANTsPy Documentation',
174
     [author], 1)
175
]
176
177
178
# -- Options for Texinfo output -------------------------------------------
179
180
# Grouping the document tree into Texinfo files. List of tuples
181
# (source start file, target name, title, author,
182
#  dir menu entry, description, category)
183
texinfo_documents = [
184
    (master_doc, 'ANTsPy', 'ANTsPy Documentation',
185
     author, 'ANTsPy', 'One line description of project.',
186
     'Miscellaneous'),
187
]
188
189
190
# Example configuration for intersphinx: refer to the Python standard library.
191
intersphinx_mapping = {
192
    'python': ('https://docs.python.org/', None),
193
    'numpy': ('http://docs.scipy.org/doc/numpy/', None),
194
}
195
196
# -- A patch that prevents Sphinx from cross-referencing ivar tags -------
197
# See http://stackoverflow.com/a/41184353/3343043
198
199
from docutils import nodes
200
from sphinx.util.docfields import TypedField
201
from sphinx import addnodes
202
203
204
def patched_make_field(self, types, domain, items, **kw):
205
    # `kw` catches `env=None` needed for newer sphinx while maingaining
206
    #  backwards compatibility when passed along further down!
207
208
    # type: (List, unicode, Tuple) -> nodes.field
209
    def handle_item(fieldarg, content):
210
        par = nodes.paragraph()
211
        par += addnodes.literal_strong('', fieldarg)  # Patch: this line added
212
        # par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
213
        #                           addnodes.literal_strong))
214
        if fieldarg in types:
215
            par += nodes.Text(' (')
216
            # NOTE: using .pop() here to prevent a single type node to be
217
            # inserted twice into the doctree, which leads to
218
            # inconsistencies later when references are resolved
219
            fieldtype = types.pop(fieldarg)
220
            if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
221
                typename = u''.join(n.astext() for n in fieldtype)
222
                typename = typename.replace('int', 'python:int')
223
                typename = typename.replace('long', 'python:long')
224
                typename = typename.replace('float', 'python:float')
225
                typename = typename.replace('type', 'python:type')
226
                par.extend(self.make_xrefs(self.typerolename, domain, typename,
227
                                           addnodes.literal_emphasis, **kw))
228
            else:
229
                par += fieldtype
230
            par += nodes.Text(')')
231
        par += nodes.Text(' -- ')
232
        par += content
233
        return par
234
235
    fieldname = nodes.field_name('', self.label)
236
    if len(items) == 1 and self.can_collapse:
237
        fieldarg, content = items[0]
238
        bodynode = handle_item(fieldarg, content)
239
    else:
240
        bodynode = self.list_type()
241
        for fieldarg, content in items:
242
            bodynode += nodes.list_item('', handle_item(fieldarg, content))
243
    fieldbody = nodes.field_body('', bodynode)
244
    return nodes.field('', fieldname, fieldbody)
245
246
TypedField.make_field = patched_make_field
247