Skip to content

Commit f91823a

Browse files
committed
docs: more getting started
1 parent 1bc2a0e commit f91823a

File tree

9 files changed

+198
-17
lines changed

9 files changed

+198
-17
lines changed

docs/_quarto.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ website:
4747
- get-started/crossrefs.qmd
4848
- get-started/interlinks.qmd
4949
- get-started/sidebar.qmd
50-
- get-started/advanced-layouts.qmd
5150
- get-started/extending.qmd
5251

52+
- section: "Docstrings"
53+
contents:
54+
- get-started/docstring-style.qmd
55+
- get-started/docstring-examples.qmd
56+
5357
- section: "Programming"
5458
contents:
5559
- get-started/dev-big-picture.qmd

docs/get-started/advanced-layouts.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jupyter:
1111

1212
## Children options
1313

14-
##
14+
##

docs/get-started/basic-building.qmd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,34 @@ quarto preview
2929
```bash
3030
quartodoc build --verbose
3131
```
32+
33+
## Speeding up preview
34+
35+
### Rewriting doc files
36+
37+
By default, the `quartodoc build` only re-writes doc pages when it detects
38+
a change to their content. This helps prevent `quarto preview` from trying
39+
to re-render every doc page--including those that haven't changed.
40+
41+
### Selectively building doc pages
42+
43+
Use the filter option with `quartodoc build` to generate a subset of doc pages.
44+
This is useful when you have a many (e.g. several hundred) doc pages, and want
45+
to test a change on a single page.
46+
47+
```bash
48+
quartodoc build --filter 'get_object'
49+
```
50+
51+
This option also accepts a wildcard pattern, which causes it to build docs for all matching objects.
52+
53+
```bash
54+
# write the docs for the MdRenderer class, and any of its methods
55+
# (e.g. MdRenderer.renderer)
56+
quartodoc build --filter 'MdRenderer*'
57+
```
58+
59+
:::{.callout-note}
60+
When using a name with a wildcard, be sure to put it in single quotes!
61+
Otherwise, your shell may try to "expand it" to match file names.
62+
:::

docs/get-started/dev-big-picture.qmd

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@ jupyter:
77
name: python3
88
---
99

10-
* The Builder class loads your quarto config as a layout
11-
* The ABCs
12-
- It contains a bunch of Auto elements, that eventually end up as Page objects.
13-
* A Renderer handles the output of blueprint into a string
14-
* Builder methods like `.write_doc_pages()`, or `.write_sidebar()` make the actual site.
10+
While the "Basic Use" section covered how to configure and build a site with quartodoc, this section focuses on using quartodoc as a python program.
11+
12+
Programming with quartodoc will help with debugging, tinkering, and extending things.
13+
14+
## Overview
15+
16+
When a user runs `quartodoc build`, they
17+
18+
* Create a [Builder](`quartodoc.Builder`) object, with the quartodoc config loaded as a [layout.Layout](`quartodoc.layout.Layout`).
19+
* Use [blueprint](`quartodoc.blueprint`) to process the layout into a plan for building the website.
20+
* Use [collect](`quartodoc.collect`) to get pages to render, and info on where documented objects live.
21+
22+
This page will cover the basics of the Builder and this process.
1523

1624
## The Builder
1725

26+
The code below shows a Builder object being loaded from a `_quarto.yml` config (loaded as a python dictionary).
27+
1828
```{python}
1929
import yaml
2030
21-
from pprint import pprint
2231
from quartodoc import Builder, preview, blueprint, collect, MdRenderer
2332
2433
cfg = yaml.safe_load("""
@@ -41,33 +50,89 @@ builder
4150
Note that .from_quarto_config used the `style:` field to decide which Builder to create
4251
(in this case, PkgdownBuilder).
4352

53+
We can view the config as a [layout.Layout](`quartodoc.layout.Layout`), by looking at the `.layout` attribute.
54+
55+
```{python}
56+
builder.layout
57+
```
58+
59+
This can be a bit difficult to read, so quartodoc implements a [preview](`quartodoc.preview`) function, which spaces things out.
60+
4461
```{python}
4562
preview(builder.layout)
4663
```
4764

65+
Notice the following:
66+
67+
* `preview` represents calls like `Layout()` with a box to the left, and then
68+
a pipe connecting it to each of its arguments.
69+
* The content entry `MdRenderer` is represented by an [Auto](`quartodoc.Auto`) class.
70+
This specifies a python object to look up and document.
71+
72+
We can follow the path in the preview above, to pull out just the contents piece:
73+
4874
```{python}
4975
content = builder.layout.sections[0].contents
5076
preview(content)
5177
```
5278

79+
Next, we'll look at `blueprint()`, which processes the layout, including transforming `Auto` objects into more concrete instructions.
80+
5381
## From config to blueprint
5482

83+
The code below shows how `blueprint()` transforms the `Auto` entry for `MdRenderer`.
84+
5585
```{python}
5686
bp = blueprint(builder.layout)
5787
bp_contents = bp.sections[0].contents
5888
preview(bp_contents[0], max_depth=3)
5989
```
6090

91+
Notice two key pieces:
92+
93+
* The outermost element is now a [layout.Page](`quartodoc.layout.Page`).
94+
The `.path` indicates that the documentation will be on a page called `"MdRenderer"`.
95+
* The content of the page is a [layout.DocClass](`quartodoc.layout.DocClass).
96+
This element holds everything needed to render this doc, including the class signature
97+
and parsed docstring.
98+
99+
Importantly, the `.members` attribute specifies how to render the class methods we specified (`.render()` and `.summarize()`).
100+
101+
```{python}
102+
preview(bp_contents[0].contents[0].members, max_depth=2)
103+
```
104+
105+
Note that they are also a instances of `Page` (`MemberPage` to be exact).
106+
Before to building the site, we need to `collect()` all the pages.
107+
108+
61109

