Skip to content

Commit f23a60a

Browse files
pre-commit-ci[bot]henryiii
authored andcommitted
style: pre-commit fixes
1 parent 7b4047a commit f23a60a

File tree

2 files changed

+131
-80
lines changed

2 files changed

+131
-80
lines changed

docs/pages/guides/docs.md

Lines changed: 118 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ parent: Topical Guides
1212

1313
Documentation used to require learning reStructuredText (sometimes referred to
1414
as reST / rST), but today we have great choices for documentation in markdown,
15-
the same format used by GitHub, Wikipedia, and others. This guide covers Sphinx and Mkdocs,
16-
and uses the modern MyST plugin to get Markdown support.
15+
the same format used by GitHub, Wikipedia, and others. This guide covers Sphinx
16+
and Mkdocs, and uses the modern MyST plugin to get Markdown support.
1717

1818
{: .note-title }
1919

@@ -23,19 +23,22 @@ and uses the modern MyST plugin to get Markdown support.
2323
> commonly used, and have somewhat fewer examples and plugins. They are:
2424
>
2525
> - [Sphinx](https://www.sphinx-doc.org/en/master/): A popular documentation
26-
> framework for scientific libraries with a history of close usage with scientific
27-
> tools like LaTeX. Examples include [astropy](https://docs.astropy.org/en/stable/index_user_docs.html)
28-
> and [corner](https://docs.astropy.org/en/stable/index_user_docs.html).
26+
> framework for scientific libraries with a history of close usage with
27+
> scientific tools like LaTeX. Examples include
28+
> [astropy](https://docs.astropy.org/en/stable/index_user_docs.html) and
29+
> [corner](https://docs.astropy.org/en/stable/index_user_docs.html).
2930
> - [MkDocs](https://www.mkdocs.org): A from-scratch new documentation system
3031
> based on markdown and HTML. Less support for man pages & PDFs than Sphinx,
3132
> since it doesn't use docutils. Has over
3233
> [200 plugins](https://github.com/mkdocs/catalog) - they are much easier to
3334
> write than Sphinx. Example sites include [hatch](https://hatch.pypa.io),
3435
> [PDM](https://pdm.fming.dev),
3536
> [cibuildwheel](https://cibuildwheel.readthedocs.io),
36-
> [Textual](https://textual.textualize.io),
37-
> [pipx](https://pypa.github.io/pipx/), [Pydantic](https://docs.pydantic.dev/latest/),
38-
> [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/)
3942
> - [JupyterBook](https://jupyterbook.org): A powerful system for rendering a
4043
> collection of notebooks using Sphinx internally. Can also be used for docs,
4144
> though, see [echopype](https://echopype.readthedocs.io).
@@ -71,15 +74,14 @@ with render_cookie() as package:
7174

7275
## Hand-written docs
7376

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.
7679

7780
{% tabs %}{% tab sphinx Sphinx %}
7881

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`:
8385

8486
### conf.py
8587

@@ -256,14 +258,23 @@ docs = [
256258
"sphinx-autodoc-typehints",
257259
]
258260
```
261+
259262
You should use `--group=docs` when using uv or pip to install.
260263

261-
{% endtab %}
262-
{% tab mkdocs MkDocs %}
264+
{% endtab %} {% tab mkdocs MkDocs %}
263265

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
268+
[Getting started](https://squidfunk.github.io/mkdocs-material/getting-started/)
269+
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`.
265274

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`:
267278

268279
```toml
269280
[dependency-groups]
@@ -277,9 +288,16 @@ docs = [
277288
]
278289
```
279290

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.
281293

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.
283301

284302
Here's the whole file for completeness. We'll break it into sections underneath.
285303

@@ -301,7 +319,7 @@ theme:
301319
- navigation.tracking
302320
- toc.follow
303321
palette:
304-
# See options to customise your colour scheme here:
322+
# See options to customise your colour scheme here:
305323
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/
306324
- media: "(prefers-color-scheme: light)"
307325
scheme: default
@@ -332,7 +350,6 @@ plugins:
332350
show_signature_annotations: true
333351
search: {}
334352

335-
336353
nav:
337354
- Home: index.md
338355
- Python API: api.md
@@ -348,13 +365,29 @@ repo_name: "wayne_industries/some_project"
348365
repo_url: "https://github.com/wayne_industries/some_project"
349366
```
350367
351-
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
372+
GitHub or GitLab brand is unwanted.
373+
374+
Extra search features are documented
375+
[here](https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/),
376+
and the three enabled are autocomplete for search suggestions (`search.suggest`)
377+
and highlighting search terms after a user clicks on a search result
378+
(`search.highlight`).
379+
380+
For navigation plugins (documented
381+
[here](https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/)),
382+
we request the side navigation to be expanded by default (`naviation.expand`)
383+
and that the URL autoupdate to the latest anchor as a user scrolls through the
384+
page (`naviation.tracking`). Finally, we request that the current user section
385+
is always shown and highlight in the sidebar via `toc.follow`.
386+
387+
In the palette section (documented
388+
[here](https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/))
389+
you can easily modify the scheme, icons, primary colours, and accents for both
390+
light and dark themes.
358391

359392
```yaml
360393
theme:
@@ -368,7 +401,7 @@ theme:
368401
- navigation.tracking
369402
- toc.follow
370403
palette:
371-
# See options to customise your colour scheme here:
404+
# See options to customise your colour scheme here:
372405
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/
373406
- media: "(prefers-color-scheme: light)"
374407
scheme: default
@@ -384,10 +417,11 @@ theme:
384417

385418
Onto the best part of MkDocs: it's many plugins!
386419

387-
* `search` enabled search functionality.
388-
* [`autorefs`](https://mkdocstrings.github.io/autorefs/) allows easier linking across pages and anchors.
389-
* [`mkdocstrings`](https://mkdocstrings.github.io/) lets you generate reference API documentation from your docstring.
390-
420+
- `search` enabled search functionality.
421+
- [`autorefs`](https://mkdocstrings.github.io/autorefs/) allows easier linking
422+
across pages and anchors.
423+
- [`mkdocstrings`](https://mkdocstrings.github.io/) lets you generate reference
424+
API documentation from your docstring.
391425

392426
```yaml
393427
plugins:
@@ -409,7 +443,10 @@ plugins:
409443
search: {}
410444
```
411445

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.
413450

414451
```yaml
415452
nav:
@@ -453,8 +490,7 @@ build:
453490
<!-- prettier-ignore-end -->
454491
<!-- [[[end]]] -->
455492

456-
{% endtab %}
457-
{% tab mkdocs MkDocs %}
493+
{% endtab %} {% tab mkdocs MkDocs %}
458494

459495
<!-- [[[cog
460496
with code_fence("yaml"):
@@ -481,25 +517,23 @@ build:
481517
<!-- prettier-ignore-end -->
482518
<!-- [[[end]]] -->
483519

484-
485520
{% endtab %} {% endtabs %}
486521

487522
This sets the Read the Docs config version (2 is required) {% rr RTD101 %}.
488523

489524
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).
492527

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.
495530

496531
### noxfile.py additions
497532

498533
Add a session to your `noxfile.py` to generate docs:
499534

500535
{% tabs %} {% tab sphinx Sphinx %}
501536

502-
503537
<!-- [[[cog
504538
with code_fence("python"):
505539
print(noxfile.get_source("docs"))
@@ -540,7 +574,6 @@ def docs(session: nox.Session) -> None:
540574
<!-- prettier-ignore-end -->
541575
<!-- [[[end]]] -->
542576

543-
544577
This is a more complex Nox job just because it's taking some options (the
545578
ability to build and serve instead of just build). The first portion is just
546579
setting up argument parsing so we can serve if building `html`. Then it does
@@ -554,9 +587,7 @@ and run either the autobuild (for `--serve`) or regular build. We could have
554587
just added `python -m http.server` pointing at the built documentation, but
555588
autobuild will rebuild if you change a file while serving.
556589

557-
{% endtab %}
558-
{% tab mkdocs MkDocs %}
559-
590+
{% endtab %} {% tab mkdocs MkDocs %}
560591

561592
<!-- [[[cog
562593
with code_fence("python"):
@@ -577,11 +608,15 @@ def docs(session: nox.Session) -> None:
577608
<!-- prettier-ignore-end -->
578609
<!-- [[[end]]] -->
579610

580-
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).
581617

582618
{% endtab %} {% endtabs %}
583619

584-
585620
## API docs
586621

587622
{% tabs %} {% tab sphinx Sphinx %}
@@ -633,29 +668,37 @@ api/<package-name-here>
633668

634669
Note that your docstrings are still parsed as reStructuredText.
635670

636-
{% endtab %}
637-
{% tab mkdocs MkDocs %}
671+
{% endtab %} {% tab mkdocs MkDocs %}
638672

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.
640677

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:
642683

643684
```markdown
644685
# Documentation for `my_package.my_module`
645686

646687
::: my_package.my_module
647688
```
648689
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`.
650695

651-
{% endtab %}
652-
{% endtabs %}
696+
{% endtab %} {% endtabs %}
653697

654698
## Notebooks in docs
655699

656700
{% tabs %} {% tab sphinx Sphinx %}
657701

658-
659702
You can combine notebooks into your docs. The tool for this is `nbsphinx`. If
660703
you want to use it, add `nbsphinx` and `ipykernel` to your documentation
661704
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.
683726
If you want to use Markdown instead of notebooks, you can use jupytext (see
684727
[here](https://nbsphinx.readthedocs.io/en/0.9.2/a-markdown-file.html)).
685728

686-
{% endtab %}
687-
{% tab mkdocs MkDocs %}
729+
{% endtab %} {% tab mkdocs MkDocs %}
688730

689-
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/).
690735

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.
692739

693740
```yaml
694741
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
698745
plugins:
699-
- mkdocs-jupyter
746+
- mkdocs-jupyter
700747
```
701748

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.
752+
For an external example, the
753+
[ChainConsumer docs](https://samreay.github.io/ChainConsumer/generated/gallery/)
754+
show `mkdocs-gallery` in action.
703755

704756
{% endtab %} {% endtabs %}
705757

0 commit comments

Comments
 (0)