Skip to content

Commit

Permalink
Merge pull request #373 from machow/feat-auto-no-sort-members
Browse files Browse the repository at this point in the history
feat: add Auto member_order option
  • Loading branch information
machow authored Oct 10, 2024
2 parents d85484a + 04c1b17 commit 7d07fbb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion quartodoc/builder/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,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}

return sorted(options)
if el.member_order == "alphabetical":
return sorted(options)
elif el.member_order == "source":
return list(options)
else:
raise ValueError(f"Unsupported value of member_order: {el.member_order}")


class _PagePackageStripper(PydanticTransformer):
Expand Down
4 changes: 4 additions & 0 deletions quartodoc/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class AutoOptions(_Base):
dynamic: Union[None, bool, str] = None
children: ChoicesChildren = ChoicesChildren.embedded
package: Union[str, None, MISSING] = MISSING()
member_order: Literal["alphabetical", "source"] = "alphabetical"
member_options: Optional["AutoOptions"] = None

# for tracking fields users manually specify
Expand Down Expand Up @@ -275,6 +276,9 @@ class Auto(AutoOptions):
Style for presenting members. Either separate, embedded, or flat.
package:
If specified, object lookup will be relative to this path.
member_order:
Order to present members in, either "alphabetical" or "source" order.
Defaults to alphabetical sorting.
member_options:
Options to apply to members. These can include any of the options above.
Expand Down
19 changes: 19 additions & 0 deletions quartodoc/tests/test_builder_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,25 @@ def test_blueprint_fetch_members_dynamic():
assert bp.members[0].obj.parent.path == name.replace(":", ".")


@pytest.mark.parametrize("order", ["alphabetical", "source"])
def test_blueprint_member_order(order):
auto = lo.Auto(
name="quartodoc.tests.example_class.C",
member_order=order,
include_functions=True,
include_attributes=False,
include_classes=False,
)
bp = blueprint(auto)
src_names = [entry.name for entry in bp.members]
dst_names = ["some_method", "some_class_method"]

if order == "alphabetical":
dst_names = sorted(dst_names)

assert src_names == dst_names


def test_blueprint_member_options():
auto = lo.Auto(
name="quartodoc.tests.example",
Expand Down

0 comments on commit 7d07fbb

Please sign in to comment.