Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update extension for API extractor #2965

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading