conf.py

Overview

`conf.py` is the primary configuration file for the Sphinx documentation build system used by the **pytest** project. This file sets up all the necessary settings, extensions, and options to generate pytest's documentation in various output formats such as HTML, PDF, manual pages, EPUB, LaTeX, and Texinfo.

The file defines metadata about the project, configures Sphinx extensions for advanced documentation features, controls which files to include or exclude, and customizes output styling and indexing. It also includes runtime checks and conditional logic (for example, enabling certain extensions only if dependencies like Inkscape are available). Finally, it provides a `setup` function to extend Sphinx with pytest-specific cross-reference types, enabling richer linking and indexing in the documentation.

This configuration makes sure the documentation is consistent, well-structured, and integrates with pytest’s ecosystem and external references.


Detailed Explanation

Project Metadata

General Configuration

Autodoc Configuration

Intersphinx Mapping

TODO Extension

Linkcheck Builder

HTML Output Options

Other Output Formats

Configuration sections for manual pages, EPUB, LaTeX, and Texinfo outputs with metadata and formatting options.

Towncrier Draft Extension

sphinx_issues Extension

ReadTheDocs Environment Detection

setup Function

def setup(app: sphinx.application.Sphinx) -> None:
    ...

Usage Examples

While `conf.py` itself is not imported or called directly by users, its configuration affects how the documentation commands work.

Typical usage workflow:

# Build HTML docs:
sphinx-build -b html docs/ docs/_build/html

# Build PDF docs (requires LaTeX and Inkscape if SVG to PDF conversion is needed):
sphinx-build -b latex docs/ docs/_build/latex
make -C docs/_build/latex all-pdf

# Generate manual pages:
sphinx-build -b man docs/ docs/_build/man

The configuration ensures that:


Important Implementation Details


Interactions with Other Parts of the System


Diagram: Structure of conf.py

flowchart TD
    A[conf.py]
    A --> B(Project Metadata)
    A --> C(General Configuration)
    A --> D(Extensions)
    D --> D1[pygments_pytest]
    D --> D2[sphinx.ext.autodoc]
    D --> D3[sphinx.ext.autosummary]
    D --> D4[sphinx.ext.intersphinx]
    D --> D5[sphinx.ext.todo]
    D --> D6[sphinx.ext.viewcode]
    D --> D7[sphinx_removed_in]
    D --> D8[sphinxcontrib_trio]
    D --> D9[sphinxcontrib.towncrier.ext]
    D --> D10[sphinx_issues]
    D --> D11[sphinxcontrib.inkscapeconverter (conditional)]
    A --> E(Output Options)
    E --> E1[HTML]
    E --> E2[PDF/LaTeX]
    E --> E3[Manual Pages]
    E --> E4[EPUB]
    E --> E5[Texinfo]
    A --> F(Linkcheck Configuration)
    A --> G(Intersphinx Mapping)
    A --> H(Towncrier Draft Configuration)
    A --> I(ReadTheDocs Environment Detection)
    A --> J[setup() function]
    J --> J1[Add Crossref Types: fixture, hook]
    J --> J2[Add Object Types: confval, globalvar]
    J --> J3[Import _pytest.legacypath]

Summary

`conf.py` is a critical configuration file that orchestrates the generation of pytest's comprehensive documentation. It sets project metadata, manages numerous Sphinx extensions, configures output formats, and customizes cross-referencing tailored to pytest’s domain. The file ensures smooth integration of external references, conditional extension loading, and enhanced documentation features, playing a central role in maintaining high-quality, user-friendly, and maintainable docs for the pytest project.