Can override ignoring local imports in modules by using __all__

pull/167/head
Ashley Whetter 5 years ago
parent 9d45eed4d0
commit 589826e90c

@ -27,6 +27,7 @@ class PythonPythonMapper(PythonMapperBase):
self.children = [] self.children = []
self.args = obj.get("args") self.args = obj.get("args")
self.docstring = obj["doc"] self.docstring = obj["doc"]
self.imported = "original_path" in obj
# For later # For later
self._class_content = class_content self._class_content = class_content

@ -221,7 +221,7 @@ class Parser(object):
top_name = node.name.split(".", 1)[0] top_name = node.name.split(".", 1)[0]
for child in node.get_children(): 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) child_data = self._parse_local_import_from(child)
else: else:
child_data = self.parse(child) child_data = self.parse(child)

@ -47,7 +47,13 @@ Submodules
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block content %} {% 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 %} {% set visible_children = obj.children|selectattr("display")|list %}
{% else %}
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
{% endif %}
{% if visible_children %} {% if visible_children %}
{{ obj.type|title }} Contents {{ obj.type|title }} Contents
{{ "-" * obj.type|length }}--------- {{ "-" * obj.type|length }}---------
@ -86,9 +92,7 @@ Functions
{% endblock %} {% endblock %}
{% endif %} {% endif %}
{% for obj_item in visible_children %} {% for obj_item in visible_children %}
{% if obj.all is none or obj_item.short_name in obj.all %}
{{ obj_item.rendered|indent(0) }} {{ obj_item.rendered|indent(0) }}
{% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

@ -3,6 +3,11 @@
This is a description This is a description
""" """
from ._private_module import PrivateClass as PublicClass
from ._subpackage import module_level_method
__all__ = ["PublicClass", "Foo"]
class Foo(object): class Foo(object):

@ -370,3 +370,17 @@ class TestComplexPackage(object):
assert "simple_function" in wildcard_file assert "simple_function" in wildcard_file
assert "public_chain" in wildcard_file assert "public_chain" in wildcard_file
assert "module_level_method" 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

Loading…
Cancel
Save