2016-11-02 23:29:28 +00:00
|
|
|
"""AutoAPI directives"""
|
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
from docutils.parsers.rst import Directive
|
2016-11-02 23:29:28 +00:00
|
|
|
from docutils import nodes
|
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
from sphinx.ext.autosummary import Autosummary
|
2016-11-02 23:29:28 +00:00
|
|
|
from sphinx.util.nodes import nested_parse_with_titles
|
2017-08-31 23:42:47 +00:00
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
from .mappers.python.objects import PythonFunction
|
2017-08-31 23:42:47 +00:00
|
|
|
|
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
class AutoapiSummary(Autosummary): # pylint: disable=too-few-public-methods
|
|
|
|
"""A version of autosummary that uses static analysis."""
|
2017-08-31 23:42:47 +00:00
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
def get_items(self, names):
|
|
|
|
items = []
|
2017-08-31 23:42:47 +00:00
|
|
|
env = self.state.document.settings.env
|
|
|
|
mapper = env.autoapi_mapper
|
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
for name in names:
|
|
|
|
obj = mapper.all_objects[name]
|
|
|
|
if isinstance(obj, PythonFunction):
|
2020-08-16 04:29:08 +00:00
|
|
|
if obj.overloads:
|
2020-08-06 07:38:29 +00:00
|
|
|
sig = "(\u2026)"
|
|
|
|
else:
|
|
|
|
sig = "({})".format(obj.args)
|
|
|
|
if obj.return_annotation is not None:
|
|
|
|
sig += " \u2192 {}".format(obj.return_annotation)
|
2020-08-01 08:25:09 +00:00
|
|
|
else:
|
|
|
|
sig = ""
|
2017-08-31 23:42:47 +00:00
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
item = (obj.short_name, sig, obj.summary, obj.id)
|
|
|
|
items.append(item)
|
2017-08-31 23:42:47 +00:00
|
|
|
|
2020-08-01 08:25:09 +00:00
|
|
|
return items
|
2016-11-02 23:29:28 +00:00
|
|
|
|
|
|
|
|
2019-10-05 22:11:23 +00:00
|
|
|
class NestedParse(Directive): # pylint: disable=too-few-public-methods
|
2016-11-02 23:29:28 +00:00
|
|
|
|
|
|
|
"""Nested parsing to remove the first heading of included rST
|
|
|
|
|
|
|
|
This is used to handle the case where we like to remove user supplied
|
|
|
|
headings from module docstrings. This is required to reduce the number of
|
|
|
|
duplicate headings on sections.
|
|
|
|
"""
|
|
|
|
|
|
|
|
has_content = 1
|
|
|
|
required_arguments = 0
|
|
|
|
optional_arguments = 0
|
|
|
|
final_argument_whitespace = False
|
|
|
|
option_spec = {}
|
|
|
|
|
|
|
|
def run(self):
|
2020-08-02 13:25:23 +00:00
|
|
|
node = nodes.container()
|
2016-11-02 23:29:28 +00:00
|
|
|
node.document = self.state.document
|
|
|
|
nested_parse_with_titles(self.state, self.content, node)
|
|
|
|
try:
|
|
|
|
title_node = node[0][0]
|
|
|
|
if isinstance(title_node, nodes.title):
|
2016-11-03 03:01:21 +00:00
|
|
|
del node[0][0]
|
2016-11-02 23:29:28 +00:00
|
|
|
except IndexError:
|
|
|
|
pass
|
2020-08-02 13:25:23 +00:00
|
|
|
return node.children
|