You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> [Polars](https://docs.pola.rs/), and [FastAPI](https://fastapi.tiangolo.com/)
37
+
> [Textual](https://textual.textualize.io),
38
+
> [pipx](https://pypa.github.io/pipx/),
39
+
> [Pydantic](https://docs.pydantic.dev/latest/),
40
+
> [Polars](https://docs.pola.rs/), and
41
+
> [FastAPI](https://fastapi.tiangolo.com/)
39
42
> -[JupyterBook](https://jupyterbook.org): A powerful system for rendering a
40
43
> collection of notebooks using Sphinx internally. Can also be used for docs,
41
44
> though, see [echopype](https://echopype.readthedocs.io).
@@ -71,15 +74,14 @@ with render_cookie() as package:
71
74
72
75
## Hand-written docs
73
76
74
-
Create `docs/` directory within your project (next to `src/`). From here,
75
-
Sphinx and MkDocs diverge.
77
+
Create `docs/` directory within your project (next to `src/`). From here, Sphinx
78
+
and MkDocs diverge.
76
79
77
80
{% tabs %}{% tab sphinx Sphinx %}
78
81
79
-
There is a sphinx-quickstart tool, but it creates unnecessary files (make/bat, we recommend
80
-
a cross-platform noxfile instead), and uses rST instead of Markdown. Instead,
81
-
this is our recommended starting point for `conf.py`:
82
-
82
+
There is a sphinx-quickstart tool, but it creates unnecessary files (make/bat,
83
+
we recommend a cross-platform noxfile instead), and uses rST instead of
84
+
Markdown. Instead, this is our recommended starting point for `conf.py`:
83
85
84
86
### conf.py
85
87
@@ -256,14 +258,23 @@ docs = [
256
258
"sphinx-autodoc-typehints",
257
259
]
258
260
```
261
+
259
262
You should use `--group=docs` when using uv or pip to install.
260
263
261
-
{% endtab %}
262
-
{% tab mkdocs MkDocs %}
264
+
{% endtab %} {% tab mkdocs MkDocs %}
263
265
264
-
While the cookie cutter creates a basic structure for your MkDocs (a top level `mkdocs.yml` file and the `docs` directory), you can also follow the official [Getting started](https://squidfunk.github.io/mkdocs-material/getting-started/) guide instead. Note, however, instead of the `pip` install, it is better practise install your documentation dependencies via `pyproject.toml` and then when you run your `uv sync` to install dependencies, you can explicitly ask for the `docs` group to be installed via `uv sync --group=docs` or `uv sync --all-groups`.
266
+
While the cookie cutter creates a basic structure for your MkDocs (a top level
267
+
`mkdocs.yml` file and the `docs` directory), you can also follow the official
guide instead. Note, however, instead of the `pip` install, it is better
270
+
practise install your documentation dependencies via `pyproject.toml` and then
271
+
when you run your `uv sync` to install dependencies, you can explicitly ask for
272
+
the `docs` group to be installed via `uv sync --group=docs` or
273
+
`uv sync --all-groups`.
265
274
266
-
If you selected the `mkdocs` option when using the template cookie-cutter repository, you will already have this group. Otherwise, add to your `pyproject.toml`:
275
+
If you selected the `mkdocs` option when using the template cookie-cutter
276
+
repository, you will already have this group. Otherwise, add to your
277
+
`pyproject.toml`:
267
278
268
279
```toml
269
280
[dependency-groups]
@@ -277,9 +288,16 @@ docs = [
277
288
]
278
289
```
279
290
280
-
These dependencies include several common plugins---such as generating reference API documentation from docstrings---to make life easier.
291
+
These dependencies include several common plugins---such as generating reference
292
+
API documentation from docstrings---to make life easier.
281
293
282
-
Similar to Sphinx, MkDocs puts your written documentation into the `/docs` directory, but also has a top-level `mkdocs.yml` configuration file. You can see the [minimal configuration for the file here](https://squidfunk.github.io/mkdocs-material/creating-your-site/#minimal-configuration), which is only four lines. However, the `mkdocs.yml` file bundled with the template repository have many options pre-configured. Let's run through an example configuration now.
294
+
Similar to Sphinx, MkDocs puts your written documentation into the `/docs`
295
+
directory, but also has a top-level `mkdocs.yml` configuration file. You can see
296
+
the
297
+
[minimal configuration for the file here](https://squidfunk.github.io/mkdocs-material/creating-your-site/#minimal-configuration),
298
+
which is only four lines. However, the `mkdocs.yml` file bundled with the
299
+
template repository have many options pre-configured. Let's run through an
300
+
example configuration now.
283
301
284
302
Here's the whole file for completeness. We'll break it into sections underneath.
285
303
@@ -301,7 +319,7 @@ theme:
301
319
- navigation.tracking
302
320
- toc.follow
303
321
palette:
304
-
# See options to customise your colour scheme here:
322
+
# See options to customise your colour scheme here:
After that, we can configure the visual theming for the the site. The repo icon is what appears in the top-right of the site next to the link to your GitHub/GitLab/etc, and you can peruse [other FontAwesome icons here](https://fontawesome.com/icons) if the default GitHub or GitLab brand is unwanted.
352
-
353
-
Extra search features are documented [here](https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/), and the three enabled are autocomplete for search suggestions (`search.suggest`) and highlighting search terms after a user clicks on a search result (`search.highlight`).
354
-
355
-
For navigation plugins (documented [here](https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/)), we request the side navigation to be expanded by default (`naviation.expand`) and that the URL autoupdate to the latest anchor as a user scrolls through the page (`naviation.tracking`). Finally, we request that the current user section is always shown and highlight in the sidebar via `toc.follow`.
356
-
357
-
In the palette section (documented [here](https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/)) you can easily modify the scheme, icons, primary colours, and accents for both light and dark themes.
368
+
After that, we can configure the visual theming for the the site. The repo icon
369
+
is what appears in the top-right of the site next to the link to your
370
+
GitHub/GitLab/etc, and you can peruse
371
+
[other FontAwesome icons here](https://fontawesome.com/icons) if the default
- [`mkdocstrings`](https://mkdocstrings.github.io/) lets you generate reference
424
+
API documentation from your docstring.
391
425
392
426
```yaml
393
427
plugins:
@@ -409,7 +443,10 @@ plugins:
409
443
search: {}
410
444
```
411
445
412
-
Finally, we have to define the actual structure of our site by providing the primary navigation sidebar layout. Here we have three top-level links, one for the home page and one where all the generated API documentation from `mkdocstrings` will live.
446
+
Finally, we have to define the actual structure of our site by providing the
447
+
primary navigation sidebar layout. Here we have three top-level links, one for
448
+
the home page and one where all the generated API documentation from
449
+
`mkdocstrings`will live.
413
450
414
451
```yaml
415
452
nav:
@@ -453,8 +490,7 @@ build:
453
490
<!-- prettier-ignore-end -->
454
491
<!-- [[[end]]] -->
455
492
456
-
{% endtab %}
457
-
{% tab mkdocs MkDocs %}
493
+
{% endtab %} {% tab mkdocs MkDocs %}
458
494
459
495
<!-- [[[cog
460
496
with code_fence("yaml"):
@@ -481,25 +517,23 @@ build:
481
517
<!-- prettier-ignore-end -->
482
518
<!-- [[[end]]] -->
483
519
484
-
485
520
{% endtab %} {% endtabs %}
486
521
487
522
This sets the Read the Docs config version (2 is required) {% rr RTD101 %}.
488
523
489
524
The `build` table is the modern way to specify a runner. You need an `os` (a
490
-
modern Ubuntu should be fine) {% rr RTD102 %} and a `tools` table (we'll use Python
491
-
{% rr RTD103 %}, several languages are supported here).
525
+
modern Ubuntu should be fine) {% rr RTD102 %} and a `tools` table (we'll use
526
+
Python {% rr RTD103 %}, several languages are supported here).
492
527
493
-
Finally, we have a `commands` table which describes how to install our dependencies and
494
-
build the documentation into the ReadTheDocs output directory.
528
+
Finally, we have a `commands` table which describes how to install our
529
+
dependencies and build the documentation into the ReadTheDocs output directory.
495
530
496
531
### noxfile.py additions
497
532
498
533
Add a session to your `noxfile.py` to generate docs:
This Nox job will invoke MkDocs to serve a live copy of your documentation under a local endpoint, such as `http://localhost:8080` (the link will be in the job output). By requesting a `serve` instead of a `build`, any time documentation or the source code is changed, the documentation will automatically update. For documentation on how to configure what directories are watched for changes, [consult the MkDocs configuration page](https://www.mkdocs.org/user-guide/configuration/#live-reloading).
611
+
This Nox job will invoke MkDocs to serve a live copy of your documentation under
612
+
a local endpoint, such as `http://localhost:8080` (the link will be in the job
613
+
output). By requesting a `serve` instead of a `build`, any time documentation or
614
+
the source code is changed, the documentation will automatically update. For
615
+
documentation on how to configure what directories are watched for changes,
616
+
[consult the MkDocs configuration page](https://www.mkdocs.org/user-guide/configuration/#live-reloading).
581
617
582
618
{% endtab %} {% endtabs %}
583
619
584
-
585
620
## API docs
586
621
587
622
{% tabs %} {% tab sphinx Sphinx %}
@@ -633,29 +668,37 @@ api/<package-name-here>
633
668
634
669
Note that your docstrings are still parsed as reStructuredText.
635
670
636
-
{% endtab %}
637
-
{% tab mkdocs MkDocs %}
671
+
{% endtab %} {% tab mkdocs MkDocs %}
638
672
639
-
API documentation can be built from your docstring using the `mkdocstrings` plugin, as referenced previously. Unlike with Sphinx, which requires a direct invocation of `sphinx-apidoc`, MkDocs plugins are integrated into the MkDocs build.
673
+
API documentation can be built from your docstring using the `mkdocstrings`
674
+
plugin, as referenced previously. Unlike with Sphinx, which requires a direct
675
+
invocation of `sphinx-apidoc`, MkDocs plugins are integrated into the MkDocs
676
+
build.
640
677
641
-
All `mkdocstrings` requires is your markdown files to specify what module, class, or function you would like documented in said file. See the [`mkdocstring` Usage page](https://mkdocstrings.github.io/usage/) for more details, but for a minimal example, if you add an `api.md` file and set its contents to:
678
+
All `mkdocstrings` requires is your markdown files to specify what module,
679
+
class, or function you would like documented in said file. See the
680
+
[`mkdocstring` Usage page](https://mkdocstrings.github.io/usage/) for more
681
+
details, but for a minimal example, if you add an `api.md` file and set its
682
+
contents to:
642
683
643
684
```markdown
644
685
# Documentation for `my_package.my_module`
645
686
646
687
::: my_package.my_module
647
688
```
648
689
649
-
Where the triple colon syntax is used to specify what documentation you would like built. In this case, we are asking to document the entire module `my_class` (and all classes and functions within it) which is located in `my_package`. You could instead ask for only a single component inside your module by being more specific, like `::: my_package.my_module.MyClass`.
690
+
Where the triple colon syntax is used to specify what documentation you would
691
+
like built. In this case, we are asking to document the entire module `my_class`
692
+
(and all classes and functions within it) which is located in `my_package`. You
693
+
could instead ask for only a single component inside your module by being more
694
+
specific, like `::: my_package.my_module.MyClass`.
650
695
651
-
{% endtab %}
652
-
{% endtabs %}
696
+
{% endtab %} {% endtabs %}
653
697
654
698
## Notebooks in docs
655
699
656
700
{% tabs %} {% tab sphinx Sphinx %}
657
701
658
-
659
702
You can combine notebooks into your docs. The tool for this is `nbsphinx`. If
660
703
you want to use it, add `nbsphinx` and `ipykernel` to your documentation
661
704
requirements, add `"nbsphinx"` to your `conf.py`'s `extensions =` list, and add
@@ -683,23 +726,32 @@ for this to work. CI services like readthedocs usually have it installed.
683
726
If you want to use Markdown instead of notebooks, you can use jupytext (see
You can combine notebooks into your docs. The plugin for this is `mkdocs-jupyter`, and configuration is detailed [here](https://github.com/danielfrg/mkdocs-jupyter) and you can find examples [here](https://mkdocs-jupyter.danielfrg.com/).
731
+
You can combine notebooks into your docs. The plugin for this is
732
+
`mkdocs-jupyter`, and configuration is detailed
733
+
[here](https://github.com/danielfrg/mkdocs-jupyter) and you can find examples
734
+
[here](https://mkdocs-jupyter.danielfrg.com/).
690
735
691
-
Once you have a notebook (which has been run and populated with results, as the plugin will not execute your notebooks for you), you simply need to add a link to the notebook in your `mkdocs.yml` navigation.
736
+
Once you have a notebook (which has been run and populated with results, as the
737
+
plugin will not execute your notebooks for you), you simply need to add a link
738
+
to the notebook in your `mkdocs.yml` navigation.
692
739
693
740
```yaml
694
741
nav:
695
-
- Home: index.md
696
-
- Notebook page: notebook.ipynb
697
-
- Python file: python_script.py
742
+
- Home: index.md
743
+
- Notebook page: notebook.ipynb
744
+
- Python file: python_script.py
698
745
plugins:
699
-
- mkdocs-jupyter
746
+
- mkdocs-jupyter
700
747
```
701
748
702
-
Note that the `mkdocs-jupyter` plugin allows you to include both python scripts and notebooks. If you have a directory of example python files to run, consider [`mkdocs-gallery`](https://smarie.github.io/mkdocs-gallery/) as an alternative. For an external example, the [ChainConsumer docs](https://samreay.github.io/ChainConsumer/generated/gallery/) show `mkdocs-gallery` in action.
749
+
Note that the `mkdocs-jupyter` plugin allows you to include both python scripts
750
+
and notebooks. If you have a directory of example python files to run, consider
751
+
[`mkdocs-gallery`](https://smarie.github.io/mkdocs-gallery/) as an alternative.
0 commit comments