Skip to content

Commit ab7621e

Browse files
tuopingtuopingnjzjz
authored
Doc api cc (#663)
* Doxyfile cannot be installed from pip, therefore I precompiled with doxyfile to generated xml/ from C++. And then api_cc.rst can be generated by breathe from xml/. * Edit conf.py to include doxygen * Edit conf.py to enable doxygen on readthedocs * Add specification in conf.py to refine the html layout of api_cc.rst * Included exhale to make prettier C++ API. * Update conf.py * add a function description to see if it works * it should be put into the header file? * add documents for DeepPot and DeepTensor * add documents for some common functions Co-authored-by: tuoping <[email protected]> Co-authored-by: Jinzhe Zeng <[email protected]>
1 parent 57b50cc commit ab7621e

File tree

10 files changed

+3024
-5
lines changed

10 files changed

+3024
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ venv*
2626
.vscode/**
2727
_build
2828
_templates
29+
API_CC

doc/Doxyfile

Lines changed: 2662 additions & 0 deletions
Large diffs are not rendered by default.

doc/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To run the HTML documention build, doxygen have to be installed.

doc/development/api.rst renamed to doc/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
API
2-
===
1+
Python API
2+
==========
33

44
.. toctree::
55
:maxdepth: 2

doc/conf.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
1313
import os
14+
import subprocess
1415
# import sys
1516
import recommonmark
1617
from recommonmark.transform import AutoStructify
@@ -108,6 +109,31 @@ def classify_index_TS():
108109
copyright = '2020, Deep Potential'
109110
author = 'Deep Potential'
110111

112+
def run_doxygen(folder):
113+
"""Run the doxygen make command in the designated folder"""
114+
115+
try:
116+
retcode = subprocess.call("cd %s; doxygen Doxyfile" % folder, shell=True)
117+
if retcode < 0:
118+
sys.stderr.write("doxygen terminated by signal %s" % (-retcode))
119+
except OSError as e:
120+
sys.stderr.write("doxygen execution failed: %s" % e)
121+
122+
123+
def generate_doxygen_xml(app):
124+
"""Run the doxygen make commands if we're on the ReadTheDocs server"""
125+
126+
read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
127+
128+
if read_the_docs_build:
129+
run_doxygen("./")
130+
else:
131+
subprocess.call("doxygen Doxyfile", shell=True)
132+
133+
def setup(app):
134+
135+
# Add hook for building doxygen xml when needed
136+
app.connect("builder-inited", generate_doxygen_xml)
111137

112138
# -- General configuration ---------------------------------------------------
113139

@@ -129,9 +155,39 @@ def classify_index_TS():
129155
extensions = [
130156
"sphinx_rtd_theme",
131157
'myst_parser',
132-
'sphinx.ext.autosummary'
158+
'sphinx.ext.autosummary',
159+
'breathe',
160+
'exhale'
133161
]
134162

163+
# breathe_domain_by_extension = {
164+
# "h" : "cpp",
165+
# }
166+
breathe_projects = {"myproject": "_build/xml/"}
167+
breathe_default_project = "myproject"
168+
169+
exhale_args = {
170+
"containmentFolder": "./API_CC",
171+
"rootFileName": "api_cc.rst",
172+
"rootFileTitle": "C++ API",
173+
"doxygenStripFromPath": "..",
174+
# Suggested optional arguments
175+
# "createTreeView": True,
176+
# TIP: if using the sphinx-bootstrap-theme, you need
177+
# "treeViewIsBootstrap": True,
178+
"exhaleExecutesDoxygen": True,
179+
"exhaleDoxygenStdin": "INPUT = ../source/api_cc/include/",
180+
# "unabridgedOrphanKinds": {"namespace"}
181+
# "listingExclude": [r"namespace_*"]
182+
}
183+
184+
# Tell sphinx what the primary language being documented is.
185+
primary_domain = 'cpp'
186+
187+
# Tell sphinx what the pygments highlight language should be.
188+
highlight_language = 'cpp'
189+
190+
#
135191
myst_heading_anchors = 4
136192

137193
# Add any paths that contain templates here, relative to this directory.

doc/development/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Developer Guide
22

3-
- [API](api.rst)
3+
- [Python API](../api.rst)
4+
- [C++ API](../API_CC/api_cc.rst)
45
- [Coding Conventions](coding-conventions.rst)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
cmake_minimum_required_version="3.0",
108108
extras_require={
109109
"test": ["dpdata>=0.1.9", "ase", "pytest", "pytest-cov", "pytest-sugar"],
110-
"docs": ["sphinx", "recommonmark", "sphinx_rtd_theme", "sphinx_markdown_tables", "myst-parser"],
110+
"docs": ["sphinx", "recommonmark", "sphinx_rtd_theme", "sphinx_markdown_tables", "myst-parser", "breathe", "exhale"],
111111
**extras_require,
112112
},
113113
entry_points={"console_scripts": ["dp = deepmd.entrypoints.main:main"]},

0 commit comments

Comments
 (0)