From 944666fa0c7eab5c6e42eeeb78f02014d0e7a9f3 Mon Sep 17 00:00:00 2001
From: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Date: Thu, 11 Aug 2022 02:20:55 -0400
Subject: [PATCH] add autoapi (#19)

* add autoapi

* add sphinx.ext.autodoc to extension

* add extensions
---
 docs/conf.py          | 21 +++++++++++++++++++++
 docs/index.rst        |  1 +
 docs/requirements.txt |  3 ++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/docs/conf.py b/docs/conf.py
index e82aef1..ed11aca 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -7,5 +7,26 @@
 extensions = [
     'deepmodeling_sphinx',
     'myst_parser',
+    'sphinx.ext.autodoc',
+    'sphinx.ext.viewcode',
+    'sphinx.ext.intersphinx',
+    'numpydoc',
 ]
 html_theme = 'sphinx_rtd_theme'
+
+def run_apidoc(_):
+    from sphinx.ext.apidoc import main
+    import os
+    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, "..", "deepmodeling_sphinx")
+    main(['-M', '--tocfile', 'api_py', '-H', 'API', '-o', os.path.join(cur_dir, "api_py"), module, '--force'])
+
+def setup(app):
+    app.connect('builder-inited', run_apidoc)
+
+intersphinx_mapping = {
+    "python": ("https://docs.python.org/", None),
+    'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
+}
diff --git a/docs/index.rst b/docs/index.rst
index 5692efc..397e8fd 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -13,6 +13,7 @@ Others
 .. toctree::
    :titlesonly:
 
+   api_py/api_py
    credits
 
 ------------------
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 97f6750..022ae80 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -1,4 +1,5 @@
 sphinx_rtd_theme
 .
 myst_parser
-docutils >=0.17
\ No newline at end of file
+docutils >=0.17
+numpydoc
\ No newline at end of file