Skip to content

Commit 8bcc2a1

Browse files
committed
Ensuring copier and cookiecutter work
1 parent 74cae7a commit 8bcc2a1

File tree

13 files changed

+48
-52
lines changed

13 files changed

+48
-52
lines changed

docs/pages/guides/docs.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ docs = [
274274
"pyyaml>=6.0.1",
275275
"mdx-include>=1.4.2",
276276
"mkdocstrings-python>=1.18.2",
277-
"mkdocs-gallery>=0.10.4",
278277
]
279278
```
280279

@@ -321,7 +320,7 @@ plugins:
321320
handlers:
322321
python:
323322
paths: [.]
324-
import:
323+
inventories:
325324
- https://docs.python.org/3/objects.inv
326325
- https://docs.pydantic.dev/latest/objects.inv
327326
options:
@@ -331,18 +330,12 @@ plugins:
331330
show_root_heading: true
332331
show_if_no_docstring: true
333332
show_signature_annotations: true
334-
gallery:
335-
examples_dirs: docs/examples # path to your example scripts
336-
gallery_dirs: docs/generated/gallery # where to save generated gallery
337-
image_srcset: ['2x']
338-
within_subsection_order: FileNameSortKey
339333
search: {}
340334

341335

342336
nav:
343337
- Home: index.md
344338
- Python API: api.md
345-
- Examples: generated/gallery
346339
```
347340
348341
First, the basic site metadata contains authors, repository details, URLs, etc:
@@ -394,7 +387,7 @@ Onto the best part of MkDocs: it's many plugins!
394387
* `search` enabled search functionality.
395388
* [`autorefs`](https://mkdocstrings.github.io/autorefs/) allows easier linking across pages and anchors.
396389
* [`mkdocstrings`](https://mkdocstrings.github.io/) lets you generate reference API documentation from your docstring.
397-
* [`gallery`](https://smarie.github.io/mkdocs-gallery/) turns an `example` directory inside your `docs` folder into accessible documentation, capturing output (such as print statements or generated `matplotlib` figures).
390+
398391

399392
```yaml
400393
plugins:
@@ -403,7 +396,7 @@ plugins:
403396
handlers:
404397
python:
405398
paths: [.]
406-
import:
399+
inventories:
407400
- https://docs.python.org/3/objects.inv
408401
- https://docs.pydantic.dev/latest/objects.inv
409402
options:
@@ -413,21 +406,15 @@ plugins:
413406
show_root_heading: true
414407
show_if_no_docstring: true
415408
show_signature_annotations: true
416-
gallery:
417-
examples_dirs: docs/examples # path to your example scripts
418-
gallery_dirs: docs/generated/gallery # where to save generated gallery
419-
image_srcset: ['2x']
420-
within_subsection_order: FileNameSortKey
421409
search: {}
422410
```
423411

424-
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, one where all the generated API documentation from `mkdocstrings` will live, and a final entry for any examples showing how to use the package.
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.
425413

426414
```yaml
427415
nav:
428416
- Home: index.md
429417
- Python API: api.md
430-
- Examples: generated/gallery
431418
```
432419

433420
{% endtab %} {% endtabs %}
@@ -651,15 +638,15 @@ Note that your docstrings are still parsed as reStructuredText.
651638

652639
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.
653640

654-
All `mkdocstrings` requires is your markdown files to specify what package, module, or class 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:
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:
655642

656643
```markdown
657-
# Documentation for `my_package.MyClass`
644+
# Documentation for `my_package.my_module`
658645

659-
::: my_package.MyClass
646+
::: my_package.my_module
660647
```
661648
662-
Where the triple colon syntax is used to specify what documentation you would like built. In this case, we are asking for the class `MyClass` which is located in `my_package`, and a user would be able to import this class via `from my_package` import `MyClass`. If the class is not exposed in the package `__init__.py` and is only importable from a module (such that a user would have to write `from my_package.my_module import MyClass`) then you would update the identifier to `my_package.my_module.MyClass`.
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`.
663650

664651
{% endtab %}
665652
{% endtabs %}
@@ -712,7 +699,7 @@ plugins:
712699
- mkdocs-jupyter
713700
```
714701

715-
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.
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.
716703

717704
{% endtab %} {% endtabs %}
718705

{{cookiecutter.project_name}}/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{%- if cookiecutter.org | lower == "scikit-hep" %}
1212
[![Scikit-HEP][sk-badge]](https://scikit-hep.org/) {%- endif %}
1313

14-
<!-- SPHINX-START -->
1514

1615
<!-- prettier-ignore-start -->
1716
[actions-badge]: {{cookiecutter.url}}/workflows/CI/badge.svg

{{cookiecutter.project_name}}/noxfile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def tests(session: nox.Session) -> None:
4444
session.install("{% if cookiecutter.backend != "mesonpy" %}-e{% endif %}.", *test_deps)
4545
session.run("pytest", *session.posargs)
4646

47+
4748
{%- if cookiecutter.docs == 'sphinx' %}
4849
@nox.session(reuse_venv=True, default=False)
4950
def docs(session: nox.Session) -> None:
@@ -92,6 +93,8 @@ def build_api_docs(session: nox.Session) -> None:
9293
"--force",
9394
"src/{{ cookiecutter.__project_slug }}",
9495
)
96+
97+
9598
{%- elif cookiecutter.docs == 'mkdocs' %}
9699
@nox.session(reuse_venv=True, default=False)
97100
def docs(session: nox.Session) -> None:
@@ -102,11 +105,9 @@ def docs(session: nox.Session) -> None:
102105
doc_deps = nox.project.dependency_groups(PROJECT, "docs")
103106
session.install("{% if cookiecutter.backend != "mesonpy" %}-e{% endif %}.", *doc_deps)
104107
session.run("mkdocs", "serve", "--clean")
105-
{%- endif %}
106-
107-
108108

109109

110+
{%- endif %}
110111
@nox.session(default=False)
111112
def build(session: nox.Session) -> None:
112113
"""

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ docs = [
140140
"mkdocs-material>=9.1.19,<10",
141141
"pyyaml>=6.0.1",
142142
"mkdocstrings-python>=1.18.2",
143-
"mkdocs-gallery>=0.10.4",
144143
]
145144
{%- endif %}
146145

@@ -317,7 +316,7 @@ isort.required-imports = ["from __future__ import annotations"]
317316
[tool.ruff.lint.per-file-ignores]
318317
"tests/**" = ["T20"]
319318
"noxfile.py" = ["T20"]
320-
{%- if cookiecutter.docs == 'mkdocs' %}
319+
{%- if cookiecutter.docs == "mkdocs" %}
321320
"docs/examples/**" = ["T20"]
322321
{%- endif %}
323322

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Behold, module level docstring."""
2+
3+
4+
class Example:
5+
"""This class exists to show off autodocstring generation."""
6+
7+
def add(self, a: int, b: int) -> int:
8+
"""Add two integers.
9+
10+
Notes:
11+
Docstring can be useful. I promise.
12+
13+
Parameters:
14+
a: First integer to add.
15+
b: Second integer to add.
16+
17+
Returns:
18+
The sum of the two integers.
19+
"""
20+
return a + b
21+
22+
def subtract(self, a: int, b: int) -> int:
23+
"""Subtract two integers.
24+
25+
Parameters:
26+
a: Integer to subtract from.
27+
b: Integer to subtract.
28+
29+
Returns:
30+
The difference of the two integers.
31+
"""
32+
return a - b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ::: {{cookiecutter.__project_slug}}.example

{{cookiecutter.project_name}}/{% if cookiecutter.docs='mkdocs' %}docs{% endif %} copy/index.md renamed to {{cookiecutter.project_name}}/{% if cookiecutter.docs == 'mkdocs' %}docs{% endif %}/index.md

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.docs='sphinx' %}docs{% endif %}/conf.py renamed to {{cookiecutter.project_name}}/{% if cookiecutter.docs == 'sphinx' %}docs{% endif %}/conf.py

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.docs='sphinx' %}docs{% endif %}/index.md renamed to {{cookiecutter.project_name}}/{% if cookiecutter.docs == 'sphinx' %}docs{% endif %}/index.md

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.docs='mkdocs' %}docs{% endif %} copy/api.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)