Skip to content

Commit b25cd28

Browse files
committed
tweaks to make docs simpler, more comprehensive
1 parent 6c9f852 commit b25cd28

File tree

9 files changed

+138
-48
lines changed

9 files changed

+138
-48
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ README.md: README.qmd
22
quarto render $<
33

44
examples/%/_site: examples/%/_quarto.yml
5+
python -m quartodoc $<
56
quarto render $(dir $<)
67

78
docs/examples/%: examples/%/_site

docs/_quarto.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ website:
7474
style: floating
7575
align: left
7676
contents:
77+
- get-started/overview.qmd
7778
- section: "Basics"
7879
contents:
79-
- get-started/overview.qmd
8080
- get-started/basic-docs.qmd
8181
- get-started/crossrefs.qmd
8282
- section: "Advanced"

docs/get-started/basic-docs.qmd

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,82 @@
11
---
2-
title: Generating docs
2+
title: Configuring docs
33
jupyter:
44
kernelspec:
55
display_name: Python 3 (ipykernel)
66
language: python
77
name: python3
88
---
99

10-
Coming soon!
10+
## Adding configuration
11+
12+
quartodoc is configured by adding a `quartodoc` section to your `_quarto.yml`:
13+
14+
```yaml
15+
quartodoc:
16+
style: single-page
17+
dir: reference
18+
package: quartodoc
19+
sections:
20+
- title: Some functions
21+
desc: Functions to inspect docstrings.
22+
contents:
23+
- get_object
24+
- preview
25+
```
26+
27+
## Options
28+
29+
The `quartodoc` section takes a `style` field, specifying which [](`quartodoc.Builder`)
30+
to use (currently "pkgdown" or "single-page"; see [Examples](/examples/)).
31+
32+
```{python}
33+
#| echo: false
34+
#| output: asis
35+
from quartodoc import get_object, MdRenderer
36+
37+
obj = get_object("quartodoc", "Builder")
38+
renderer = MdRenderer()
39+
40+
doc_parts = obj.docstring.parsed
41+
doc_params = [entry for entry in doc_parts if entry.kind.name == "parameters"][0]
42+
print(renderer.to_md(doc_params))
43+
```
44+
45+
## Section options
46+
47+
The `sections` field defines which functions to document.
48+
49+
| Name | Type | Description |
50+
| ---- | ---- | ----------- |
51+
| title | str | A title for the section |
52+
| desc | str | A description for the section |
53+
| contents | list[str] | A list of functions to document |
54+
55+
56+
## Looking up functions
57+
58+
Finding functions to document involves two pieces of configuration:
59+
60+
* the package name.
61+
* a list of functions for content.
62+
63+
```yaml
64+
quartodoc:
65+
package: quartodoc
66+
sections:
67+
- contents:
68+
# top-level function: quartodoc.get_object
69+
- get_object
70+
71+
# top-level class: quartodoc.MdRenderer
72+
- MdRenderer
73+
74+
# submodule function: quartodoc.ast.preview
75+
- ast.preview
76+
```
77+
78+
The functions listed in `contents` are assumed to be imported from the package.
79+
80+
### Class methods
81+
82+
Currently, quartodoc can't look up class methods. (Though this would be quick to implement!).

docs/get-started/overview.qmd

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Overview
3+
aliases:
4+
- ../index.html
35
jupyter:
46
kernelspec:
57
display_name: Python 3 (ipykernel)
@@ -12,7 +14,8 @@ quartodoc is work in progress!
1214
:::
1315

