# SPDX-License-Identifier: GPL-2.0-or-later """ API dump in RST files --------------------- Run this script from Blender's root path once you have compiled Blender blender --background --factory-startup -noaudio --python doc/python_api/sphinx_doc_gen.py This will generate python files in doc/python_api/sphinx-in/ providing ./blender is or links to the blender executable To choose sphinx-in directory: blender --background --factory-startup --python doc/python_api/sphinx_doc_gen.py -- --output=../python_api For quick builds: blender --background --factory-startup --python doc/python_api/sphinx_doc_gen.py -- --partial=bmesh.* Sphinx: HTML generation ----------------------- After you have built doc/python_api/sphinx-in (see above), generate html docs by running: sphinx-build doc/python_api/sphinx-in doc/python_api/sphinx-out Sphinx: PDF generation ---------------------- After you have built doc/python_api/sphinx-in (see above), generate the pdf doc by running: sphinx-build -b latex doc/python_api/sphinx-in doc/python_api/sphinx-out cd doc/python_api/sphinx-out make """ try: import bpy # Blender module. except ImportError: print("\nERROR: this script must run from inside Blender") print(__doc__) import sys sys.exit() import rna_info # Blender module. def rna_info_BuildRNAInfo_cache(): if rna_info_BuildRNAInfo_cache.ret is None: rna_info_BuildRNAInfo_cache.ret = rna_info.BuildRNAInfo() return rna_info_BuildRNAInfo_cache.ret rna_info_BuildRNAInfo_cache.ret = None # --- end rna_info cache import os import sys import inspect import shutil import time import logging import warnings from textwrap import indent SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) # For now, ignore add-ons and internal sub-classes of `bpy.types.PropertyGroup`. # # Besides disabling this line, the main change will be to add a # 'toctree' to 'write_rst_index' which contains the generated RST files. # This 'toctree' can be generated automatically. # # See: D6261 for reference. USE_ONLY_BUILTIN_RNA_TYPES = True # Write a page for each static enum defined in: # `source/blender/makesrna/RNA_enum_items.h` so the enums can be linked to instead of being expanded everywhere. USE_SHARED_RNA_ENUM_ITEMS_STATIC = True if USE_SHARED_RNA_ENUM_ITEMS_STATIC: from _bpy import rna_enum_items_static rna_enum_dict = rna_enum_items_static() for key in ("DummyRNA_DEFAULT_items", "DummyRNA_NULL_items"): del rna_enum_dict[key] del key, rna_enum_items_static # Build enum `{pointer: identifier}` map, so any enum property pointer can # lookup an identifier using `InfoPropertyRNA.enum_pointer` as the key. rna_enum_pointer_to_id_map = { enum_prop.as_pointer(): key for key, enum_items in rna_enum_dict.items() # It's possible the first item is a heading (which has no identifier). # skip these as the `EnumProperty.enum_items` does not expose them. if (enum_prop := next(iter(enum_prop for enum_prop in enum_items if enum_prop.identifier), None)) } def handle_args(): """ Parse the args passed to Blender after "--", ignored by Blender """ import argparse # When --help is given, print the usage text parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, usage=__doc__ ) # optional arguments parser.add_argument( "-p", "--partial", dest="partial", type=str, default="", help="Use a wildcard to only build specific module(s)\n" "Example: --partial\"=bmesh*\"\n", required=False, ) parser.add_argument( "-f", "--fullrebuild", dest="full_rebuild", default=False, action='store_true', help="Rewrite all RST files in sphinx-in/ " "(default=False)", required=False, ) parser.add_argument( "-b", "--bpy", dest="bpy", default=False, action='store_true', help="Write the RST file of the bpy module " "(default=False)", required=False, ) parser.add_argument( "--api-changelog-generate", dest="changelog", default=False, action='store_true', help="Generate the API changelog RST file " "(default=False, requires `--api-dump-index-path` parameter)", required=False, ) parser.add_argument( "--api-dump-index-path", dest="api_dump_index_path", metavar='FILE', default=None, help="Path to the API dump index JSON file " "(required when `--api-changelog-generate` is True)", required=False, ) parser.add_argument( "-o", "--output", dest="output_dir", type=str, default=SCRIPT_DIR, help="Path of the API docs (default=