Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement auto excludes option #372

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions quartodoc/builder/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,6 @@ def _fetch_members(self, el: Auto, obj: dc.Object | dc.Alias):
if obj.is_module and obj.exports is not None:
options = {k: v for k, v in options.items() if v.is_exported}

if el.include:
raise NotImplementedError("include argument currently unsupported.")

if el.exclude:
raise NotImplementedError("exclude argument currently unsupported.")

if not el.include_private:
options = {k: v for k, v in options.items() if not k.startswith("_")}

Expand Down Expand Up @@ -407,6 +401,12 @@ def _fetch_members(self, el: Auto, obj: dc.Object | dc.Alias):
if not el.include_functions:
options = {k: v for k, v in options.items() if not v.is_function}

if el.include:
raise NotImplementedError("include argument currently unsupported.")

if el.exclude:
options = {k: v for k, v in options.items() if k not in el.exclude}

if el.member_order == "alphabetical":
return sorted(options)
elif el.member_order == "source":
Expand Down
6 changes: 4 additions & 2 deletions quartodoc/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class AutoOptions(_Base):

# other options ----
include: Optional[str] = None
exclude: Optional[str] = None
exclude: Optional[list[str]] = None
dynamic: Union[None, bool, str] = None
children: ChoicesChildren = ChoicesChildren.embedded
package: Union[str, None, MISSING] = MISSING()
Expand Down Expand Up @@ -250,6 +250,7 @@ class Auto(AutoOptions):
path the object, and short is the name of the object (i.e. no periods).
members:
A list of members, such as attributes or methods on a class, to document.
If members is specified, no other includes or excludes are applied.
include_private:
Whether to include members starting with "_"
include_imports:
Expand All @@ -267,7 +268,8 @@ class Auto(AutoOptions):
include:
(Not implemented). A list of members to include.
exclude:
(Not implemented). A list of members to exclude.
A list of members to exclude. This is performed last, in order to subtract
from the results of options like include_functions.
dynamic:
Whether to dynamically load docstring. By default docstrings are loaded
using static analysis. dynamic may be a string pointing to another object,
Expand Down
24 changes: 24 additions & 0 deletions quartodoc/tests/test_builder_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,30 @@ def test_blueprint_fetch_members_include_inherited():
assert "some_method" in member_names


def test_blueprint_fetch_members_exclude():
auto = lo.Auto(
name="quartodoc.tests.example_class.C",
include_functions=True,
include_attributes=False,
include_classes=False,
exclude=["some_property", "some_class_method"],
)

bp = blueprint(auto)
_check_member_names(bp.members, {"some_method"})


def test_blueprint_fetch_members_exclude_ignored():
auto = lo.Auto(
name="quartodoc.tests.example_class.C",
members=["some_property", "some_class_method"],
exclude=["some_class_method"],
)

bp = blueprint(auto)
_check_member_names(bp.members, {"some_property", "some_class_method"})


def test_blueprint_fetch_members_dynamic():
# Since AClass is imported via star import it has to be dynamically
# resolved. This test ensures that the members of AClass also get
Expand Down
Loading