sphinx_gallery.gen_rst#
reST ファイルジェネレーター。
Python のサンプルファイルを反復処理して、サンプル用の rst ファイルを生成します。
画像を生成するファイルは「plot」で始める必要があります。
関数#
- sphinx_gallery.gen_rst.codestr2rst(codestr, lang='python', lineno=None)[ソース]#
コード文字列から reStructuredText コードブロックを返します。
- sphinx_gallery.gen_rst.executable_script(src_file, gallery_conf)[ソース]#
ギャラリー設定に従ってスクリプトを実行する必要があるかどうかを検証します。
- パラメータ:
src_file (str) – Python スクリプトへのパス
gallery_conf (dict) – Sphinx-Gallery の設定が含まれています
- 戻り値:
スクリプトを実行する必要がある場合は True
- 戻り値の型:
- sphinx_gallery.gen_rst.execute_code_block(compiler, block, example_globals, script_vars, gallery_conf, file_conf)[ソース]#
サンプルファイルのコードブロックを実行します。
- パラメータ:
compiler (codeop.Compile) – コードブロックの AST をコンパイルするコンパイラー。
block (sphinx_gallery.py_source_parser.Block) – 実行するコードブロック。
example_globals (Dict[str, Any]) – サンプルのグローバル変数。
script_vars (Dict[str, Any]) – 設定および実行時の変数。
gallery_conf (Dict[str, Any]) – ギャラリーの設定。
file_conf (Dict[str, Any]) – ソースファイルのコメントとして指定されたファイル固有の設定:
# sphinx_gallery_<name> = <value>
。
- 戻り値:
code_output – reST でのコード実行の出力。
- 戻り値の型:
- sphinx_gallery.gen_rst.execute_script(script_blocks, script_vars, gallery_conf, file_conf)[ソース]#
すでにブロック構造になっている Python スクリプトから出力の実行とキャプチャを行います。
- パラメータ:
script_blocks (list) – (ラベル、コンテンツ、行番号) 各要素がラベル(「text」または「code」)、ブロックの対応するコンテンツ文字列、および先頭の行番号を持つタプルであるリスト
script_vars (dict) – 設定およびランタイム変数
gallery_conf (dict) – Sphinx-Gallery の設定が含まれています
file_conf (dict) – ソースファイルのコメントとして指定されたファイル固有の設定:
# sphinx_gallery_<name> = <value>
- 戻り値:
output_blocks (list) – 各要素が各ブロックの出力の構造化テキスト表現である文字列のリスト
time_elapsed (float) – 実行中に経過した時間
- sphinx_gallery.gen_rst.extract_intro_and_title(filename, docstring)[ソース]#
モジュールレベルのドキュメント文字列の最初の段落を抽出してクリーンアップします。
- sphinx_gallery.gen_rst.generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs, is_subsection=True)[ソース]#
サンプルディレクトリのギャラリー reStructuredText を生成します。
- パラメータ:
src_dir (str,) – サンプルファイルを含むルートまたはサブギャラリーディレクトリへのパス
target_dir (str,) – 解析されたサンプル(rst、python ファイルなど)が出力されるパス
gallery_conf (Dict[str, Any]) – ギャラリーの設定。
seen_backrefs (set,) – このギャラリーの解析時に検出されたバックリファレンスは、このセットに保存されます。
is_subsection (bool,) – src_dir がサブセクションディレクトリであるかどうか。サブセクションディレクトリの場合、すべてのサンプルファイルを一覧表示した toctree を含む index.rst ファイルを書き込みます。デフォルト = True。
- 戻り値:
index_path (str または None) – src_dir の index rst ファイルへのパス。ユーザーが独自のインデックスを提供した場合は None。
index_content (str または None) – ギャラリーヘッダーのコンテンツ。ユーザーが独自の index.rst を提供した場合は None。
costs (List[Dict]) –
- ギャラリーの各要素を構築するためのコストの辞書のリスト
キーは「t」、「mem」、「src_file」、および「target_dir」です。
toctree_items (list,) – ReST を生成したサンプルファイル名のリスト。
- sphinx_gallery.gen_rst.generate_file_rst(fname, target_dir, src_dir, gallery_conf)[ソース]#
特定のサンプルの rst ファイルを生成します。
- パラメータ:
fname (str) – Python スクリプトのファイル名。
target_dir (str) – サンプルが保存されるドキュメント内のディレクトリへの絶対パス。
src_dir (str) – ソースサンプルが保存されているディレクトリへの絶対パス。
gallery_conf (dict) – Sphinx-Gallery の設定が含まれています。
- 戻り値:
intro (str) – サンプルの導入。
title (str) – サンプルのタイトル。
cost (tuple) – スクリプトの実行に必要な
(time_elapsed, memory_used)
を含むタプル。out_vars (dict) – スクリプトの実行に使用される変数(場合によってはエントリを含む)
- 「stale」
サンプルが古い場合は True。
- 「backrefs」
バックリファレンス。
- 「passing」
サンプルが合格した場合は True。
- 「formatted_exception」
例外の書式化された文字列。
- sphinx_gallery.gen_rst.handle_exception(exc_info, src_file, script_vars, gallery_conf)[ソース]#
例外をトリミングして書式化し、エラーを発生させるなどします。
- sphinx_gallery.gen_rst.md5sum_is_current(src_file, mode='b')[ソース]#
src_fileがディスク上にあるものと同じMD5ハッシュを持っているかどうかをチェックします。
- sphinx_gallery.gen_rst.rst_blocks(script_blocks, output_blocks, file_conf, gallery_conf, *, language='python')[ソース]#
スクリプトの文章、コード、出力を含むrst文字列を生成します。
- パラメータ:
script_blocks (list) – (ラベル、コンテンツ、行番号) 各要素がラベル(「text」または「code」)、ブロックの対応するコンテンツ文字列、および先頭の行番号を持つタプルであるリスト
output_blocks (list) – 各要素が各ブロックの出力のreStructuredText表現である文字列のリスト
file_conf (dict) – ソースファイルのコメントとして指定されたファイル固有の設定:
# sphinx_gallery_<name> = <value>
language (str) – コードブロックでのシンタックスハイライトに使用される言語。Pygmentsで認識される名前またはエイリアスである必要があります。
gallery_conf (dict) – Sphinx-Gallery の設定が含まれています
- 戻り値:
out – rstノートブック
- 戻り値の型:
- sphinx_gallery.gen_rst.save_rst_example(example_rst, example_file, time_elapsed, memory_used, gallery_conf, *, language='python')[ソース]#
rstノートブックをヘッダーとフッターを含めてexample_fileに保存します。