Skip to content

Commit 1b5cdec

Browse files
committed
feat: add options config to Section in layout
1 parent b798de3 commit 1b5cdec

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

docs/_quarto.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,16 @@ quartodoc:
9393
- title: Docstring Renderers
9494
desc: |
9595
Renderers convert parsed docstrings into a target format, like markdown.
96+
options:
97+
dynamic: true
9698
contents:
9799
- name: MdRenderer
98100
children: linked
99-
- name: MdRenderer.render
100-
dynamic: true
101-
- name: MdRenderer.render_annotation
102-
dynamic: true
103-
- name: MdRenderer.render_header
104-
dynamic: true
105-
- name: MdRenderer.signature
106-
dynamic: true
107-
- name: MdRenderer.summarize
108-
dynamic: true
101+
- MdRenderer.render
102+
- MdRenderer.render_annotation
103+
- MdRenderer.render_header
104+
- MdRenderer.signature
105+
- MdRenderer.summarize
109106

110107
- title: API Builders
111108
desc: |

quartodoc/builder/blueprint.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def __init__(self, get_object=None, parser="numpy"):
107107
self.get_object = get_object
108108

109109
self.crnt_package = None
110-
self.dynamic = None
110+
self.options = None
111+
self.dynamic = False
111112

112113
@staticmethod
113114
def _append_member_path(path: str, new: str):
@@ -138,16 +139,26 @@ def visit(self, el):
138139
# TODO: use a context handler
139140
self._log("VISITING", el)
140141

142+
# set package ----
141143
package = getattr(el, "package", MISSING())
142144
old = self.crnt_package
143145

144146
if not isinstance(package, MISSING):
145147
self.crnt_package = package
146148

149+
# set options ----
150+
# TODO: check for Section instead?
151+
options = getattr(el, "options", None)
152+
old_options = self.options
153+
154+
if options is not None:
155+
self.options = options
156+
147157
try:
148158
return super().visit(el)
149159
finally:
150160
self.crnt_package = old
161+
self.options = old_options
151162

152163
@dispatch
153164
def enter(self, el: Layout):
@@ -208,6 +219,7 @@ def exit(self, el: Section):
208219
def enter(self, el: Auto):
209220
self._log("Entering", el)
210221

222+
# settings based on parent context options (package, options) ----
211223
# TODO: make this less brittle
212224
pkg = self.crnt_package
213225
if pkg is None:
@@ -217,6 +229,12 @@ def enter(self, el: Auto):
217229
else:
218230
path = f"{pkg}:{el.name}"
219231

232+
# auto default overrides
233+
if self.options is not None:
234+
# TODO: is this round-tripping guaranteed by pydantic?
235+
el = el.__class__(**{**self.options.dict(), **el.dict()})
236+
237+
# fetching object ----
220238
_log.info(f"Getting object for {path}")
221239

222240
dynamic = el.dynamic if el.dynamic is not None else self.dynamic

quartodoc/layout.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Section(_Structural):
7878
desc: Optional[str] = None
7979
package: Union[str, None, MISSING] = MISSING()
8080
contents: ContentList = []
81+
options: Optional["AutoOptions"] = None
8182

8283
def __init__(self, **data):
8384
super().__init__(**data)
@@ -199,7 +200,21 @@ class ChoicesChildren(Enum):
199200
linked = "linked"
200201

201202

202-
class Auto(_Base):
203+
class AutoOptions(_Base):
204+
"""Options available for Auto content layout element."""
205+
206+
members: Optional[list[str]] = None
207+
include_private: bool = False
208+
include_imports: bool = False
209+
include_empty: bool = False
210+
include: Optional[str] = None
211+
exclude: Optional[str] = None
212+
dynamic: Union[None, bool, str] = None
213+
children: ChoicesChildren = ChoicesChildren.embedded
214+
package: Union[str, None, MISSING] = MISSING()
215+
216+
217+
class Auto(AutoOptions):
203218
"""Configure a python object to document (e.g. module, class, function, attribute).
204219
205220
Attributes
@@ -233,15 +248,6 @@ class Auto(_Base):
233248

234249
kind: Literal["auto"] = "auto"
235250
name: str
236-
members: Optional[list[str]] = None
237-
include_private: bool = False
238-
include_imports: bool = False
239-
include_empty: bool = False
240-
include: Optional[str] = None
241-
exclude: Optional[str] = None
242-
dynamic: Union[None, bool, str] = None
243-
children: ChoicesChildren = ChoicesChildren.embedded
244-
package: Union[str, None, MISSING] = MISSING()
245251

246252

247253
# TODO: rename to Default or something

0 commit comments

Comments
 (0)