Skip to content

Commit df3a68b

Browse files
authored
Feat layouts (#64)
* DRAFT: layouts * DRAFT: rough layout refactor * DRAFT: move summarizer into renderer * DRAFT: tidy up, start on summarizing class attributes * fix: do not try to get parameters for attributes * DRAFT: small improvements * dev: add pydantic as a dependency * ci: use python 3.10 to build docs * fix: workaround bug in plum where KeyError causes inf recursion * interlinks: if lookup fails, return original text * feat: preview works on pydantic models, add compact option * docs: add builder method docstrings * feat: make Page path necessary; add Section.package * feat(renderer): support rendering modules * docs: add advanced overview * chore: remove some print statements * examples: update shiny renderer to escape html * fix: failing tests * fix: radically speed up module loading * dev: add some logging to blueprint * fix: transform splits multiple sections grouped together * dev!: require py 3.10 or greater for now * feat: interlinks fallback now uses link text, then url * feat: get_object allows module to be none; add dynamic alias * feat: blueprint supports package set to None * fix: add a bit more to sanitize * feat!: renderer default header level now 1, nest members in methods section * ci: only push docs on release * feat: include verbatim title of parsed docstring sections * refactor!: use loader in get_object; dynamic arg can be string * examples: update shiny example * feat!: new path syntax with colon * examples: remove deprecated event page from shiny doc * dev: make py3.8+ compatible * docs: add docstring to render_header * refactor: simplify get_object * feat: add linked option for children * docs: tweak website * ci: re-add earlier python versions * dev: fix < py3.10 compat * feat: put stars in signatures when needed * chore: move node to own file to py3.9 compat * dev: more __future__ imports * dev: pin lower plum version for py < 3.10 * dev: more py < 3.10 compat * dev!: declare bankruptcy on 3.8 support
1 parent 1679759 commit df3a68b

28 files changed

+1893
-474
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
# Checks based on python versions ---
27-
python-version: ['3.8', '3.9', '3.10']
27+
python-version: ['3.9', '3.10']
2828
requirements: [""]
2929

3030
steps:
@@ -73,7 +73,7 @@ jobs:
7373
- uses: actions/checkout@v2
7474
- uses: actions/setup-python@v2
7575
with:
76-
python-version: "3.9"
76+
python-version: "3.10"
7777
- name: Install dependencies
7878
run: |
7979
python -m pip install -r requirements-dev.txt
@@ -139,6 +139,7 @@ jobs:
139139
env_url: 'https://${{ steps.deployment.outputs.env }}--quartodoc.netlify.app'
140140
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
141141
- uses: peaceiris/actions-gh-pages@v3
142+
if: github.event_name == 'release'
142143
with:
143144
github_token: ${{ secrets.GITHUB_TOKEN }}
144145
publish_dir: docs/_build

_extensions/interlinks/interlinks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def visit(el: pf.Link, doc):
256256
return ref_to_anchor(url.replace("%60", "`"), el.content)
257257
except InvLookupError as e:
258258
pf.debug("WARNING: " + str(e))
259+
if el.content:
260+
# Assuming content is a ListContainer(Str(...))
261+
body = el.content[0].text
262+
else:
263+
body = url.replace("%60", "")
264+
return pf.Code(body)
259265

260266
return el
261267

docs/_quarto.yml

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,45 @@ quartodoc:
2525
package: quartodoc
2626
sidebar: "api/_sidebar.yml"
2727
sections:
28-
- title: API Builders
28+
- title: Inspection
2929
desc: |
30-
Builders are responsible for building documentation. They tie all the pieces
31-
of quartodoc together, and can be defined in your _quarto.yml config.
30+
These functions Fetch and analyze python objects, including parsing docstrings.
3231
contents:
33-
- Builder
34-
- BuilderPkgdown
35-
- BuilderSinglePage
32+
- get_object
33+
- preview
3634

3735
- title: Docstring Renderers
3836
desc: |
3937
Renderers convert parsed docstrings into a target format, like markdown.
4038
contents:
41-
- MdRenderer
39+
- name: MdRenderer
40+
children: linked
41+
- name: MdRenderer.render
42+
dynamic: true
43+
- name: MdRenderer.render_annotation
44+
dynamic: true
45+
- name: MdRenderer.render_header
46+
dynamic: true
47+
- name: MdRenderer.signature
48+
dynamic: true
49+
- name: MdRenderer.summarize
50+
dynamic: true
4251

43-
- title: Inspection
52+
- title: API Builders
4453
desc: |
45-
These functions Fetch and analyze python objects, including parsing docstrings.
54+
Builders are responsible for building documentation. They tie all the pieces
55+
of quartodoc together, and can be defined in your _quarto.yml config.
4656
contents:
47-
- get_object
48-
- preview
57+
- kind: auto
58+
name: Builder
59+
members: []
60+
- Builder.build
61+
- Builder.do_blueprint
62+
- Builder.do_collect
63+
- Builder.do_summarize
64+
- Builder.write_index
65+
- Builder.write_doc_pages
66+
4967

5068
- title: Inventory links
5169
desc: |
@@ -55,6 +73,29 @@ quartodoc:
5573
- create_inventory
5674
- convert_inventory
5775

76+
- title: Data models
77+
desc: |
78+
Classes for specifying the exact layout of your docs.
79+
contents:
80+
- kind: "page"
81+
path: "layouts"
82+
flatten: true
83+
contents:
84+
- layout.Layout
85+
- layout.Section
86+
- layout.Page
87+
- layout.Auto
88+
- name: layout.Doc
89+
members: []
90+
- layout.DocFunction
91+
- layout.DocAttribute
92+
- layout.DocModule
93+
- layout.DocClass
94+
- layout.Link
95+
- layout.Item
96+
- layout.SectionElement
97+
- layout.ContentElement
98+
5899

59100
website:
60101
title: "quartodoc"
@@ -88,6 +129,7 @@ website:
88129
contents:
89130
- get-started/docstrings.qmd
90131
- get-started/renderers.qmd
132+
- get-started/building.qmd
91133
- section: "Extra Topics"
92134
contents:
93135
- get-started/architecture.qmd

docs/get-started/building.qmd

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Building layouts
3+
jupyter:
4+
jupytext:
5+
text_representation:
6+
extension: .qmd
7+
format_name: quarto
8+
format_version: '1.0'
9+
jupytext_version: 1.14.5
10+
kernelspec:
11+
display_name: Python 3 (ipykernel)
12+
language: python
13+
name: python3
14+
---
15+
16+
quartodoc has 4 main pieces:
17+
18+
* Builder: the class responsible for reading a `_quarto.yml`, and generating docs.
19+
* Layout: a specification of the docs, that the builder enhances to fully specify "what should get rendered and how?".
20+
* Docstring objects: a representation of parsed docstrings, and the python objects they belong to.
21+
* Renderer: the class responsible for rendering layouts and doc objects.
22+
23+
```{python}
24+
from quartodoc import Builder, layout, get_object, MdRenderer, preview
25+
```
26+
27+
## Builder
28+
29+
```{python}
30+
config = {"quartodoc":
31+
{
32+
"package": "quartodoc",
33+
"style": "pkgdown",
34+
"sections": [
35+
{
36+
"title": "some section",
37+
"desc": "some description",
38+
"contents": [
39+
"get_object",
40+
"MdRenderer"
41+
]
42+
}
43+
]
44+
}
45+
}
46+
builder = Builder.from_quarto_config(config)
47+
```
48+
49+
```{python}
50+
preview(builder.layout)
51+
```
52+
53+
```{python}
54+
blueprint = builder.do_blueprint()
55+
preview(blueprint, max_depth=6)
56+
```
57+
58+
## Layout
59+
60+
The layout classes represent documentation to build.
61+
62+
See the [layouts API reference](reference/layout.qmd).
63+
64+
* Section: a section of documentation, with a title and description.
65+
* Page: represents a page of documentation.
66+
* Doc: represents a python object and its docstring to render.
67+
* DocClass, DocModule: has a members field.
68+
* Auto: an object (e.g. function) to look up, and turn into the appropriate Doc class.
69+
This is the default class used in the config, and has options for customizing
70+
documentation, such as how to document members of a class.
71+
72+
Note that classes like Doc include docstring objects, that are the result of
73+
statically analyzing the target library with griffe.
74+
75+
```{python}
76+
doc_page = blueprint.sections[0].contents[0]
77+
preview(doc_page, max_depth = 4)
78+
```
79+
80+
## Docstring objects
81+
82+
```{python}
83+
obj = get_object("quartodoc", "get_object")
84+
```
85+
86+
## Renderer
87+
88+
The renderer is responsible for converting layout and docstring objects into a
89+
string of documentation (e.g. markdown).
90+
91+
```{python}
92+
renderer = MdRenderer()
93+
94+
print(
95+
renderer.render(obj)[:150]
96+
)
97+
```
98+
99+
Note that it is also capable of rendering most layout objects, such as a Page.
100+
101+
```{python}
102+
doc_page = blueprint.sections[0].contents[0]
103+
104+
# not run, since it produces a lot of output!
105+
# renderer.render(doc_page)
106+
```

docs/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/* css styles */
2+
3+
.cell-output pre code {
4+
white-space: pre-wrap;
5+
}

0 commit comments

Comments
 (0)