Skip to content

Make automodsumm work with templates #47

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 25 additions & 9 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class members that are inherited from a base class. This value can be

from sphinx import __version__
from sphinx.ext.autosummary import Autosummary
from sphinx.ext.autosummary.generate import generate_autosummary_docs
from sphinx.ext.inheritance_diagram import InheritanceDiagram
from docutils.parsers.rst.directives import flag

Expand Down Expand Up @@ -241,15 +242,15 @@ def run(self):


# <---------------------automodsumm generation stuff-------------------------->
def process_automodsumm_generation(app):
env = app.builder.env

filestosearch = []
for docname in env.found_docs:
filename = env.doc2path(docname)
if os.path.isfile(filename):
filestosearch.append(docname + os.path.splitext(filename)[1])

def process_automodsumm_generation(app, filestosearch=None):
if not filestosearch:
env = app.builder.env

filestosearch = []
for docname in env.found_docs:
filename = env.doc2path(docname)
if os.path.isfile(filename):
filestosearch.append(docname + os.path.splitext(filename)[1])
liness = []
for sfn in filestosearch:
lines = automodsumm_to_autosummary_lines(sfn, app)
Expand Down Expand Up @@ -400,6 +401,10 @@ def automodsumm_to_autosummary_lines(fn, app):

return newlines

def _underline(title, line='='):
if '\n' in title:
raise ValueError('Can only underline single lines')
return title + '\n' + line * len(title)

def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst', warn=None,
info=None, base_path=None, builder=None,
Expand Down Expand Up @@ -445,6 +450,8 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst', warn=None,
template_loader = FileSystemLoader(template_dirs)
template_env = SandboxedEnvironment(loader=template_loader)

template_env.filters['underline'] = _underline

# read
# items = find_autosummary_in_files(sources)
items = find_autosummary_in_lines(lines, filename=srcfn)
Expand Down Expand Up @@ -641,9 +648,18 @@ def get_members_class(obj, typ, include_public=[],

rendered = template.render(**ns)
f.write(cleanup_whitespace(rendered))

finally:
f.close()

if new_files:
generate_autosummary_docs(new_files, output_dir=path,
suffix=suffix, warn=warn, info=info,
base_path=base_path, builder=builder,
template_dir=template_dir, app=app)

process_automodsumm_generation(app, filestosearch=new_files)


def setup(app):

Expand Down