Skip to content

Commit d92ab0b

Browse files
jklymakQuLogic
andcommitted
DOC: fix Sphinx Gallery discussion to explain mixed subddirs [ci doc]
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent cf9a887 commit d92ab0b

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

doc/devel/documenting_mpl.rst

+46-11
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,11 +816,30 @@ 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
824-
from having an plot generated insert "sgskip" somewhere in the filename.
825-
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 embedded 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. The last,
836+
:file:`galleries/users_explain`, is a mixed gallery where some of the files are
837+
raw ``*.rst`` files and some are ``*.py`` files; Sphinx Gallery just copies
838+
these ``*.rst`` files from the source location to the build location (see
839+
:ref:`raw_restructured_gallery`, below).
840+
841+
In the Python files, to exclude an example from having a plot generated, insert
842+
"sgskip" somewhere in the filename.
826843

827844
Formatting the example
828845
----------------------
@@ -947,6 +964,23 @@ to name your example consistently, i.e. use the main function or subject
947964
of the example as first word in the filename; e.g. an image example
948965
should ideally be named similar to :file:`imshow_mynewexample.py`.
949966

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

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

0 commit comments

Comments
 (0)