diff --git a/autoapi/mappers/python/objects.py b/autoapi/mappers/python/objects.py index 891a6d8..00acf03 100644 --- a/autoapi/mappers/python/objects.py +++ b/autoapi/mappers/python/objects.py @@ -27,6 +27,7 @@ class PythonPythonMapper(PythonMapperBase): self.children = [] self.args = obj.get("args") self.docstring = obj["doc"] + self.imported = "original_path" in obj # For later self._class_content = class_content diff --git a/autoapi/mappers/python/parser.py b/autoapi/mappers/python/parser.py index 9c49380..853c92c 100644 --- a/autoapi/mappers/python/parser.py +++ b/autoapi/mappers/python/parser.py @@ -221,7 +221,7 @@ class Parser(object): top_name = node.name.split(".", 1)[0] for child in node.get_children(): - if node.package and astroid_utils.is_local_import_from(child, top_name): + if astroid_utils.is_local_import_from(child, top_name): child_data = self._parse_local_import_from(child) else: child_data = self.parse(child) diff --git a/autoapi/templates/python/module.rst b/autoapi/templates/python/module.rst index 55df3f7..3f3292d 100644 --- a/autoapi/templates/python/module.rst +++ b/autoapi/templates/python/module.rst @@ -47,7 +47,13 @@ Submodules {% endif %} {% endblock %} {% block content %} +{% if obj.all is not none %} +{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %} +{% elif obj.type is equalto("package") %} {% set visible_children = obj.children|selectattr("display")|list %} +{% else %} +{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %} +{% endif %} {% if visible_children %} {{ obj.type|title }} Contents {{ "-" * obj.type|length }}--------- @@ -86,9 +92,7 @@ Functions {% endblock %} {% endif %} {% for obj_item in visible_children %} -{% if obj.all is none or obj_item.short_name in obj.all %} {{ obj_item.rendered|indent(0) }} -{% endif %} {% endfor %} {% endif %} {% endblock %} diff --git a/tests/python/pypackagecomplex/complex/foo.py b/tests/python/pypackagecomplex/complex/foo.py index 6233add..09f7fb5 100644 --- a/tests/python/pypackagecomplex/complex/foo.py +++ b/tests/python/pypackagecomplex/complex/foo.py @@ -3,6 +3,11 @@ This is a description """ +from ._private_module import PrivateClass as PublicClass +from ._subpackage import module_level_method + +__all__ = ["PublicClass", "Foo"] + class Foo(object): diff --git a/tests/python/test_pyintegration.py b/tests/python/test_pyintegration.py index d6a9102..2e60009 100644 --- a/tests/python/test_pyintegration.py +++ b/tests/python/test_pyintegration.py @@ -370,3 +370,17 @@ class TestComplexPackage(object): assert "simple_function" in wildcard_file assert "public_chain" in wildcard_file assert "module_level_method" in wildcard_file + + def test_no_imports_in_module_with_all(self): + foo_path = "_build/text/autoapi/complex/foo/index.txt" + with io.open(foo_path, encoding="utf8") as foo_handle: + foo_file = foo_handle.read() + + assert "module_level_method" not in foo_file + + def test_all_overrides_import_in_module_with_all(self): + foo_path = "_build/text/autoapi/complex/foo/index.txt" + with io.open(foo_path, encoding="utf8") as foo_handle: + foo_file = foo_handle.read() + + assert "PublicClass" in foo_file