generate_rst Module#
generate_rst.py
A utility module for generating reStructuredText (.rst) files for Python modules to be used with Sphinx documentation.
This script scans a given directory for Python modules (excluding specified directories) and automatically creates corresponding .rst files using the .. automodule:: directive. These files are intended to be included in a Sphinx documentation build.
- Usage:
Run this script as a standalone module to generate .rst files:
$ export PYTHONPATH=$PYTHONPATH:. $ python utils/generate_rst.py
- This will:
Search for all .py files (excluding __init__.py) in the specified source directory.
Skip excluded directories like tests, build, and __pycache__.
Output .rst files to the appropriate subdirectories in source/.
- Functions:
- generate_module_rst(module_path, output_dir):
Generates a .rst file for a single module using the Sphinx automodule directive.
- find_modules(root_dir, current_dir, exclude_dirs=None):
Recursively finds Python modules in a directory, excluding specified directories.
Note
The generated .rst files are intended to be included in the Sphinx build.
- utils.generate_rst.find_modules(root_dir: str, current_dir: str, exclude_dirs: list[str] | None = None) list[str][source]#
Recursively finds Python modules (.py files) within a given root directory.
- utils.generate_rst.generate_module_rst(module_path: str, output_dir: str) None[source]#
Generates a reStructuredText file for a Python module.