summaryrefslogtreecommitdiff
path: root/sphinx/ext/autosummary/__init__.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-21 23:04:38 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-21 23:04:38 +0900
commitb9da9237bc04e6d8da46045b18780d853c7581ef (patch)
tree143a7cbe4a2638281b11922f428516e9ef27ab8f /sphinx/ext/autosummary/__init__.py
parent476b73b6ca6dd3e64a557495e3f8137e702f77dd (diff)
parent44da84c910cfd84996e17e8d3f5c9e7d170c3462 (diff)
downloadsphinx-git-b9da9237bc04e6d8da46045b18780d853c7581ef.tar.gz
Merge branch '3.x' into 6040_autosummary_recursive
Diffstat (limited to 'sphinx/ext/autosummary/__init__.py')
-rw-r--r--sphinx/ext/autosummary/__init__.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 72eb5afcf..c9427d8ce 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -48,7 +48,7 @@
resolved to a Python object, and otherwise it becomes simple emphasis.
This can be used as the default role to make links 'smart'.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -60,7 +60,7 @@ import sys
import warnings
from os import path
from types import ModuleType
-from typing import Any, Dict, List, Tuple, Type
+from typing import Any, Dict, List, Tuple
from typing import cast
from docutils import nodes
@@ -72,22 +72,26 @@ from docutils.statemachine import StringList
import sphinx
from sphinx import addnodes
from sphinx.application import Sphinx
-from sphinx.deprecation import RemovedInSphinx40Warning
+from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning
from sphinx.environment import BuildEnvironment
from sphinx.environment.adapters.toctree import TocTree
-from sphinx.ext.autodoc import Documenter, get_documenters
+from sphinx.ext.autodoc import Documenter
from sphinx.ext.autodoc.directive import DocumenterBridge, Options
from sphinx.ext.autodoc.importer import import_module
from sphinx.ext.autodoc.mock import mock
from sphinx.locale import __
from sphinx.pycode import ModuleAnalyzer, PycodeError
-from sphinx.util import import_object, rst, logging
+from sphinx.util import rst, logging
from sphinx.util.docutils import (
NullReporter, SphinxDirective, SphinxRole, new_document, switch_source_input
)
from sphinx.util.matching import Matcher
from sphinx.writers.html import HTMLTranslator
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
logger = logging.getLogger(__name__)
@@ -106,6 +110,8 @@ def process_autosummary_toc(app: Sphinx, doctree: nodes.document) -> None:
"""Insert items described in autosummary:: to the TOC tree, but do
not generate the toctree:: list.
"""
+ warnings.warn('process_autosummary_toc() is deprecated',
+ RemovedInSphinx50Warning, stacklevel=2)
env = app.builder.env
crawled = {}
@@ -173,7 +179,7 @@ class FakeDirective(DocumenterBridge):
super().__init__({}, None, Options(), 0, state) # type: ignore
-def get_documenter(app: Sphinx, obj: Any, parent: Any) -> Type[Documenter]:
+def get_documenter(app: Sphinx, obj: Any, parent: Any) -> "Type[Documenter]":
"""Get an autodoc.Documenter class suitable for documenting the given
object.
@@ -199,7 +205,7 @@ def get_documenter(app: Sphinx, obj: Any, parent: Any) -> Type[Documenter]:
parent_doc = parent_doc_cls(FakeDirective(), "")
# Get the corrent documenter class for *obj*
- classes = [cls for cls in get_documenters(app).values()
+ classes = [cls for cls in app.registry.documenters.values()
if cls.can_document_member(obj, '', False, parent_doc)]
if classes:
classes.sort(key=lambda cls: cls.priority)
@@ -222,6 +228,7 @@ class Autosummary(SphinxDirective):
final_argument_whitespace = False
has_content = True
option_spec = {
+ 'caption': directives.unchanged_required,
'toctree': directives.unchanged,
'nosignatures': directives.flag,
'recursive': directives.flag,
@@ -265,9 +272,14 @@ class Autosummary(SphinxDirective):
tocnode['entries'] = [(None, docn) for docn in docnames]
tocnode['maxdepth'] = -1
tocnode['glob'] = None
+ tocnode['caption'] = self.options.get('caption')
nodes.append(autosummary_toc('', '', tocnode))
+ if 'toctree' not in self.options and 'caption' in self.options:
+ logger.warning(__('A captioned autosummary requires :toctree: option. ignored.'),
+ location=nodes[-1])
+
return nodes
def get_items(self, names: List[str]) -> List[Tuple[str, str, str, str]]:
@@ -698,8 +710,6 @@ def get_rst_suffix(app: Sphinx) -> str:
parser_class = app.registry.get_source_parsers().get(suffix)
if parser_class is None:
return ('restructuredtext',)
- if isinstance(parser_class, str):
- parser_class = import_object(parser_class, 'source parser')
return parser_class.supported
suffix = None # type: str
@@ -717,9 +727,11 @@ def process_generate_options(app: Sphinx) -> None:
env = app.builder.env
genfiles = [env.doc2path(x, base=None) for x in env.found_docs
if os.path.isfile(env.doc2path(x))]
+ elif genfiles is False:
+ pass
else:
ext = list(app.config.source_suffix)
- genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
+ genfiles = [genfile + (ext[0] if not genfile.endswith(tuple(ext)) else '')
for genfile in genfiles]
for entry in genfiles[:]:
@@ -764,7 +776,6 @@ def setup(app: Sphinx) -> Dict[str, Any]:
texinfo=(autosummary_noop, autosummary_noop))
app.add_directive('autosummary', Autosummary)
app.add_role('autolink', AutoLink())
- app.connect('doctree-read', process_autosummary_toc)
app.connect('builder-inited', process_generate_options)
app.add_config_value('autosummary_generate', [], True, [bool])
app.add_config_value('autosummary_generate_overwrite', True, False)