A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://sphinx-gallery.github.io/stable/getting_started.html below:

Getting Started with Sphinx-Gallery — Sphinx-Gallery 0.19.0-git documentation

Getting Started with Sphinx-Gallery# Creating a basic Gallery#

This section describes how to set up a basic gallery for your examples using the Sphinx extension Sphinx-Gallery, which will do the following:

A template repository, with sample example galleries and basic configurations is also available to help you get started.

Note

Working sphinx builders for sphinx_gallery include html, dirhtml and latex.

Overview your project files and folders#

This section describes the general files and structure needed for Sphinx-Gallery to build your examples.

Let’s say your Python project has the following structure:

.
├── doc
│   ├── conf.py
│   ├── index.rst
|   ├── make.bat
│   └── Makefile
├── my_python_module
│   ├── __init__.py
│   └── mod.py
└── examples
    ├── plot_example.py
    ├── example.py
    └── GALLERY_HEADER.rst (or README.[rst/.txt])

Sphinx-Gallery expects the examples directory to have a specific structure, which we’ll cover next.

Structure the examples folder#

In order for Sphinx-Gallery to build a gallery from your examples folder, this folder must have the following things:

Warning

The variable name ___ (3 underscores) should never be used in your example Python scripts as it is used as an internal Sphinx-Gallery variable.

Configure and use Sphinx-Gallery#

After Sphinx-Gallery is installed, we must enable and configure it to build with Sphinx.

First, enable Sphinx-Gallery in the Sphinx doc/conf.py file with:

extensions = [
    ...
    'sphinx_gallery.gen_gallery',
    ]

This loads Sphinx-Gallery as one of your extensions, the ellipsis ... represents your other loaded extensions.

Next, create your configuration dictionary for Sphinx-Gallery. Here we will simply set the minimal required configurations. We must set the location of the ‘examples’ directory (containing the gallery header file and our example Python scripts) and the directory to place the output files generated. The path to both of these directories should be relative to the doc/conf.py file.

The following configuration declares the location of the ‘examples’ directory ('example_dirs') to be ../examples and the ‘output’ directory ('gallery_dirs') to be auto_examples:

sphinx_gallery_conf = {
     'examples_dirs': '../examples',   # path to your example scripts
     'gallery_dirs': 'auto_examples',  # path to where to save gallery generated output
}

After building your documentation, gallery_dirs will contain the following files and directories:

Additionally for each .py file, a file with the following suffix is generated:

Additionally, two compressed .zip files containing all the .ipynb and .py files are generated, as well as a root-level sg_execution_times.rst file containing all of the execution times.

For more advanced configuration, see the Configuration page.

Add your gallery to the documentation#

The index.rst file generated for your gallery can be added to the table of contents tree in the main Sphinx doc/index.rst file or embedded in a Sphinx source .rst file with an .. include:: statement.

Build the documentation#

In your Sphinx source directory, (e.g., myproject/doc) execute:

This will start the build of your complete documentation. Both the Sphinx-Gallery output files described above and the Sphinx built HTML documentation will be generated. Once a build is completed, all the outputs from your examples will be cached. In the future, only examples that have changed will be re-built.

You should now have a gallery built from your example scripts! For more advanced usage and configuration, check out the Advanced usage page or the Configuration reference.

Note

Sphinx-Gallery may work for non-HTML Sphinx builders but support for this is mostly untested and results may vary.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4