- AdalFlow Documentation Guide
AdalFlow uses Sphinx and reStructuredText for generating project documentation. Sphinx reads configurations from a Python script (conf.py), pulls documentation from comments in the code (via the autodoc extension), and organizes content through .rst files.
- Configuration: Managed via
conf.py. - Automatic Documentation: Generated from docstrings using
autodoc. - Content Organization: Structured through
.rstfiles and the table of contents defined inindex.rst.
This guide will walk you through setting up, building, and contributing to the AdalFlow documentation.
Before you begin, ensure you have the following installed:
-
Poetry: For dependency management. Install it with:
pip install poetry
-
Optional Tools:
pandocfor converting Markdown to reStructuredText.- A modern browser for viewing documentation.
Clone the AdalFlow GitHub repository:
git clone https://github.com/SylphAI-Inc/AdalFlow.git
cd AdalFlowInstall all necessary dependencies using poetry:
poetry installIf you encounter issues with poetry, ensure it is up-to-date by reinstalling:
pip install --upgrade poetryNote: Be sure to run these commands from the root level of the project.
Ensure all dependencies are installed correctly:
poetry checkThe docs/source/conf.py controls the configurations used by Sphinx to build the documentation, including the project-related information, sphinx extensions, templates configuration, HTML theme, patterns to exclude, language configuration, project path setup, etc.
The docs/source/index.rst is the root document for Sphinx-generated documentation ("homepage" for the documentation site). It includes the toctree that defines the documentation hierarchical structure (sections/chapters). It also links to other .rst files that users can navigate through.
For example, in the index.rst, the :caption: Get Started corresponds to the section name of the documentation site. installation and introduction are the detailed pages.
.. toctree::
:glob:
:maxdepth: 1
:caption: Get Started
get_started/installation
get_started/introductionExisting sections include:
get_started/: Includes installation and AdalFlow in 10 minutestutorials/: Includes our main tutorialsuse_cases/: Includes the use cases of AdalFlow that will be added in the future and which accepts community contributionsapis/: All the source-code-related documents will be included in this directory
Most of the documentation is automatically generated from code comments using the autodoc extension. To update:
- Edit the docstrings in your source code.
- Rebuild the documentation (see Building the Documentation).
Note: Ensure that your docstrings follow the reStructuredText format for proper rendering.
When you add new modules or code to the project, it's essential to generate corresponding .rst files to include them in the documentation. Here's how to do it:
-
Ensure Proper Structure:
- If your new module is a folder, it should contain an
__init__.pyfile to be recognized as a package. - Write comprehensive docstrings for your new code to leverage the
autodocextension effectively.
- If your new module is a folder, it should contain an
-
Generate
.rstFiles Usingsphinx-apidoc:Use the
sphinx-apidoccommand to automatically generate.rstfiles for your new modules:sphinx-apidoc [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN …]
Example:
While located in the root directory of your project, run the following command to generate
.rstfiles for theuse_casesmodule, excluding any files or directories with "test" in their names:sphinx-apidoc --force -o docs/source/tutorials ./use_cases "*test*"--force: Overwrites any existing.rstfiles in the output directory. This is safe as long as you haven't made manual edits to these.rstfiles.-o docs/source/tutorials: Specifies the directory where the.rstfiles will be generated../use_cases: Path to the module or package to document."*test*": Excludes any files or directories with "test" in their names.
Caution: The
--forceflag will overwrite existing.rstfiles in the specified output directory. Ensure that you haven't made manual edits to these files that you wish to preserve. If you have custom.rstfiles, consider backing them up or omitting the--forceflag. -
Update
index.rstto Include New Sections:After generating the
.rstfiles, update theindex.rstto include the new documentation sections. For example:.. toctree:: :glob: :maxdepth: 1 :caption: Tutorials tutorials/use_cases
This ensures the new module is linked in the documentation's table of contents.
-
Rebuild the Documentation:
After adding new docstrings and generating
.rstfiles, rebuild the documentation to see the updatesSummary of Steps When Adding New Code with Docstrings:
- Add the new code/module with proper docstrings.
- Generate
.rstfiles usingsphinx-apidoc. - Update
index.rstto include new sections. - Rebuild the documentation to reflect changes.
-
Navigate to the
docsDirectory:cd docs -
Clean Previous Builds:
Remove previous build artifacts to ensure a fresh build.
make clean
-
Build the Documentation:
Generate the HTML documentation.
make html
-
(Optional) Build with Verbose Output:
For more detailed build logs, useful for debugging.
sphinx-build -b html source build -v
For users who prefer straightforward commands without additional options:
cd docs
make htmlAfter the build completes, open the documentation:
-
macOS:
open build/html/index.html
-
Linux:
xdg-open build/html/index.html
-
Windows:
Manually open the
index.htmlfile in your preferred browser.
After building, the HTML files will be available in docs/build/html. Open index.html in your browser to view the documentation.
Handling Browser Restrictions on Local Resources:
Some browsers restrict loading local resources like CSS for security reasons. In such cases, use a local server to serve the files:
cd docs/build/html
python -m http.serverVisit http://127.0.0.1:8000/ in your browser to view the documentation.
To ensure the documentation builds correctly without errors or warnings, run:
sphinx-build -n -W --keep-going source build-n: Runs Sphinx in nit-picky mode to catch missing references.-W: Treats warnings as errors, causing the build to fail if any warnings are present.--keep-going: Continues the build as much as possible after encountering errors.
Recommendation: Fix any issues reported by this command before committing your changes to maintain documentation quality.
To maintain a clean repository, exclude unnecessary files from commits. Specifically, avoid committing the docs/build directory, as documentation builds are dynamic and can be regenerated locally.
Example .gitignore:
# Ignore build files
docs/build/
*.pyc
__pycache__/
- Commit Only Necessary Files:
- Source files (
.rst,.py, etc.) - Configuration files (
conf.py,Makefile,pyproject.toml, etc.)
- Source files (
- Exclude:
docs/build/: Generated HTML files.- Compiled Python files (
*.pyc,__pycache__/).
Ensure the project follows this structure:
AdalFlow/
├── docs/
│ ├── apis/
│ │ ├── core/
│ │ │ ├── core.module1.rst
│ │ │ ├── core.module2.rst
│ │ ├── components/
│ │ │ ├── components.module1.rst
│ │ │ ├── components.module2.rst
│ ├── build/
│ │ ├── html/
│ │ │ ├── _static/
│ │ │ ├── _templates/
│ │ │ ├── index.html
│ │ │ ├── core/
│ │ │ │ ├── core.module1.html
│ │ │ │ ├── core.module2.html
│ │ │ ├── components/
│ │ │ │ ├── components.module1.html
│ │ │ │ ├── components.module2.html
│ ├── _static/
│ ├── _templates/
│ ├── conf.py
│ ├── index.rst
│ ├── Makefile
│ ├── pyproject.toml
│ ├── poetry.lock
Note: The build/ directory contains generated files and should not be manually edited or committed.
If you want to add any written files such as README.md to the documentation, there is an easy way to transform the files to .rst files using Pandoc.
To convert .md files (e.g., README.md) to .rst:
-
Install
pandoc:brew install pandoc
For non-Homebrew users, refer to Pandoc's installation guide.
-
Run the Conversion:
Conversion Syntax:
pandoc -s <input.md> -o <path/to/target.rst>
Example:
This command will take content from
README.mdand create anintroduction.rstfile in the specified directory.pandoc -s README.md -o docs/source/get_started/introduction.rst
-
Rebuild the Documentation:
After converting, rebuild the documentation to include the new
.rstfiles.cd docs make clean make html
Note: Ensure that the converted .rst files are correctly linked in your index.rst or appropriate parent .rst files.