Skip to content

Commit 7d07fbb

Browse files
authored
Merge pull request #373 from machow/feat-auto-no-sort-members
feat: add Auto member_order option
2 parents d85484a + 04c1b17 commit 7d07fbb

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

quartodoc/builder/blueprint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,12 @@ def _fetch_members(self, el: Auto, obj: dc.Object | dc.Alias):
407407
if not el.include_functions:
408408
options = {k: v for k, v in options.items() if not v.is_function}
409409

410-
return sorted(options)
410+
if el.member_order == "alphabetical":
411+
return sorted(options)
412+
elif el.member_order == "source":
413+
return list(options)
414+
else:
415+
raise ValueError(f"Unsupported value of member_order: {el.member_order}")
411416

412417

413418
class _PagePackageStripper(PydanticTransformer):

quartodoc/layout.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class AutoOptions(_Base):
225225
dynamic: Union[None, bool, str] = None
226226
children: ChoicesChildren = ChoicesChildren.embedded
227227
package: Union[str, None, MISSING] = MISSING()
228+
member_order: Literal["alphabetical", "source"] = "alphabetical"
228229
member_options: Optional["AutoOptions"] = None
229230

230231
# for tracking fields users manually specify
@@ -275,6 +276,9 @@ class Auto(AutoOptions):
275276
Style for presenting members. Either separate, embedded, or flat.
276277
package:
277278
If specified, object lookup will be relative to this path.
279+
member_order:
280+
Order to present members in, either "alphabetical" or "source" order.
281+
Defaults to alphabetical sorting.
278282
member_options:
279283
Options to apply to members. These can include any of the options above.
280284

quartodoc/tests/test_builder_blueprint.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ def test_blueprint_fetch_members_dynamic():
260260
assert bp.members[0].obj.parent.path == name.replace(":", ".")
261261

262262

263+
@pytest.mark.parametrize("order", ["alphabetical", "source"])
264+
def test_blueprint_member_order(order):
265+
auto = lo.Auto(
266+
name="quartodoc.tests.example_class.C",
267+
member_order=order,
268+
include_functions=True,
269+
include_attributes=False,
270+
include_classes=False,
271+
)
272+
bp = blueprint(auto)
273+
src_names = [entry.name for entry in bp.members]
274+
dst_names = ["some_method", "some_class_method"]
275+
276+
if order == "alphabetical":
277+
dst_names = sorted(dst_names)
278+
279+
assert src_names == dst_names
280+
281+
263282
def test_blueprint_member_options():
264283
auto = lo.Auto(
265284
name="quartodoc.tests.example",

0 commit comments

Comments
 (0)