Skip to content

Commit

Permalink
Explain how to add new examples to the gallery (napari#137)
Browse files Browse the repository at this point in the history
# Description
Adds some explanation on how to add new examples to the gallery.

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Fixes or improves existing content

# References
Closes napari#92

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
---------

Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
  • Loading branch information
melissawm and psobolewskiPhD committed Apr 26, 2023
1 parent 3da9815 commit d6334b4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
57 changes: 57 additions & 0 deletions docs/developers/contributing.md
Expand Up @@ -112,6 +112,63 @@ Now you are all set to start developing with napari.

If you wish to contribute documentation changes to napari, please read the [guide on contributing documentation](documentation/index.md).

(add-examples)=
## Adding examples to the [Gallery](gallery)

All of the examples in the [examples Gallery](gallery) are Python scripts that
live under [the `examples` folder of the napari repository](https://github.com/napari/napari/tree/main/examples).
Because of how this gallery is built, every such Python script needs a docstring
containing at least a title (following the `.rst` format of docstrings in
Python) and one or more _tags_. This ensures the example will be shown in the
correct place in the table of contents for the gallery (see, for example, the
[](tagoverview) page.)

Here's an example of what that means. The example file
[add_image.py](https://github.com/napari/napari/blob/main/examples/add_image.py)
contains the following:

```python
"""
Add image
=========
Display one image using the :func:`view_image` API.
.. tags:: visualization-basic
"""

from skimage import data
import napari

# create the viewer with an image
viewer = napari.view_image(data.astronaut(), rgb=True)

if __name__ == '__main__':
napari.run()
```

The equals signs under "Add image" mark this as the example title. The text
below is a short description of the example, and the tags are assigned by the
use of the `.. tags::` directive. In this case, the only tag associated with
this example is `visualization-basic`. Multiple tags can be separated with a
comma.

Note that the examples are `.py` source files, and any outputs and images will
be autogenerated when the documentation site is built.

````{note}
If you are running any of these examples in an interactive environment (e.g. a Jupyter notebook or
IPython console), the block
```
if __name__ == '__main__':
napari.run()
```
is not necessary—you can copy-paste the code above it. However, it is required when running examples as scripts, using for example `python add_image.py`.
Because our example gallery is built from Python scripts, you need to ensure this
block is present in all contributed examples.
````
## Adding icons

If you want to add a new icon to the app, make the icon in whatever program you
Expand Down
3 changes: 2 additions & 1 deletion docs/developers/documentation/index.md
Expand Up @@ -11,7 +11,8 @@ The napari documentation is built from sources located at the
repository is where all the narrative documentation (e.g. tutorials, how-to
guides) pull requests should be made. Meanwhile, changes to docstrings or to the
[examples gallery](https://napari.org/gallery) should be made to the
[napari/napari](https://github.com/napari/napari) repository.
[napari/napari](https://github.com/napari/napari) repository (see also
[](add-examples)).

## Prerequisites

Expand Down
6 changes: 6 additions & 0 deletions docs/gallery.md
Expand Up @@ -3,6 +3,12 @@

Examples of napari usage.

```{note}
If you want to submit a new example to this gallery, check out our
[contribution guide](add-examples)!
```

```{toctree}
:maxdepth: 1
Expand Down

0 comments on commit d6334b4

Please sign in to comment.