conf.py 8.61 KB
Newer Older
zhangqha's avatar
zhangqha committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
88
89
90
91
92
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
162
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# 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

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

# 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 subprocess
import sys
import recommonmark
from recommonmark.transform import AutoStructify
from datetime import date
from deepmd.common import ACTIVATION_FN_DICT, PRECISION_DICT
from deepmd.utils.argcheck import list_to_doc

sys.path.append(os.path.dirname(__file__))
import sphinx_contrib_exhale_multiproject as _

def mkindex(dirname):
    dirname = dirname + "/"
    oldfindex = open(dirname + "index.md", "r")
    oldlist = oldfindex.readlines()
    oldfindex.close()

    oldnames = []
    for entry in oldlist:
        _name = entry[entry.find("(")+1 : entry.find(")")]
        oldnames.append(_name)
    
    newfindex = open(dirname + "index.md", "a")
    for root, dirs, files in os.walk(dirname, topdown=False):
        newnames = [name for name in files if "index.md" not in name and name not in oldnames]
        for name in newnames:
            f = open(dirname + name, "r")
            _lines = f.readlines()
            for _headline in _lines:
                _headline = _headline.strip("#")
                headline = _headline.strip()
                if (len(headline) == 0 or headline[0] == "." or headline[0] == "="):
                    continue
                else:
                    break
            longname = "- ["+headline+"]"+"("+name+")\n"
            newfindex.write(longname)

    
    newfindex.close()

def classify_index_TS():
    dirname = "troubleshooting/"
    oldfindex = open(dirname + "index.md", "r")
    oldlist = oldfindex.readlines()
    oldfindex.close()

    oldnames = []
    sub_titles = []
    heads = []
    while(len(oldlist) > 0):
        entry = oldlist.pop(0)
        if (entry.find("(") >= 0):
            _name = entry[entry.find("(")+1 : entry.find(")")]
            oldnames.append(_name)
            continue
        if (entry.find("##") >= 0):
            _name = entry[entry.find("##")+3:-1]
            sub_titles.append(_name)
            continue
        entry.strip()
        if (entry != '\n'):
            heads.append(entry)
    
    newfindex = open(dirname + "index.md", "w")
    for entry in heads:
        newfindex.write(entry)
    newfindex.write('\n')
    sub_lists = [[],[]]
    for root, dirs, files in os.walk(dirname, topdown=False):
        newnames = [name for name in files if "index.md" not in name]
        for name in newnames:
            f = open(dirname + name, "r")
            _lines = f.readlines()
            f.close()
            for _headline in _lines:
                _headline = _headline.strip("#")
                headline = _headline.strip()
                if (len(headline) == 0 or headline[0] == "." or headline[0] == "="):
                    continue
                else:
                    break
            longname = "- ["+headline+"]"+"("+name+")\n"
            if ("howtoset_" in name):
                sub_lists[1].append(longname)
            else:
                sub_lists[0].append(longname)
    
    newfindex.write("## Trouble shooting\n")
    for entry in sub_lists[0]:
        newfindex.write(entry)
    newfindex.write("\n")
    newfindex.write("## Parameters setting\n")
    for entry in sub_lists[1]:
        newfindex.write(entry)
    newfindex.close()


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

project = 'DeePMD-kit'
copyright = '2017-%d, DeepModeling' % date.today().year
author = 'DeepModeling'

def run_apidoc(_):
    from sphinx.ext.apidoc import main
    import sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    module = os.path.join(cur_dir,"..","deepmd")
    main(['-M', '--tocfile', 'api_py', '-H', 'Python API', '-o', os.path.join(cur_dir, "api_py"), module, '--force'])

def setup(app):

    # Add hook for building doxygen xml when needed
    app.connect('builder-inited', run_apidoc)

# -- 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 = [
#     'recommonmark',
#     "sphinx_rtd_theme",
#     'myst_parser',
#     'sphinx_markdown_tables',
#     'sphinx.ext.autosummary'
# ]

#mkindex("troubleshooting")
#mkindex("development")
#classify_index_TS()

extensions = [
    "deepmodeling_sphinx",
    "dargs.sphinx",
    "sphinx_rtd_theme",
    'myst_parser',
    'sphinx.ext.autosummary',
    'sphinx.ext.mathjax',
    'sphinx.ext.viewcode',
    'sphinx.ext.intersphinx',
    'sphinx.ext.napoleon',
    'sphinxarg.ext',
    'numpydoc',
    'breathe',
    'exhale'
]

# breathe_domain_by_extension = {
#         "h" : "cpp",
# }
breathe_projects = {
    "cc": "_build/cc/xml/",
    "core": "_build/core/xml/",
}
breathe_default_project = "cc"

exhale_args = {
    "doxygenStripFromPath":  "..",
    # Suggested optional arguments
    # "createTreeView":        True,
    # TIP: if using the sphinx-bootstrap-theme, you need
    # "treeViewIsBootstrap": True,
    "exhaleExecutesDoxygen": True,
    # "unabridgedOrphanKinds": {"namespace"}
    # "listingExclude": [r"namespace_*"]
}
exhale_projects_args = {
    "cc": {
        "containmentFolder": "./API_CC",
        "exhaleDoxygenStdin": "INPUT = ../source/api_cc/include/",
        "rootFileTitle": "C++ API",
        "rootFileName": "api_cc.rst",
    },
    "core": {
        "containmentFolder": "./api_core",
        "exhaleDoxygenStdin": """INPUT = ../source/lib/include/
                                 PREDEFINED = GOOGLE_CUDA
                                              TENSORFLOW_USE_ROCM
        """,
        "rootFileTitle": "Core API",
        "rootFileName": "api_core.rst",
    },
}

# Tell sphinx what the primary language being documented is.
#primary_domain = 'cpp'

# Tell sphinx what the pygments highlight language should be.
#highlight_language = 'cpp'

# 
myst_heading_anchors = 4

# 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']

intersphinx_mapping = {
    "numpy": ("https://docs.scipy.org/doc/numpy/", None),
    "python": ("https://docs.python.org/", None),
    "tensorflow": (
        "https://www.tensorflow.org/api_docs/python",
        "https://github.com/mr-ubik/tensorflow-intersphinx/raw/master/tf2_py_objects.inv",
    ), 
    "ase": ("https://wiki.fysik.dtu.dk/ase/", None),
}
numpydoc_xref_param_type = True


numpydoc_xref_aliases = {}
import typing
for typing_type in typing.__all__:
    numpydoc_xref_aliases[typing_type] = "typing.%s" % typing_type

rst_epilog = """
.. |ACTIVATION_FN| replace:: %s
.. |PRECISION| replace:: %s
""" % (list_to_doc(ACTIVATION_FN_DICT.keys()), list_to_doc(PRECISION_DICT.keys()))

# -- 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_css_files = ['css/custom.css']

autodoc_default_flags = ['members']
autosummary_generate = True
master_doc = 'index'
mathjax_path = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.min.js'
myst_enable_extensions = [
    'dollarmath',
    'colon_fence',
]
# fix emoji issue in pdf
latex_engine = "xelatex"
latex_elements = {
    'fontpkg': r'''
\usepackage{fontspec}
\setmainfont{Symbola}
''',
}

# For TF automatic generated OP docs
napoleon_google_docstring = True
napoleon_numpy_docstring = False