summaryrefslogtreecommitdiff
path: root/sphinx/ext/autosummary/generate.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-08 20:19:36 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-08 20:19:36 +0900
commit326d7e64cedb5280a9cf51a90c00266e1dab9e7b (patch)
tree0ce4e7845e09aa822da027fbe6401174458c47d9 /sphinx/ext/autosummary/generate.py
parent7a194f52960fe5ace04ef7daa72563e6d3bf094f (diff)
parent3965b1f023bbac932d0dfbf414386f0667ec002a (diff)
downloadsphinx-git-326d7e64cedb5280a9cf51a90c00266e1dab9e7b.tar.gz
Merge branch 'master' into dont_emit_system_message_on_autodoc_warning
Diffstat (limited to 'sphinx/ext/autosummary/generate.py')
-rw-r--r--sphinx/ext/autosummary/generate.py54
1 files changed, 34 insertions, 20 deletions
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index f02c50692..aeffcb564 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -14,7 +14,7 @@
generate:
sphinx-autogen -o source/generated source/*.rst
- :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
@@ -33,24 +33,11 @@ from sphinx import __display_version__
from sphinx import package_dir
from sphinx.ext.autosummary import import_by_name, get_documenter
from sphinx.jinja2glue import BuiltinTemplateLoader
+from sphinx.registry import SphinxComponentRegistry
from sphinx.util.osutil import ensuredir
from sphinx.util.inspect import safe_getattr
from sphinx.util.rst import escape as rst_escape
-# Add documenters to AutoDirective registry
-from sphinx.ext.autodoc import add_documenter, \
- ModuleDocumenter, ClassDocumenter, ExceptionDocumenter, DataDocumenter, \
- FunctionDocumenter, MethodDocumenter, AttributeDocumenter, \
- InstanceAttributeDocumenter
-add_documenter(ModuleDocumenter)
-add_documenter(ClassDocumenter)
-add_documenter(ExceptionDocumenter)
-add_documenter(DataDocumenter)
-add_documenter(FunctionDocumenter)
-add_documenter(MethodDocumenter)
-add_documenter(AttributeDocumenter)
-add_documenter(InstanceAttributeDocumenter)
-
if False:
# For type annotation
from typing import Any, Callable, Dict, Tuple, List # NOQA
@@ -60,6 +47,30 @@ if False:
from sphinx.environment import BuildEnvironment # NOQA
+class DummyApplication(object):
+ """Dummy Application class for sphinx-autogen command."""
+
+ def __init__(self):
+ # type: () -> None
+ self.registry = SphinxComponentRegistry()
+
+
+def setup_documenters(app):
+ # type: (Any) -> None
+ from sphinx.ext.autodoc import (
+ ModuleDocumenter, ClassDocumenter, ExceptionDocumenter, DataDocumenter,
+ FunctionDocumenter, MethodDocumenter, AttributeDocumenter,
+ InstanceAttributeDocumenter
+ )
+ documenters = [
+ ModuleDocumenter, ClassDocumenter, ExceptionDocumenter, DataDocumenter,
+ FunctionDocumenter, MethodDocumenter, AttributeDocumenter,
+ InstanceAttributeDocumenter
+ ]
+ for documenter in documenters:
+ app.registry.add_documenter(documenter.objtype, documenter)
+
+
def _simple_info(msg):
# type: (unicode) -> None
print(msg)
@@ -81,8 +92,8 @@ def _underline(title, line='='):
def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
warn=_simple_warn, info=_simple_info,
base_path=None, builder=None, template_dir=None,
- imported_members=False):
- # type: (List[unicode], unicode, unicode, Callable, Callable, unicode, Builder, unicode, bool) -> None # NOQA
+ imported_members=False, app=None):
+ # type: (List[unicode], unicode, unicode, Callable, Callable, unicode, Builder, unicode, bool, Any) -> None # NOQA
showed_sources = list(sorted(sources))
if len(showed_sources) > 20:
@@ -148,7 +159,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
new_files.append(fn)
with open(fn, 'w') as f:
- doc = get_documenter(obj, parent)
+ doc = get_documenter(app, obj, parent)
if template_name is not None:
template = template_env.get_template(template_name)
@@ -167,7 +178,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
value = safe_getattr(obj, name)
except AttributeError:
continue
- documenter = get_documenter(value, obj)
+ documenter = get_documenter(app, value, obj)
if documenter.objtype == typ:
if typ == 'method':
items.append(name)
@@ -392,11 +403,14 @@ The format of the autosummary directive is documented in the
def main(argv=sys.argv[1:]):
# type: (List[str]) -> None
+ app = DummyApplication()
+ setup_documenters(app)
args = get_parser().parse_args(argv)
generate_autosummary_docs(args.source_file, args.output_dir,
'.' + args.suffix,
template_dir=args.templates,
- imported_members=args.imported_members)
+ imported_members=args.imported_members,
+ app=app)
if __name__ == '__main__':