62110
## Collecting pages and items
63111

112+
The [collect](`quartodoc.collect`) function pulls out two important pieces of information:
113+
114+
* **pages** - each page to be rendered.
115+
* **items** - information on where each documented object lives in the site.
116+
64117
```{python}
65118
pages, items = collect(bp, builder.dir)
66119
preview(pages, max_depth=3)
67120
```
68121

122+
The code below shows a preview of the items.
123+
124+
```{python}
125+
preview(items, max_depth=2)
126+
```
127+
128+
Notice that if you wanted to look up `quartodoc.MdRenderer.render`, the first item's `.uri` attribute shows the URL for it, relative to wherever the doc site is hosted.
129+
130+
69131
## Rendering and writing
70132

133+
A `Builder` instantiates a `Renderer` (like [MdRenderer](`quartodoc.MdRenderer`)).
134+
Use the `.renderer` attribute to access it.
135+
71136
```{python}
72137
builder.renderer
73138
```
@@ -77,11 +142,9 @@ print(builder.renderer.render(pages[0]))
77142
78143
```
79144

80-
TODO: note about static analysis, dynamic option.
81-
82-
```{python}
83-
#| eval: false
84-
builder.write_doc_pages(pages)
85-
```
86-
145+
## Writing pages
87146

147+
The builder has a number of methods it uses during build.
148+
The main method is [.build()](`quartodoc.Builder.build`).
149+
See the [Builder section of the API](#api-builders) for a list of methods,
150+
or this [giant build process diagram](/get-started/extra-build-sequence.qmd) for a full breakdown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: 🚧 Examples
3+
jupyter:
4+
kernelspec:
5+
display_name: Python 3 (ipykernel)
6+
language: python
7+
name: python3
8+
---
9+
10+
```{python}
11+
from quartodoc import MdRenderer, preview
12+
13+
renderer = MdRenderer()
14+
```
15+
16+
## Returns: using type annotation
17+
18+
In order to use the return type annotation of a function, use the following syntax.
19+
20+
```
21+
Returns
22+
--------
23+
:
24+
Some description of result
25+
```
26+
27+
Below is a full example.
28+
29+
```{python}
30+
def f() -> int:
31+
"""Some func
32+
33+
Returns
34+
-------
35+
:
36+
A number
37+
""""
38+
39+
```
40+
41+
TODO: need to load as a griffe object somehow.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: numpydoc style
3+
jupyter:
4+
kernelspec:
5+
display_name: Python 3 (ipykernel)
6+
language: python
7+
name: python3
8+
---
9+
10+
quartodoc expects numpydoc style for docstrings.
11+
See the [numpydoc sections guide][numpydoc] for more information and examples.
12+
13+
[numpydoc]: https://numpydoc.readthedocs.io/en/latest/format.html#sections

docs/get-started/extending.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ quartodoc:
6464
style: _renderer.py
6565
```
6666

67-
See the [shiny example docs](https://github.com/machow/quartodoc/tree/main/examples/shiny), which contains a custom renderer.
68-
67+
See the [Rendering docstrings](/get-started/renderers.qmd) page for instructions on
68+
creating a custom renderer, and the [](`quartodoc.MdRenderer`) docs for more information.
6969

7070
## Using a custom Builder
7171

docs/get-started/extra-build-sequence.qmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jupyter:
77
name: python3
88
---
99

10+
This sequence diagram shows the process behind `quartodoc build`.
11+
See the API docs for [](`~quartodoc.Builder`), [](`~quartodoc.MdRenderer`), and the preperation functions ([](`~quartodoc.Auto`), [](`~quartodoc.blueprint`), [](`~quartodoc.collect`))
12+
1013
```{mermaid}
1114
%%| fig-width: 100%
1215
sequenceDiagram

docs/get-started/renderers.qmd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,29 @@ Note 3 big pieces:
129129
* **Tree walking**: `render` methods often call `render` again on sub elements.
130130

131131

132+
## Completing the Renderer
133+
134+
While the above example showed a simple example with a `.render` method, a complete renderer will often do two more things:
135+
136+
* Subclass an existing renderer.
137+
* Also override other methods like `.summarize()`
138+
139+
```{python}
140+
from quartodoc import MdRenderer
141+
142+
class NewRenderer(MdRenderer):
143+
style = "new_renderer"
144+
145+
@dispatch
146+
def render(self, el):
147+
print("calling parent method for render")
148+
return super().render(el)
149+
150+
@dispatch
151+
def summarize(self, el):
152+
print("calling parent method for summarize")
153+
return super().summarize(el)
154+
```
155+
156+
For a list of methods, see the [](`~quartodoc.MdRenderer`) docs.
157+

0 commit comments

Comments
 (0)