Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8994247

Browse files
committed
DOC: fix Sphinx Gallery discussion to explain mixed subddirs [ci doc]
1 parent a844eca commit 8994247

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

doc/devel/documenting_mpl.rst

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ the docstrings of the classes in the Matplotlib library. Except for
2020
:file:`doc/api/api_changes/`, ``.rst`` files in :file:`doc/api` are created
2121
when the documentation is built. See :ref:`writing-docstrings` below.
2222

23-
Second, the contents of :file:`doc/plot_types`, :file:`doc/gallery` and
24-
:file:`doc/tutorials` are generated by the `Sphinx Gallery`_ from python files
25-
in :file:`galleries/plot_types/`, :file:`galleries/examples/` and
26-
:file:`galleries/tutorials/`. These sources consist of python scripts that have
27-
ReST_ documentation built into their comments. See
28-
:ref:`writing-examples-and-tutorials` below.
23+
Second, our example pages, tutorials, and some of the narrative documentation
24+
are created by `Sphinx Gallery`_. Sphinx Gallery converts example python files
25+
to ``*.rst`` files with the result of Matplotlib plot calls as embedded images.
26+
See :ref:`writing-examples-and-tutorials` below.
2927

3028
Third, Matplotlib has narrative docs written in ReST_ in subdirectories of
3129
:file:`doc/users/`. If you would like to add new documentation that is suited
@@ -818,12 +816,28 @@ code will also appear in interactive docstrings.
818816
Writing examples and tutorials
819817
==============================
820818

821-
Examples and tutorials are python scripts that are run by `Sphinx Gallery`_
822-
to create a gallery of images in the :file:`/doc/gallery` and
823-
:file:`/doc/tutorials` directories respectively. To exclude an example
819+
Examples and tutorials are python scripts that are run by `Sphinx Gallery`_.
820+
Sphinx Gallery finds ``*.py`` files in source directories and runs the files to
821+
create images and narrative that are embeded in ``*.rst`` files in a build
822+
location of the :file:`doc/` directory. Files in the build location should not
823+
be directly edited as they will be overwritten by Sphinx gallery. Currently
824+
Matplotlib has four galleries as follows:
825+
826+
=============================== ==========================
827+
Source location Build location
828+
=============================== ==========================
829+
:file:`galleries/plot_types` :file:`doc/plot_types`
830+
:file:`galleries/examples` :file:`doc/gallery`
831+
:file:`galleries/tutorials` :file:`doc/tutorials`
832+
:file:`galleries/users_explain` :file:`doc/users/explain`
833+
=============================== ==========================
834+
835+
The first three are traditional galleries, :file:`galleries/users_explain` is a
836+
mixed gallery where some of the files are raw ``*.rst`` files rather than
837+
``*.py`` files; Sphinx Gallery just copies those from the location to the build
838+
location (see :ref:`raw_restructured_gallery`, below). To exclude an example
824839
from having an plot generated insert "sgskip" somewhere in the filename.
825840

826-
827841
Formatting the example
828842
----------------------
829843

@@ -947,6 +961,23 @@ to name your example consistently, i.e. use the main function or subject
947961
of the example as first word in the filename; e.g. an image example
948962
should ideally be named similar to :file:`imshow_mynewexample.py`.
949963

964+
.. _raw_restructured_gallery:
965+
966+
Raw restructured text files in the gallery
967+
------------------------------------------
968+
969+
`Sphinx Gallery`_ folders usually consist of a ``README.txt`` and a series of
970+
python source files that are then translated to an ``index.rst`` file and a
971+
series of ``example_name.rst`` files in the :file:`doc/` subdirectories.
972+
However, Sphinx Gallery also allows raw ``*.rst`` files to be passed through a
973+
gallery (see `Manually passing files`_ in the Sphinx Gallery documentation). We
974+
use this feature in :file:`galleries/users_explain`, where, for instance,
975+
:file:`galleries/users_explain/colors` is a regular Sphinx Gallery
976+
subdirectory, but :file:`galleries/users_explain/artists` has a mix of
977+
``*.rst`` and ``*py`` files. For mixed subdirectories like this, we must add
978+
any ``*.rst`` files to a ``:toctree:``, either in the ``README.txt`` or in a
979+
manual ``index.rst``.
980+
950981
Miscellaneous
951982
=============
952983

@@ -1022,3 +1053,4 @@ style or topbar should be made there to propagate across all subprojects.
10221053
.. _`Sphinx Gallery`: https://sphinx-gallery.readthedocs.io/en/latest/
10231054
.. _references: https://www.sphinx-doc.org/en/stable/usage/restructuredtext/roles.html
10241055
.. _`numpydoc docstring guide`: https://numpydoc.readthedocs.io/en/latest/format.html
1056+
.. _`Manually passing files`: https://sphinx-gallery.github.io/stable/configuration.html#manually-passing-files

0 commit comments

Comments
 (0)