mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7548 from tk0miya/refactor_autosummary4
refactor: AutosummaryRender
This commit is contained in:
commit
56ed2991fd
3
CHANGES
3
CHANGES
@ -14,6 +14,8 @@ Deprecated
|
|||||||
|
|
||||||
* The first argument for sphinx.ext.autosummary.generate.AutosummaryRenderer has
|
* The first argument for sphinx.ext.autosummary.generate.AutosummaryRenderer has
|
||||||
been changed to Sphinx object
|
been changed to Sphinx object
|
||||||
|
* ``sphinx.ext.autosummary.generate.AutosummaryRenderer`` takes an object type
|
||||||
|
as an argument
|
||||||
* The ``template_dir`` argument of ``sphinx.ext.autosummary.generate.
|
* The ``template_dir`` argument of ``sphinx.ext.autosummary.generate.
|
||||||
AutosummaryRenderer``
|
AutosummaryRenderer``
|
||||||
* The ``module`` argument of ``sphinx.ext.autosummary.generate.
|
* The ``module`` argument of ``sphinx.ext.autosummary.generate.
|
||||||
@ -22,6 +24,7 @@ Deprecated
|
|||||||
generate_autosummary_docs()``
|
generate_autosummary_docs()``
|
||||||
* The ``template_dir`` argument of ``sphinx.ext.autosummary.generate.
|
* The ``template_dir`` argument of ``sphinx.ext.autosummary.generate.
|
||||||
generate_autosummary_docs()``
|
generate_autosummary_docs()``
|
||||||
|
* ``sphinx.ext.autosummary.generate.AutosummaryRenderer.exists()``
|
||||||
|
|
||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
@ -33,6 +33,12 @@ The following is a list of deprecated interfaces.
|
|||||||
- 5.0
|
- 5.0
|
||||||
- N/A
|
- N/A
|
||||||
|
|
||||||
|
* - ``sphinx.ext.autosummary.generate.AutosummaryRenderer`` takes an object
|
||||||
|
type as an argument
|
||||||
|
- 3.1
|
||||||
|
- 5.0
|
||||||
|
- N/A
|
||||||
|
|
||||||
* - The ``template_dir`` argument of
|
* - The ``template_dir`` argument of
|
||||||
``sphinx.ext.autosummary.generate.AutosummaryRenderer``
|
``sphinx.ext.autosummary.generate.AutosummaryRenderer``
|
||||||
- 3.1
|
- 3.1
|
||||||
@ -57,6 +63,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- 5.0
|
- 5.0
|
||||||
- N/A
|
- N/A
|
||||||
|
|
||||||
|
* - ``sphinx.ext.autosummary.generate.AutosummaryRenderer.exists()``
|
||||||
|
- 3.1
|
||||||
|
- 5.0
|
||||||
|
- N/A
|
||||||
|
|
||||||
* - ``desc_signature['first']``
|
* - ``desc_signature['first']``
|
||||||
-
|
-
|
||||||
- 3.0
|
- 3.0
|
||||||
|
@ -147,15 +147,30 @@ class AutosummaryRenderer:
|
|||||||
|
|
||||||
def exists(self, template_name: str) -> bool:
|
def exists(self, template_name: str) -> bool:
|
||||||
"""Check if template file exists."""
|
"""Check if template file exists."""
|
||||||
|
warnings.warn('AutosummaryRenderer.exists() is deprecated.',
|
||||||
|
RemovedInSphinx50Warning, stacklevel=2)
|
||||||
try:
|
try:
|
||||||
self.env.get_template(template_name)
|
self.env.get_template(template_name)
|
||||||
return True
|
return True
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def render(self, template_name: str, context: Dict) -> str:
|
def render(self, objtype: str, context: Dict) -> str:
|
||||||
"""Render a template file."""
|
"""Render a template file."""
|
||||||
return self.env.get_template(template_name).render(context)
|
if objtype.endswith('.rst'):
|
||||||
|
# old styled: template_name is given
|
||||||
|
warnings.warn('AutosummaryRenderer.render() takes an object type as an argument.',
|
||||||
|
RemovedInSphinx50Warning, stacklevel=2)
|
||||||
|
return self.env.get_template(objtype).render(context)
|
||||||
|
else:
|
||||||
|
# objtype is given
|
||||||
|
try:
|
||||||
|
template = self.env.get_template('autosummary/%s.rst' % objtype)
|
||||||
|
except TemplateNotFound:
|
||||||
|
# fallback to base.rst
|
||||||
|
template = self.env.get_template('autosummary/base.rst')
|
||||||
|
|
||||||
|
return template.render(context)
|
||||||
|
|
||||||
|
|
||||||
# -- Generating output ---------------------------------------------------------
|
# -- Generating output ---------------------------------------------------------
|
||||||
@ -167,11 +182,6 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
|
|||||||
recursive: bool) -> str:
|
recursive: bool) -> str:
|
||||||
doc = get_documenter(app, obj, parent)
|
doc = get_documenter(app, obj, parent)
|
||||||
|
|
||||||
if template_name is None:
|
|
||||||
template_name = 'autosummary/%s.rst' % doc.objtype
|
|
||||||
if not template.exists(template_name):
|
|
||||||
template_name = 'autosummary/base.rst'
|
|
||||||
|
|
||||||
def skip_member(obj: Any, name: str, objtype: str) -> bool:
|
def skip_member(obj: Any, name: str, objtype: str) -> bool:
|
||||||
try:
|
try:
|
||||||
return app.emit_firstresult('autodoc-skip-member', objtype, name,
|
return app.emit_firstresult('autodoc-skip-member', objtype, name,
|
||||||
@ -256,7 +266,7 @@ 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(template_name, ns)
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user