From 1dff27cf39230e33a839a84ad710f37bf40940fb Mon Sep 17 00:00:00 2001 From: Michael Chow Date: Wed, 9 Oct 2024 12:54:56 -0400 Subject: [PATCH] feat: implement auto excludes option --- quartodoc/builder/blueprint.py | 12 ++++++------ quartodoc/layout.py | 6 ++++-- quartodoc/tests/test_builder_blueprint.py | 24 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/quartodoc/builder/blueprint.py b/quartodoc/builder/blueprint.py index 10786c7..0d0ff86 100644 --- a/quartodoc/builder/blueprint.py +++ b/quartodoc/builder/blueprint.py @@ -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("_")} @@ -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} + return sorted(options) diff --git a/quartodoc/layout.py b/quartodoc/layout.py index 43cdf8e..84f2a1d 100644 --- a/quartodoc/layout.py +++ b/quartodoc/layout.py @@ -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() @@ -249,6 +249,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: @@ -266,7 +267,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, diff --git a/quartodoc/tests/test_builder_blueprint.py b/quartodoc/tests/test_builder_blueprint.py index bd6c4cc..927ddb0 100644 --- a/quartodoc/tests/test_builder_blueprint.py +++ b/quartodoc/tests/test_builder_blueprint.py @@ -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