Inheritance diagrams can follow imports

Closes #193
Closes #208
pull/220/head
Ashley Whetter 4 years ago
parent efe815c1df
commit 975ac49dc0

@ -29,6 +29,9 @@ Bug Fixes
* `#195 <https://github.com/readthedocs/sphinx-autoapi/issues/195>`: (Python)
Fixed incorrect formatting when ``show-inheritance-diagram``
and ``private-members`` are turned on.
* `#193 <https://github.com/readthedocs/sphinx-autoapi/issues/193>` and
* `#208 <https://github.com/readthedocs/sphinx-autoapi/issues/208>`: (Python)
Inheritance diagrams can follow imports to find classes to document.
Trivial/Internal Changes
^^^^^^^^^^^^^^^^^^^^^^^^
@ -36,6 +39,7 @@ Trivial/Internal Changes
* `#207 <https://github.com/readthedocs/sphinx-autoapi/issues/207>`:
Fixed a typo in the code of the golang tutorial.
v1.3.0 (2020-04-05)
-------------------

@ -9,25 +9,36 @@ else:
_BUILTINS = "__builtins__"
def _import_class(name, currmodule):
def _do_import_class(name, currmodule=None):
path_stack = list(reversed(name.split(".")))
if not currmodule:
currmodule = path_stack.pop()
try:
target = astroid.MANAGER.ast_from_module_name(currmodule)
while target and path_stack:
path_part = path_stack.pop()
target = (target.getattr(path_part) or (None,))[0]
while isinstance(target, astroid.ImportFrom):
try:
target = target.do_import_module(path_part)
except astroid.AstroidImportError:
target = target.do_import_module()
target = (target.getattr(path_part) or (None,))[0]
break
except astroid.AstroidError:
target = None
return target
def _import_class(name, currmodule):
target = None
if currmodule:
try:
target = astroid.MANAGER.ast_from_module_name(currmodule)
while target and path_stack:
target = (target.getattr(path_stack.pop()) or (None,))[0]
except astroid.AstroidError:
target = None
target = _do_import_class(name, currmodule)
if target is None:
path_stack = list(reversed(name.split(".")))
try:
target = astroid.MANAGER.ast_from_module_name(path_stack.pop())
while target and path_stack:
target = (target.getattr(path_stack.pop()) or (None,))[0]
except astroid.AstroidError:
target = None
target = _do_import_class(name)
if not target:
raise sphinx.ext.inheritance_diagram.InheritanceException(

Loading…
Cancel
Save