拡張¶
たくさんのプロジェクトではそのドキュメントに独自の機能を必要としているため、Sphinxでは "拡張" をビルド中に加える事が出来ます。拡張により、ドキュメント処理中のほぼすべての場面に変更を加える事が出来ます。
この章ではSphinxに標準で付属している拡張について説明します。ご自身の拡張を実装するときに必要なAPIドキュメントは、 Sphinx API を参照してください。
組み込みの拡張¶
これらの拡張機能はすべてSphinxに組み込まれています。設定ファイルの extensions のリストの中に名前を書くことで使用できるようになります:
sphinx.ext.apidoc-- Generate API documentation from Python packagessphinx.ext.autodoc-- docstringからのドキュメントの取り込みsphinx.ext.autosectionlabel-- Allow referencing sections by their titlesphinx.ext.autosummary-- autodocのサマリーの生成sphinx.ext.coverage-- ドキュメントのカバレッジの状況を収集しますsphinx.ext.doctest-- ドキュメント内の簡易テストsphinx.ext.duration-- Sphinx処理の処理時間を測定します。sphinx.ext.extlinks-- 外部リンクを短縮表記させるマークアップsphinx.ext.githubpages-- GitHub PagesへHTMLドキュメントを公開しますsphinx.ext.graphviz-- Graphvizのグラフを追加sphinx.ext.ifconfig-- 設定にしたがってコンテンツをON/OFFするsphinx.ext.imgconverter-- A reference image converter using Imagemagicksphinx.ext.inheritance_diagram-- 継承関係図の追加sphinx.ext.intersphinx-- 他のプロジェクトのドキュメントへのリンクsphinx.ext.linkcode-- ソースコードへの外部リンクを追加- SphinxにおけるHTML出力での数式サポート
sphinx.ext.napoleon-- NumPy および Google スタイルの docstring をドキュメントに取り込むsphinx.ext.todo-- Todoアイテムのサポートsphinx.ext.viewcode-- ハイライト済みのソースコードへのリンクを追加
サードパーティ製の拡張機能¶
You can find several extensions contributed by users in the sphinx-contrib organization. If you wish to include your extension in this organization, simply follow the instructions provided in the github-administration project. This is optional and there are several extensions hosted elsewhere. The awesome-sphinxdoc and sphinx-extensions projects are both curated lists of Sphinx packages, and many packages use the Framework :: Sphinx :: Extension and Framework :: Sphinx :: Theme trove classifiers for Sphinx extensions and themes, respectively.
自分自身の拡張機能はどこに置くべき?¶
Extensions local to a project should be put within the project's directory
structure. Set Python's module search path, sys.path, accordingly so that
Sphinx can find them. For example, if your extension foo.py lies in the
exts subdirectory of the project root, put into conf.py:
import sys
from pathlib import Path
sys.path.append(str(Path('exts').resolve()))
extensions = ['foo']
sys.pathを使う以外の方法では、site-packagesディレクトリの中にインストールするという方法などもあります。