Skip to content

Commit

Permalink
Include class summary in automodule docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Nov 17, 2023
1 parent 6139c28 commit ea06dbd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/_templates/module.rst_t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Summary
^^^^^^^
{#
TODO: Include these sections only if classes/functions exist in the current module.
The automodule directive currently doesn't pass enough info into the template context
to make this possible.
#}
.. rubric:: Classes
.. automodsumm:: {{ qualname }}
:classes-only:

.. rubric:: Functions
.. automodsumm:: {{ qualname }}
:functions-only:

Expand Down
16 changes: 16 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def setup(app):
* https://docs.readthedocs.io/en/stable/builds.html
* https://github.com/sphinx-contrib/apidoc
"""
app.connect('config-inited', patch_sphinx_jinja_extensions)
app.connect('builder-inited', document_models)
app.connect('builder-inited', setup_external_files)
app.connect('builder-inited', patch_automodapi)
Expand All @@ -211,6 +212,21 @@ def make_symlink(src, dest):
symlink(src, dest)


# TODO: Surely there's an easier way to do this?
def patch_sphinx_jinja_extensions(*args):
"""Monkey-patch Sphinx to enable Jinja extensions"""
from jinja2 import Environment
from sphinx.jinja2glue import SphinxFileSystemLoader

original_get_source = SphinxFileSystemLoader.get_source

def get_source(self, environment: Environment, template: str):
environment.add_extension('jinja2.ext.debug')
return original_get_source(self, environment, template)

SphinxFileSystemLoader.get_source = get_source


def patch_automodapi(app):
"""Monkey-patch the automodapi extension to exclude imported members.
Expand Down

0 comments on commit ea06dbd

Please sign in to comment.