mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7578 from tk0miya/7570_autosummary_template_option
Fix #7570: autosummary: template option is broken
This commit is contained in:
commit
ca082f6893
@ -156,22 +156,19 @@ class AutosummaryRenderer:
|
|||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def render(self, objtype: str, context: Dict) -> str:
|
def render(self, template_name: str, context: Dict) -> str:
|
||||||
"""Render a template file."""
|
"""Render a template file."""
|
||||||
if objtype.endswith('.rst'):
|
if template_name.endswith('.rst'):
|
||||||
# old styled: template_name is given
|
template = self.env.get_template(template_name)
|
||||||
warnings.warn('AutosummaryRenderer.render() takes an object type as an argument.',
|
|
||||||
RemovedInSphinx50Warning, stacklevel=2)
|
|
||||||
return self.env.get_template(objtype).render(context)
|
|
||||||
else:
|
else:
|
||||||
# objtype is given
|
# objtype is given as template_name
|
||||||
try:
|
try:
|
||||||
template = self.env.get_template('autosummary/%s.rst' % objtype)
|
template = self.env.get_template('autosummary/%s.rst' % template_name)
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
# fallback to base.rst
|
# fallback to base.rst
|
||||||
template = self.env.get_template('autosummary/base.rst')
|
template = self.env.get_template('autosummary/base.rst')
|
||||||
|
|
||||||
return template.render(context)
|
return template.render(context)
|
||||||
|
|
||||||
|
|
||||||
# -- Generating output ---------------------------------------------------------
|
# -- Generating output ---------------------------------------------------------
|
||||||
@ -268,7 +265,10 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
|
|||||||
ns['objtype'] = doc.objtype
|
ns['objtype'] = doc.objtype
|
||||||
ns['underline'] = len(name) * '='
|
ns['underline'] = len(name) * '='
|
||||||
|
|
||||||
return template.render(doc.objtype, ns)
|
if template_name:
|
||||||
|
return template.render(template_name, ns)
|
||||||
|
else:
|
||||||
|
return template.render(doc.objtype, ns)
|
||||||
|
|
||||||
|
|
||||||
def generate_autosummary_docs(sources: List[str], output_dir: str = None,
|
def generate_autosummary_docs(sources: List[str], output_dir: str = None,
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
EMPTY
|
10
tests/roots/test-ext-autosummary-template/conf.py
Normal file
10
tests/roots/test-ext-autosummary-template/conf.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath('.'))
|
||||||
|
|
||||||
|
|
||||||
|
extensions = ['sphinx.ext.autosummary']
|
||||||
|
autosummary_generate = True
|
||||||
|
autodoc_default_options = {'members': True}
|
||||||
|
templates_path = ['_templates']
|
5
tests/roots/test-ext-autosummary-template/index.rst
Normal file
5
tests/roots/test-ext-autosummary-template/index.rst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.. autosummary::
|
||||||
|
:toctree: generate
|
||||||
|
:template: empty.rst
|
||||||
|
|
||||||
|
target.Foo
|
2
tests/roots/test-ext-autosummary-template/target.py
Normal file
2
tests/roots/test-ext-autosummary-template/target.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class Foo:
|
||||||
|
"""docstring of Foo."""
|
@ -378,6 +378,14 @@ def test_autosummary_skip_member(app):
|
|||||||
assert 'Foo._privatemeth' in content
|
assert 'Foo._privatemeth' in content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx(testroot='ext-autosummary-template')
|
||||||
|
def test_autosummary_template(app):
|
||||||
|
app.build()
|
||||||
|
|
||||||
|
content = (app.srcdir / 'generate' / 'target.Foo.rst').read_text()
|
||||||
|
assert 'EMPTY' in content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
|
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
|
||||||
confoverrides={'autosummary_generate': []})
|
confoverrides={'autosummary_generate': []})
|
||||||
def test_empty_autosummary_generate(app, status, warning):
|
def test_empty_autosummary_generate(app, status, warning):
|
||||||
|
Loading…
Reference in New Issue
Block a user