Skip to content

Commit 16c170f

Browse files
committed
feat(builder): add top-level dynamic option
1 parent 68cef3e commit 16c170f

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

quartodoc/autosummary.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ class Builder:
340340
A directory where source files to be documented live. This is only necessary
341341
if you are not documenting a package, but collection of scripts. Use a "."
342342
to refer to the current directory.
343+
dynamic:
344+
Whether to dynamically load all python objects. By default, objects are
345+
loaded using static analysis.
343346
344347
"""
345348

@@ -382,6 +385,7 @@ def __init__(
382385
sidebar: "str | None" = None,
383386
rewrite_all_pages=False,
384387
source_dir: "str | None" = None,
388+
dynamic: bool | None = None,
385389
):
386390
self.layout = self.load_layout(sections=sections, package=package)
387391

@@ -398,6 +402,7 @@ def __init__(
398402

399403
self.rewrite_all_pages = rewrite_all_pages
400404
self.source_dir = str(Path(source_dir).absolute()) if source_dir else None
405+
self.dynamic = dynamic
401406

402407
def load_layout(self, sections: dict, package: str):
403408
# TODO: currently returning the list of sections, to make work with
@@ -428,7 +433,7 @@ def build(self, filter: str = "*"):
428433
# shaping and collection ----
429434

430435
_log.info("Generating blueprint.")
431-
blueprint = blueprint(self.layout)
436+
blueprint = blueprint(self.layout, self.dynamic)
432437

433438
_log.info("Collecting pages and inventory items.")
434439
pages, items = collect(blueprint, base_dir=self.dir)

quartodoc/builder/blueprint.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self, get_object=None, parser="numpy"):
4545
self.get_object = get_object
4646

4747
self.crnt_package = None
48+
self.dynamic = None
4849

4950
@staticmethod
5051
def _append_member_path(path: str, new: str):
@@ -109,7 +110,9 @@ def enter(self, el: Auto):
109110

110111
_log.info(f"Getting object for {path}")
111112

112-
obj = self.get_object_fixed(path, dynamic=el.dynamic)
113+
dynamic = el.dynamic if el.dynamic is not None else self.dynamic
114+
115+
obj = self.get_object_fixed(path, dynamic=dynamic)
113116
raw_members = self._fetch_members(el, obj)
114117

115118
# Three cases for structuring child methods ----
@@ -122,7 +125,7 @@ def enter(self, el: Auto):
122125
# On the other hand, we've wired get_object up to make sure getting
123126
# the member of an Alias also returns an Alias.
124127
member_path = self._append_member_path(path, entry)
125-
obj_member = self.get_object_fixed(member_path, dynamic=el.dynamic)
128+
obj_member = self.get_object_fixed(member_path, dynamic=dynamic)
126129

127130
# do no document submodules
128131
if obj_member.kind.value == "module":
@@ -198,7 +201,7 @@ def blueprint(el: Auto, package: str) -> Doc:
198201
...
199202

200203

201-
def blueprint(el: _Base, package: str = None) -> _Base:
204+
def blueprint(el: _Base, package: str = None, dynamic: None | bool = None) -> _Base:
202205
"""Convert a configuration element to something that is ready to render.
203206
204207
Parameters
@@ -207,6 +210,8 @@ def blueprint(el: _Base, package: str = None) -> _Base:
207210
An element, like layout.Auto, to transform.
208211
package:
209212
A base package name. If specified, this is prepended to the names of any objects.
213+
dynamic:
214+
Whether to dynamically load objects. Defaults to using static analysis.
210215
211216
Examples
212217
--------
@@ -226,6 +231,9 @@ def blueprint(el: _Base, package: str = None) -> _Base:
226231
if package is not None:
227232
trans.crnt_package = package
228233

234+
if dynamic is not None:
235+
trans.dynamic = dynamic
236+
229237
return trans.visit(el)
230238

231239

quartodoc/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Auto(_Base):
212212
include_private: bool = False
213213
include: Optional[str] = None
214214
exclude: Optional[str] = None
215-
dynamic: Union[bool, str] = False
215+
dynamic: Union[None, bool, str] = None
216216
children: ChoicesChildren = ChoicesChildren.embedded
217217

218218

quartodoc/tests/test_builder_blueprint.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from quartodoc import get_object
22
from quartodoc import layout as lo
3-
from quartodoc.builder.blueprint import BlueprintTransformer
3+
from quartodoc.builder.blueprint import BlueprintTransformer, blueprint
44
import pytest
55

66
TEST_MOD = "quartodoc.tests.example"
@@ -70,3 +70,14 @@ def test_blueprint_visit_module(bp, dynamic):
7070
assert len(res.members) == 1
7171
assert res.members[0].name == "a_func"
7272
assert res.members[0].obj.path == path.replace(":", ".") + ".a_func"
73+
74+
75+
def test_blueprint_default_dynamic(bp):
76+
from quartodoc.tests.example_dynamic import NOTE
77+
78+
path = "quartodoc.tests.example_dynamic:f"
79+
auto = lo.Auto(name=path)
80+
81+
res = blueprint(auto, dynamic=True)
82+
assert isinstance(res, lo.DocFunction)
83+
assert NOTE in res.obj.docstring.value

0 commit comments

Comments
 (0)