Skip to content

Commit 90d83d3

Browse files
authored
Merge branch 'main' into feat-auto-exclude
2 parents 1dff27c + 7d07fbb commit 90d83d3

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
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 el.exclude:
408408
options = {k: v for k, v in options.items() if k not in el.exclude}
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
@@ -277,6 +278,9 @@ class Auto(AutoOptions):
277278
Style for presenting members. Either separate, embedded, or flat.
278279
package:
279280
If specified, object lookup will be relative to this path.
281+
member_order:
282+
Order to present members in, either "alphabetical" or "source" order.
283+
Defaults to alphabetical sorting.
280284
member_options:
281285
Options to apply to members. These can include any of the options above.
282286

quartodoc/renderers/md_renderer.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ParamRow:
5959
def to_definition_list(self):
6060
name = self.name
6161
anno = self.annotation
62-
desc = self.description
62+
desc = sanitize(self.description, allow_markdown=True)
6363
default = sanitize(str(self.default))
6464

6565
part_name = (
@@ -77,7 +77,7 @@ def to_definition_list(self):
7777
# in the table display format, not description lists....
7878
# by this stage _required_ is basically a special token to indicate
7979
# a required argument.
80-
if default is not None:
80+
if self.default is not None:
8181
part_default_sep = Span(" = ", Attr(classes=["parameter-default-sep"]))
8282
part_default = Span(default, Attr(classes=["parameter-default"]))
8383
else:
@@ -100,13 +100,15 @@ def to_definition_list(self):
100100

101101
def to_tuple(self, style: Literal["parameters", "attributes", "returns"]):
102102
name = self.name
103+
description = sanitize(self.description, allow_markdown=True)
104+
103105
if style == "parameters":
104106
default = "_required_" if self.default is None else escape(self.default)
105-
return (name, self.annotation, self.description, default)
107+
return (name, self.annotation, description, default)
106108
elif style == "attributes":
107-
return (name, self.annotation, self.description)
109+
return (name, self.annotation, description)
108110
elif style == "returns":
109-
return (name, self.annotation, self.description)
111+
return (name, self.annotation, description)
110112

111113
raise NotImplementedError(f"Unsupported table style: {style}")
112114

@@ -595,8 +597,9 @@ def render(self, el: ds.DocstringSectionParameters):
595597
@dispatch
596598
def render(self, el: ds.DocstringParameter) -> ParamRow:
597599
annotation = self.render_annotation(el.annotation)
598-
clean_desc = sanitize(el.description, allow_markdown=True)
599-
return ParamRow(el.name, clean_desc, annotation=annotation, default=el.default)
600+
return ParamRow(
601+
el.name, el.description, annotation=annotation, default=el.default
602+
)
600603

601604
# attributes ----
602605

@@ -611,7 +614,7 @@ def render(self, el: ds.DocstringSectionAttributes):
611614
def render(self, el: ds.DocstringAttribute) -> ParamRow:
612615
return ParamRow(
613616
el.name,
614-
sanitize(el.description or "", allow_markdown=True),
617+
el.description or "",
615618
annotation=self.render_annotation(el.annotation),
616619
)
617620

@@ -680,7 +683,7 @@ def render(self, el: ds.DocstringReturn):
680683
# similar to DocstringParameter, but no name or default
681684
return ParamRow(
682685
el.name,
683-
sanitize(el.description, allow_markdown=True),
686+
el.description,
684687
annotation=self.render_annotation(el.annotation),
685688
)
686689

@@ -689,7 +692,7 @@ def render(self, el: ds.DocstringRaise) -> ParamRow:
689692
# similar to DocstringParameter, but no name or default
690693
return ParamRow(
691694
None,
692-
sanitize(el.description, allow_markdown=True),
695+
el.description,
693696
annotation=self.render_annotation(el.annotation),
694697
)
695698

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@
483483
List
484484
# Parameters {.doc-section .doc-section-parameters}
485485

486-
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
486+
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
487487

488488
: A description.
489489

490490
# Returns {.doc-section .doc-section-returns}
491491

492-
<code>[]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
492+
<code>[]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
493493

494494
: A description.
495495

496496
# Attributes {.doc-section .doc-section-attributes}
497497

498-
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
498+
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
499499

500500
: A description.
501501
'''
@@ -540,19 +540,19 @@
540540
List
541541
# Parameters {.doc-section .doc-section-parameters}
542542

543-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
543+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
544544

545545
: A description.
546546

547547
# Returns {.doc-section .doc-section-returns}
548548

549-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
549+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
550550

551551
: A description.
552552

553553
# Attributes {.doc-section .doc-section-attributes}
554554

555-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
555+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
556556

557557
: A description.
558558
'''

quartodoc/tests/test_builder_blueprint.py

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

286286

287+
@pytest.mark.parametrize("order", ["alphabetical", "source"])
288+
def test_blueprint_member_order(order):
289+
auto = lo.Auto(
290+
name="quartodoc.tests.example_class.C",
291+
member_order=order,
292+
include_functions=True,
293+
include_attributes=False,
294+
include_classes=False,
295+
)
296+
bp = blueprint(auto)
297+
src_names = [entry.name for entry in bp.members]
298+
dst_names = ["some_method", "some_class_method"]
299+
300+
if order == "alphabetical":
301+
dst_names = sorted(dst_names)
302+
303+
assert src_names == dst_names
304+
305+
287306
def test_blueprint_member_options():
288307
auto = lo.Auto(
289308
name="quartodoc.tests.example",

0 commit comments

Comments
 (0)