Required Sphinx configuration#

The following page explains the minimum required Sphinx configuration for building the documentation of a PyAnsys library.

When installing Sphinx, a program named sphinx-build also gets installed. This program is in charge of collecting, parsing, and rendering all ReStructuredText (RST) files in The doc/ directory.

The behavior of the sphinx-build program is controlled through either a Makefile (for POSIX systems) or a make.bat file (for Windows systems). Once the sphinx-build command is triggered, the configuration declared in the file is applied when rendering the documentation pages.

The file#

The following file provides the minimum required configuration for a PyAnsys library. To guarantee consistency across PyAnsys libraries, you should only make custom additions on top of this configuration.

"""Sphinx documentation configuration file."""
from datetime import datetime

from ansys_sphinx_theme import pyansys_logo_black as logo

# Project information
project = "ansys-product-library"
copyright = f"(c) {} ANSYS, Inc. All rights reserved"
author = "ANSYS, Inc."
release = version = "0.1.dev0"

# Select desired logo, theme, and declare the html title
html_logo = logo
html_theme = "ansys_sphinx_theme"
html_short_title = html_title = "pyproduct-library"

# specify the location of your github repo
html_theme_options = {
    "github_url": "",
    "show_prev_next": False,
    "show_breadcrumbs": True,
    "additional_breadcrumbs": [
        ("PyAnsys", ""),

# Sphinx extensions
extensions = [

# Intersphinx mapping
intersphinx_mapping = {
    "python": ("", None),
    # kept here as an example
    # "scipy": ("", None),
    # "numpy": ("", None),
    # "matplotlib": ("", None),
    # "pandas": ("", None),
    # "pyvista": ("", None),
    # "grpc": ("", None),

# numpydoc configuration
numpydoc_show_class_members = False
numpydoc_xref_param_type = True

# Consider enabling numpydoc validation. See:
numpydoc_validate = True
numpydoc_validation_checks = {
    "GL06",  # Found unknown section
    "GL07",  # Sections are in the wrong order.
    "GL08",  # The object does not have a docstring
    "GL09",  # Deprecation warning should precede extended summary
    "GL10",  # reST directives {directives} must be followed by two colons
    "SS01",  # No summary found
    "SS02",  # Summary does not start with a capital letter
    "SS03",  # Summary does not end with a period
    "SS04",  # Summary contains heading whitespaces
    "SS05",  # Summary must start with infinitive verb, not third person
    "RT02",  # The first line of the Returns section should contain only the
    # type, unless multiple values are being returned"

# static path
html_static_path = ["_static"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

# Generate section labels up to four levels deep
autosectionlabel_maxdepth = 4

Automation files#

As indicated earlier in this topic, the sphinx-build program and all its options and arguments can be automated by using a Makefile file or a make.bat` file. These files should be placed at the first level of The doc/ directory, next to the source/ directory.

Notice that both files contain a SPHINXOPTS variable with these flags: -j, -W, and --keep-going.

  • The -j flag indicates the number of jobs (number of cores) to use. The default value is auto, which means that the number of cores in the CPU is to be automatically detected.

  • The -W flag turns warnings into errors. This guarantees that documentation health is maximized.

  • The --keep-going flag specifies whether to render the whole documentation, even if a warning is found. This flag enables developers to be aware of the full set of warnings.

A special rule named pdf is also included. This rule is in charge of generating a PDF file for the library’s documentation.

Example for Makefile#

The following code collects the required options and automation rules for the Makefile program to use when building documentation for a PyAnsys library:

# Minimal makefile for Sphinx documentation

# You can set these variables from the command line:
SPHINXOPTS    = -j auto -W --keep-going
SPHINXBUILD   = sphinx-build
SOURCEDIR     = source
BUILDDIR      = build

# Put the "help" rule the first one so that "make" without argument behaves like "make help".

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
# Clean build directory files
	rm -rf build
	find . -type d -name "_autosummary" -exec rm -rf {} +

# Build PDF documentation
	cd build/latex && latexmk -r latexmkrc -pdf *.tex -interaction=nonstopmode || true
	(test -f build/latex/*.pdf && echo pdf exists) || exit 1

Example for make.bat#

The following code collects the required options and automation rules for the make.bat program to use when building documentation for a PyAnsys project:


pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
	set SPHINXBUILD=sphinx-build
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXOPTS=-j auto -W --keep-going

if "%1" == "" goto help
if "%1" == "clean" goto clean
if "%1" == "pdf" goto pdf

if errorlevel 9009 (
	echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
	echo.installed, then set the SPHINXBUILD environment variable to point the full path of the 'sphinx-build' executable. Alternatively you
	echo.may add the Sphinx directory to PATH.
	echo.If you don't have Sphinx installed, grab it from
	exit /b 1

goto end


rmdir /s /q %BUILDDIR% > /NUL 2>&1 
for /d /r %SOURCEDIR% %%d in (_autosummary) do @if exist "%%d" rmdir /s /q "%%d"
goto end

	cd "%BUILDDIR%\latex"
	for %%f in (*.tex) do (
	pdflatex "%%f" --interaction=nonstopmode)