|
| 1 | +# Configuration file for the Sphinx documentation builder. |
| 2 | +# |
| 3 | +# For the full list of built-in configuration values, see the documentation: |
| 4 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 5 | +from bs4 import BeautifulSoup |
| 6 | +from typing import * |
| 7 | + |
| 8 | +# -- Project information ----------------------------------------------------- |
| 9 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information |
| 10 | + |
| 11 | +project = 'fastplotlib' |
| 12 | +copyright = '2022, Kushal Kolar, Caitlin Lewis' |
| 13 | +author = 'Kushal Kolar, Caitlin Lewis' |
| 14 | +release = 'v0.1.0.a6' |
| 15 | + |
| 16 | +# -- General configuration --------------------------------------------------- |
| 17 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration |
| 18 | + |
| 19 | +extensions = ["sphinx.ext.napoleon", "sphinx.ext.autodoc"] |
| 20 | +autodoc_typehints = "description" |
| 21 | + |
| 22 | +templates_path = ['_templates'] |
| 23 | +exclude_patterns = [] |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +# -- Options for HTML output ------------------------------------------------- |
| 28 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output |
| 29 | + |
| 30 | +html_theme = 'pydata_sphinx_theme' |
| 31 | +html_theme_options = {"page_sidebar_items": ["class_page_toc"]} |
| 32 | + |
| 33 | +html_static_path = ['_static'] |
| 34 | + |
| 35 | +autodoc_member_order = 'bysource' |
| 36 | +autoclass_content = "both" |
| 37 | + |
| 38 | +def _setup_navbar_side_toctree(app: Any): |
| 39 | + |
| 40 | + def add_class_toctree_function(app: Any, pagename: Any, templatename: Any, context: Any, doctree: Any): |
| 41 | + def get_class_toc() -> Any: |
| 42 | + soup = BeautifulSoup(context["body"], "html.parser") |
| 43 | + |
| 44 | + matches = soup.find_all('dl') |
| 45 | + if matches is None or len(matches) == 0: |
| 46 | + return "" |
| 47 | + items = [] |
| 48 | + deeper_depth = matches[0].find('dt').get('id').count(".") |
| 49 | + for match in matches: |
| 50 | + match_dt = match.find('dt') |
| 51 | + if match_dt is not None and match_dt.get('id') is not None: |
| 52 | + current_title = match_dt.get('id') |
| 53 | + current_depth = match_dt.get('id').count(".") |
| 54 | + current_link = match.find(class_="headerlink") |
| 55 | + if current_link is not None: |
| 56 | + if deeper_depth > current_depth: |
| 57 | + deeper_depth = current_depth |
| 58 | + if deeper_depth == current_depth: |
| 59 | + items.append({ |
| 60 | + "title": current_title.split('.')[-1], |
| 61 | + "link": current_link["href"], |
| 62 | + "attributes_and_methods": [] |
| 63 | + }) |
| 64 | + if deeper_depth < current_depth: |
| 65 | + items[-1]["attributes_and_methods"].append( |
| 66 | + { |
| 67 | + "title": current_title.split('.')[-1], |
| 68 | + "link": current_link["href"], |
| 69 | + } |
| 70 | + ) |
| 71 | + return items |
| 72 | + context["get_class_toc"] = get_class_toc |
| 73 | + |
| 74 | + app.connect("html-page-context", add_class_toctree_function) |
| 75 | + |
| 76 | + |
| 77 | +def setup(app: Any): |
| 78 | + for setup_function in [ |
| 79 | + _setup_navbar_side_toctree, |
| 80 | + ]: |
| 81 | + setup_function(app) |
0 commit comments