1416
quartodoc let's you quickly generate python package documentation,
15-
using markdown and quarto. It is designed as an alternative to sphinx.
17+
using markdown and [quarto](https://quarto.org).
18+
It is designed as an alternative to Sphinx.
1619

1720
## Installation
1821

@@ -25,6 +28,11 @@ python -m pip install git+https://github.com/machow/quartodoc.git
2528

2629
## Basic use
2730

31+
Getting started with quartodoc takes two steps: configuring a quarto website,
32+
and generating documentation pages for your library.
33+
34+
First, create a `_quarto.yml` file with the following:
35+
2836
```yaml
2937
project:
3038
type: website
@@ -37,26 +45,50 @@ quartodoc:
3745
package: quartodoc
3846
sections:
3947
- title: Some functions
40-
desc: These functions inspect and parse docstrings.
48+
desc: Functions to inspect docstrings.
4149
contents:
4250
- get_object
4351
- preview
4452
```
4553
46-
## Goals
54+
Next, run this command to generate your API pages:
55+
56+
```bash
57+
python -m quartodoc
58+
```
59+
60+
This should create a `reference/` directory with an `index.qmd` and documentation
61+
pages for listed functions, like `get_object` and `preview`.
62+
63+
Finally, preview your website with quarto:
64+
65+
```bash
66+
quarto preview
67+
```
68+
69+
## Key Features
4770

4871
* Load docstrings (with [griffe](https://github.com/mkdocstrings/griffe))
4972
* Render docstrings (e.g. with [MdRenderer](/api/#sec-MdRenderer))
5073
* Enable cross references to function documentation.
5174
- Link to functions within a doc.
5275
- Link to functions in other docs.
5376
- Generate an inventory file for other docs to link to yours.
54-
* (WIP) Generate high-level summaries.
55-
- Class summaries, with methods.
77+
* Generate high-level summaries.
78+
- First line of docstring used as description.
79+
- Class doc pages have table of class attributes.
5680
- Tables of function names and descriptions.
5781

58-
## Different documentation structures
82+
## Example sites
83+
84+
| style | source | layout |
85+
| ----- | ------ | ------ |
86+
| [pkgdown] | [github][pkgdown-code] | Index page with a title and short description for functions listed in each section. Each function gets its own documentation page. |
87+
| [single-page] | [github][sp-code] | Index page has function documentation embedded on it. |
88+
89+
: {tbl-colwidths="[20, 20, 60]"}
5990

60-
* All functions listed on a single page.
61-
* Functions split across a few pages (e.g. parsers, renderers).
62-
* Each function gets its own page.
91+
[pkgdown]: /examples/pkgdown/reference
92+
[pkgdown-code]: https://github.com/machow/quartodoc/tree/main/examples/pkgdown
93+
[single-page]: /examples/single-page/reference
94+
[sp-code]: https://github.com/machow/quartodoc/tree/main/examples/single-page

docs/get-started/quickstart.qmd

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/index.qmd

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/pkgdown/reference/get_object.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Fetch a griffe object.
1212
| `object_name` | str | A function name. | required |
1313
| `parser` | str | A docstring parser to use. | `'numpy'` |
1414

15-
See Also
16-
--------
15+
### See_Also
16+
1717
get_function: a deprecated function.
1818

1919
### Examples

quartodoc/__main__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import click
2+
import contextlib
3+
import os
4+
5+
from pathlib import Path
26

37
from .autosummary import Builder
48

59

10+
@contextlib.contextmanager
11+
def chdir(new_dir):
12+
prev = os.getcwd()
13+
os.chdir(new_dir)
14+
try:
15+
yield new_dir
16+
finally:
17+
os.chdir(prev)
18+
19+
620
@click.command()
721
@click.argument("config", default="_quarto.yml")
822
@click.option("--dry-run", is_flag=True, default=False)
@@ -12,7 +26,8 @@ def build(config, dry_run):
1226
if dry_run:
1327
click.echo(builder.render_index())
1428
else:
15-
builder.build()
29+
with chdir(Path(config).parent):
30+
builder.build()
1631

1732

1833
if __name__ == "__main__":

quartodoc/autosummary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ class Builder:
9494
9595
Parameters
9696
----------
97-
sections: ConfigSection
98-
A list of sections, with items to document.
9997
package: str
10098
The name of the package.
99+
sections: ConfigSection
100+
A list of sections, with items to document.
101101
version:
102102
The package version. By default this attempts to look up the current package
103103
version (TODO).
@@ -141,8 +141,8 @@ def __init_subclass__(cls, **kwargs):
141141

142142
def __init__(
143143
self,
144-
sections: "list[Any]",
145144
package: str,
145+
sections: "list[Any]",
146146
version: "str | None" = None,
147147
dir: str = "reference",
148148
title: str = "Function reference",

0 commit comments

Comments
 (0)