Implementation:Kornia Kornia Sphinx Config
| Knowledge Sources | |
|---|---|
| Domains | Documentation, Infrastructure |
| Last Updated | 2026-02-09 15:00 GMT |
Overview
This is the Sphinx configuration file for the Kornia documentation, defining extensions, theme settings, API documentation options, and cross-reference mappings for building the project's Read the Docs site.
Description
The conf.py file in docs/source/ configures the Sphinx documentation build system for Kornia. It includes compatibility patches for PyTorch's torch.jit.annotations and sphinx_autodoc_defaultargs to handle TorchScript/pybind11 callables. The configuration triggers example image generation by importing and running generate_examples.main() at build time. It uses the furo theme with custom light/dark CSS variables for sidebar styling. Key Sphinx extensions include autodoc, autosummary, napoleon (Google-style docstrings), sphinx_autodoc_typehints, sphinx_copybutton, sphinxcontrib.bibtex, sphinxcontrib.gtagjs (Google Analytics), sphinxcontrib.youtube, sphinx_design, and notfound.extension. The linkcode_resolve function provides GitHub source code links in the documentation. Intersphinx mappings connect to Python, NumPy, and PyTorch documentation.
Usage
This file is used by Sphinx when building the Kornia documentation. It is not imported by application code. Run sphinx-build or use the Read the Docs build pipeline to invoke it.
Code Reference
Source Location
- Repository: Kornia
- File: docs/source/conf.py
- Lines: 1-339
Key Configuration
# Extensions
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
"sphinx_autodoc_defaultargs",
"sphinx_copybutton",
"sphinx.ext.linkcode",
"sphinx.ext.githubpages",
"sphinxcontrib.bibtex",
"sphinxcontrib.gtagjs",
"sphinxcontrib.youtube",
"sphinx_design",
"notfound.extension",
]
# Theme
html_theme = "furo"
project = "Kornia"
language = "en"
source_suffix = [".rst", ".ipynb"]
# Linkcode resolver
def linkcode_resolve(domain, info): ...
Import
# Not imported directly; used by Sphinx build system
# sphinx-build -b html docs/source docs/build
I/O Contract
Configuration Settings
| Setting | Value | Description |
|---|---|---|
| project | "Kornia" | Project name used in documentation. |
| html_theme | "furo" | Sphinx theme for documentation rendering. |
| html_baseurl | "https://kornia.readthedocs.io" | Base URL for the documentation. |
| source_suffix | [".rst", ".ipynb"] | Accepted source file types. |
| master_doc | "index" | Root document of the documentation. |
| pygments_style | "friendly" | Syntax highlighting style for light mode. |
| pygments_dark_style | "monokai" | Syntax highlighting style for dark mode. |
| bibtex_bibfiles | ["references.bib"] | Bibliography file for citations. |
| autodoc_mock_imports | ["boxmot", "segmentation_models_pytorch"] | Modules mocked during autodoc. |
Intersphinx Mappings
| Target | URL |
|---|---|
| Python | https://docs.python.org/3/ |
| NumPy | http://numpy.org/doc/stable/ |
| PyTorch | http://pytorch.org/docs/stable/ |
Theme Configuration
The Furo theme is configured with custom CSS variables:
Light mode:
- Sidebar background: #3980F5 (blue)
- Sidebar text: white
- Sidebar hover: #5dade2
Dark mode:
- Sidebar background: #1a1c1e (dark gray)
- Sidebar text: white
Compatibility Patches
The configuration applies two patches at build time:
- torch.jit.annotations.compiler_flag - Adds a missing attribute removed in newer PyTorch versions.
- sphinx_autodoc_defaultargs.process_docstring - Wraps the original function to catch ValueError exceptions from TorchScript/pybind11 callables.
Usage Examples
# Build documentation locally
# cd docs/
# sphinx-build -b html source build
# Or using make
# cd docs/
# make html
# The configuration is also used by Read the Docs automatically