Skip to content

Commit

Permalink
Merge pull request #2965 from jessica-mitchell/update-api-ext
Browse files Browse the repository at this point in the history
Update extension for API extractor
  • Loading branch information
jessica-mitchell authored Oct 5, 2023
2 parents b88b099 + f0a967b commit d70a893
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
33 changes: 26 additions & 7 deletions doc/htmldoc/_ext/extract_api_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
import ast
import glob
import json
import os
import re

from sphinx.application import Sphinx

"""
Generate a JSON dictionary that stores the module name as key and corresponding
functions as values, along with the ``NestModule`` and the kernel attributes.
Expand Down Expand Up @@ -105,13 +106,31 @@ def process_directory(directory):
return api_dict


def ExtractPyNESTAPIS():
def get_pynest_list(app, env, docname):
directory = "../../pynest/nest/"
all_variables_dict = process_directory(directory)

with open("api_function_list.json", "w") as outfile:
json.dump(all_variables_dict, outfile, indent=4)
if not hasattr(env, "pynest_dict"):
env.pynest_dict = {}

env.pynest_dict = process_directory(directory)


def api_customizer(app, docname, source):
env = app.builder.env
if docname == "ref_material/pynest_api/index":
get_apis = env.pynest_dict
html_context = {"api_dict": get_apis}
api_source = source[0]
rendered = app.builder.templates.render_string(api_source, html_context)
source[0] = rendered


def setup(app):
app.connect("env-before-read-docs", get_pynest_list)
app.connect("source-read", api_customizer)

if __name__ == "__main__":
ExtractPyNESTAPIS()
return {
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
17 changes: 1 addition & 16 deletions doc/htmldoc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
extension_module_dir = os.path.abspath("./_ext")
sys.path.append(extension_module_dir)

from extract_api_functions import ExtractPyNESTAPIS # noqa
from extractor_userdocs import ExtractUserDocs, relative_glob # noqa

repo_root_dir = os.path.abspath("../..")
Expand All @@ -57,6 +56,7 @@
"add_button_notebook",
"IPython.sphinxext.ipython_console_highlighting",
"nbsphinx",
"extract_api_functions",
"sphinx_design",
"HoverXTooltip",
"VersionSyncRole",
Expand Down Expand Up @@ -214,19 +214,6 @@ def config_inited_handler(app, config):
)


def get_pynest_list(app, env, docname):
ExtractPyNESTAPIS()


def api_customizer(app, docname, source):
if docname == "ref_material/pynest_api/index":
list_apis = json.load(open("api_function_list.json"))
html_context = {"api_dict": list_apis}
api_source = source[0]
rendered = app.builder.templates.render_string(api_source, html_context)
source[0] = rendered


def toc_customizer(app, docname, source):
if docname == "models/models-toc":
models_toc = json.load(open("models/toc-tree.json"))
Expand All @@ -240,11 +227,9 @@ def setup(app):
# for events see
# https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events
app.connect("source-read", toc_customizer)
app.connect("source-read", api_customizer)
app.add_css_file("css/custom.css")
app.add_css_file("css/pygments.css")
app.add_js_file("js/custom.js")
app.connect("env-before-read-docs", get_pynest_list)
app.connect("config-inited", config_inited_handler)


Expand Down

0 comments on commit d70a893

Please sign in to comment.