|
| 1 | +# Overview |
1 | 2 |
|
2 |
| -# quartodoc |
| 3 | +**quartodoc** lets you quickly generate Python package API reference |
| 4 | +documentation using Markdown and [Quarto](https://quarto.org). quartodoc |
| 5 | +is designed as an alternative to |
| 6 | +[Sphinx](https://www.sphinx-doc.org/en/master/). |
3 | 7 |
|
4 |
| -Generate python API documentation for quarto. |
| 8 | +Check out the below screencast for a walkthrough of creating a |
| 9 | +documentation site, or read on for instructions. |
5 | 10 |
|
6 |
| -## Install |
| 11 | +<p align="center"> |
| 12 | +<a href="https://www.loom.com/share/fb4eb736848e470b8409ba46b514e2ed"> |
| 13 | +<img src="https://cdn.loom.com/sessions/thumbnails/fb4eb736848e470b8409ba46b514e2ed-00001.gif" width="75%"> |
| 14 | +</a> |
| 15 | +</p> |
7 | 16 |
|
8 |
| - pip install quartodoc |
| 17 | +<br> |
9 | 18 |
|
10 |
| -Or for the latest changes: |
| 19 | +## Installation |
11 | 20 |
|
12 |
| - python3 -m pip install -e git+https://github.com/machow/quartodoc.git#egg=quartodoc |
13 |
| - |
14 |
| -## Basic use |
15 |
| - |
16 |
| -``` python |
17 |
| -from quartodoc import get_function, MdRenderer |
| 21 | +``` bash |
| 22 | +python -m pip install quartodoc |
| 23 | +``` |
18 | 24 |
|
19 |
| -# get function object --- |
20 |
| -f_obj = get_function("quartodoc", "get_function") |
| 25 | +or from GitHub |
21 | 26 |
|
22 |
| -# render --- |
23 |
| -renderer = MdRenderer(header_level = 1) |
24 |
| -print( |
25 |
| - renderer.to_md(f_obj) |
26 |
| -) |
| 27 | +``` bash |
| 28 | +python -m pip install git+https://github.com/machow/quartodoc.git |
27 | 29 | ```
|
28 | 30 |
|
29 |
| - # get_function |
| 31 | +<div> |
30 | 32 |
|
31 |
| - `get_function(module: str, func_name: str, parser: str = 'numpy')` |
| 33 | +> **Install Quarto** |
| 34 | +> |
| 35 | +> If you haven’t already, you’ll need to [install |
| 36 | +> Quarto](https://quarto.org/docs/get-started/) before you can use |
| 37 | +> quartodoc. |
32 | 38 |
|
33 |
| - Fetch a function. |
| 39 | +</div> |
34 | 40 |
|
35 |
| - ## Parameters |
36 |
| - |
37 |
| - | Name | Type | Description | Default | |
38 |
| - |-------------|--------|----------------------------|-----------| |
39 |
| - | `module` | str | A module name. | required | |
40 |
| - | `func_name` | str | A function name. | required | |
41 |
| - | `parser` | str | A docstring parser to use. | `'numpy'` | |
| 41 | +## Basic use |
42 | 42 |
|
43 |
| - ## Examples |
| 43 | +Getting started with quartodoc takes two steps: configuring quartodoc, |
| 44 | +then generating documentation pages for your library. |
| 45 | + |
| 46 | +You can configure quartodoc alongside the rest of your Quarto site in |
| 47 | +the |
| 48 | +[`_quarto.yml`](https://quarto.org/docs/projects/quarto-projects.html) |
| 49 | +file you are already using for Quarto. To [configure |
| 50 | +quartodoc](https://machow.github.io/quartodoc/get-started/basic-docs.html#site-configuration), |
| 51 | +you need to add a `quartodoc` section to the top level your |
| 52 | +`_quarto.yml` file. Below is a minimal example of a configuration that |
| 53 | +documents the `quartodoc` package: |
| 54 | + |
| 55 | +``` yaml |
| 56 | +project: |
| 57 | + type: website |
| 58 | + |
| 59 | +# tell quarto to read the generated sidebar |
| 60 | +metadata-files: |
| 61 | + - _sidebar.yml |
| 62 | + |
| 63 | + |
| 64 | +quartodoc: |
| 65 | + # the name used to import the package you want to create reference docs for |
| 66 | + package: quartodoc |
| 67 | + |
| 68 | + # write sidebar data to this file |
| 69 | + sidebar: _sidebar.yml |
| 70 | + |
| 71 | + sections: |
| 72 | + - title: Some functions |
| 73 | + desc: Functions to inspect docstrings. |
| 74 | + contents: |
| 75 | + # the functions being documented in the package. |
| 76 | + # you can refer to anything: class methods, modules, etc.. |
| 77 | + - get_object |
| 78 | + - preview |
| 79 | +``` |
44 | 80 |
|
45 |
| - ```python |
46 |
| - >>> get_function("quartodoc", "get_function") |
47 |
| - <Function('get_function', ... |
48 |
| - ``` |
| 81 | +Now that you have configured quartodoc, you can generate the reference |
| 82 | +API docs with the following command: |
49 | 83 |
|
50 |
| -## How it works |
| 84 | +``` bash |
| 85 | +quartodoc build |
| 86 | +``` |
51 | 87 |
|
52 |
| -quartodoc consists of two pieces: |
| 88 | +This will create a `reference/` directory with an `index.qmd` and |
| 89 | +documentation pages for listed functions, like `get_object` and |
| 90 | +`preview`. |
53 | 91 |
|
54 |
| -- **collection**: using the library |
55 |
| - [griffe](https://github.com/mkdocstrings/griffe) to statically collect |
56 |
| - information about functions and classes in a program. |
57 |
| -- **docstring parsing**: also handled by griffe, which breaks it into a |
58 |
| - tree structure. |
59 |
| -- **docstring rendering**: use plum-dispatch on methods like |
60 |
| - MdRenderer.to_md to decide how to visit and render each piece of the |
61 |
| - tree (e.g. the examples section, a parameter, etc..). |
| 92 | +Finally, preview your website with quarto: |
62 | 93 |
|
63 |
| -Here is a quick example of how you can grab a function from griffe and |
64 |
| -walk through it. |
| 94 | +``` bash |
| 95 | +quarto preview |
| 96 | +``` |
65 | 97 |
|
66 |
| -``` python |
67 |
| -from griffe.loader import GriffeLoader |
68 |
| -from griffe.docstrings.parsers import Parser |
| 98 | +## Rebuilding site |
69 | 99 |
|
70 |
| -griffe = GriffeLoader(docstring_parser = Parser("numpy")) |
71 |
| -mod = griffe.load_module("quartodoc") |
| 100 | +You can preview your `quartodoc` site using the following commands: |
72 | 101 |
|
73 |
| -f_obj = mod._modules_collection["quartodoc.get_function"] |
74 |
| -``` |
| 102 | +First, watch for changes to the library you are documenting so that your |
| 103 | +docs will automatically re-generate: |
75 | 104 |
|
76 |
| -``` python |
77 |
| -f_obj.name |
| 105 | +``` bash |
| 106 | +quartodoc build --watch |
78 | 107 | ```
|
79 | 108 |
|
80 |
| - 'get_function' |
| 109 | +Second, preview your site: |
81 | 110 |
|
82 |
| -``` python |
83 |
| -docstring = f_obj.docstring.parsed |
84 |
| -docstring |
| 111 | +``` bash |
| 112 | +quarto preview |
85 | 113 | ```
|
86 | 114 |
|
87 |
| - [<griffe.docstrings.dataclasses.DocstringSectionText at 0x105a2c310>, |
88 |
| - <griffe.docstrings.dataclasses.DocstringSectionParameters at 0x10f7961f0>, |
89 |
| - <griffe.docstrings.dataclasses.DocstringSectionExamples at 0x10f7965b0>] |
90 |
| - |
91 |
| -Note that quartodoc’s MdRenderer can be called on any part of the parsed |
92 |
| -docstring. |
93 |
| - |
94 |
| -``` python |
95 |
| -from quartodoc import MdRenderer |
96 |
| - |
97 |
| -renderer = MdRenderer() |
98 |
| - |
99 |
| -print( |
100 |
| - renderer.to_md(docstring[1]) |
101 |
| -) |
| 115 | +## Looking up objects |
| 116 | + |
| 117 | +Generating API reference docs for Python objects involves two pieces of |
| 118 | +configuration: |
| 119 | + |
| 120 | +1. the package name. |
| 121 | +2. a list of objects for content. |
| 122 | + |
| 123 | +quartodoc can look up a wide variety of objects, including functions, |
| 124 | +modules, classes, attributes, and methods: |
| 125 | + |
| 126 | +``` yaml |
| 127 | +quartodoc: |
| 128 | + package: quartodoc |
| 129 | + sections: |
| 130 | + - title: Some section |
| 131 | + desc: "" |
| 132 | + contents: |
| 133 | + - get_object # function: quartodoc.get_object |
| 134 | + - ast.preview # submodule func: quartodoc.ast.preview |
| 135 | + - MdRenderer # class: quartodoc.MdRenderer |
| 136 | + - MdRenderer.render # method: quartodoc.MDRenderer.render |
| 137 | + - renderers # module: quartodoc.renderers |
102 | 138 | ```
|
103 | 139 |
|
104 |
| - | Name | Type | Description | Default | |
105 |
| - |-------------|--------|----------------------------|-----------| |
106 |
| - | `module` | str | A module name. | required | |
107 |
| - | `func_name` | str | A function name. | required | |
108 |
| - | `parser` | str | A docstring parser to use. | `'numpy'` | |
| 140 | +The functions listed in `contents` are assumed to be imported from the |
| 141 | +package. |
| 142 | + |
| 143 | +## Learning more |
| 144 | + |
| 145 | +Go [to the next |
| 146 | +page](https://machow.github.io/quartodoc/get-started/basic-docs.html) to |
| 147 | +learn how to configure quartodoc sites, or check out these handy pages: |
| 148 | + |
| 149 | +- [Examples |
| 150 | + page](https://machow.github.io/quartodoc/examples/index.html): sites |
| 151 | + using quartodoc. |
| 152 | +- [Tutorials |
| 153 | + page](https://machow.github.io/quartodoc/tutorials/index.html): |
| 154 | + screencasts of building a quartodoc site. |
| 155 | +- [Docstring issues and |
| 156 | + examples](https://machow.github.io/quartodoc/get-started/docstring-examples.html): |
| 157 | + common issues when formatting docstrings. |
| 158 | +- [Programming, the big |
| 159 | + picture](https://machow.github.io/quartodoc/get-started/dev-big-picture.html): |
| 160 | + the nitty gritty of how quartodoc works, and how to extend it. |
0 commit comments