-
Notifications
You must be signed in to change notification settings - Fork 0
feat: enhance documentation structure and generation for agents #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2e13ba4
feat: enhance documentation structure and generation for agents
pmalarme 62a6c9e
feat: enhance documentation generation with tomllib support and updat…
pmalarme aaf8d71
feat: improve documentation generation and error handling in scripts
pmalarme 8fb1793
feat: enhance documentation generation with improved error handling a…
pmalarme f7d16ff
feat: improve error handling in documentation generation functions
pmalarme a5a80ac
feat: improve error handling in version retrieval from pyproject.toml
pmalarme fb1113e
feat: enhance documentation generation with improved argument handlin…
pmalarme 3a60ae9
feat: update documentation generation scripts with improved argument …
pmalarme aaea061
feat: improve error handling in documentation generation by raising S…
pmalarme dbc0cf2
feat: update documentation generation configuration to include docs a…
pmalarme cb3293c
feat: enhance PYTHONPATH handling in documentation generation to incl…
pmalarme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Agent 1 | ||
| ======= | ||
|
|
||
| Package Documentation | ||
| --------------------- | ||
|
|
||
| .. automodule:: python_agent_template.agents.agent1 | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| CLI Entry Point | ||
| --------------- | ||
|
|
||
| .. automodule:: python_agent_template.agents.agent1.__main__ | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| try: | ||
| import tomllib | ||
| except ModuleNotFoundError: # Python < 3.11 | ||
| try: | ||
| import tomli as tomllib # type: ignore[import-not-found] | ||
| except ModuleNotFoundError: | ||
| tomllib = None # type: ignore[assignment] | ||
|
|
||
| THIS_FILE = Path(__file__).resolve() | ||
|
|
||
|
|
||
| def _find_upwards(start: Path, marker: str = "pyproject.toml") -> Path: | ||
| """Return the first parent containing ``marker``; raise if none is found.""" | ||
| for parent in [start, *start.parents]: | ||
| if (parent / marker).is_file(): | ||
| return parent | ||
| logger.debug("%s not found starting at %s", marker, start) | ||
| err = FileNotFoundError(marker) | ||
| if hasattr(err, "add_note"): | ||
| err.add_note(f"search start: {start}") | ||
| raise err | ||
|
|
||
|
|
||
| AGENT_ROOT = _find_upwards(THIS_FILE) | ||
| PROJECT_ROOT = _find_upwards(AGENT_ROOT.parent) | ||
| sys.path.insert(0, str(PROJECT_ROOT)) | ||
| for src_path in PROJECT_ROOT.glob("agents/*/src"): | ||
| sys.path.insert(0, str(src_path)) | ||
|
|
||
| project = "python-agent-template" | ||
| author = "python-agent-template maintainers" | ||
|
|
||
|
|
||
| def _get_project_version(default: str = "0.0.0") -> str: | ||
| """Return the project version from this agent's pyproject.toml, or a default.""" | ||
| pyproject_path = AGENT_ROOT / "pyproject.toml" | ||
| if tomllib is None or not pyproject_path.is_file(): | ||
| return default | ||
|
|
||
| try: | ||
| with pyproject_path.open("rb") as f: | ||
| data = tomllib.load(f) | ||
| except OSError as exc: | ||
| logger.warning("Failed to read %s; falling back to default version.", pyproject_path, exc_info=exc) | ||
| return default | ||
| except tomllib.TOMLDecodeError as exc: # type: ignore[union-attr] | ||
| logger.warning("Failed to parse %s; falling back to default version.", pyproject_path, exc_info=exc) | ||
| return default | ||
|
|
||
| version = data.get("project", {}).get("version") or data.get("tool", {}).get("poetry", {}).get("version") | ||
| return version or default | ||
|
|
||
|
|
||
| version = _get_project_version() | ||
| release = version | ||
|
|
||
| extensions = [ | ||
| "sphinx.ext.autodoc", | ||
| "sphinx.ext.autosummary", | ||
| "sphinx.ext.napoleon", | ||
| "sphinx.ext.viewcode", | ||
| ] | ||
|
|
||
| try: | ||
| if tomllib is not None: | ||
| # Only enable when the TOML parser (and therefore the extension's deps) is available. | ||
| # Import is intentionally unused; it fails fast if the dependency stack is missing. | ||
| import sphinx_autodoc_typehints # noqa: F401 # pyright: ignore[reportUnusedImport] | ||
pmalarme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| extensions.append("sphinx_autodoc_typehints") | ||
| except Exception: | ||
| logger.warning("sphinx_autodoc_typehints not enabled; dependency stack missing.", exc_info=True) | ||
|
|
||
| autosummary_generate = True | ||
| autodoc_typehints = "description" | ||
| autodoc_default_options = { | ||
| "members": True, | ||
| "undoc-members": True, | ||
| "show-inheritance": True, | ||
| } | ||
|
|
||
| napoleon_google_docstring = True | ||
| napoleon_numpy_docstring = False | ||
|
|
||
| # set to ["_templates"] when the directory is added | ||
| templates_path: list[str] = [] | ||
| exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] | ||
|
|
||
| html_theme = "alabaster" | ||
| html_static_path: list[str] = [] # set to ["_static"] when the directory is added | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Python Agent Template | ||
| ===================== | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 4 | ||
|
|
||
| agent1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Documentation Build Guide | ||
|
|
||
| How to build API docs for the template and each agent. | ||
|
|
||
| ## What gets built | ||
| - Per-agent site: Sphinx sources in `agents/<agent>/docs/source` → HTML in `agents/<agent>/docs/generated`. | ||
| - Unified site: Sphinx sources in `docs/source` → HTML in `docs/generated`. | ||
| - Manual docs: hand-written content lives in `docs/manual`. | ||
|
|
||
| ## Commands | ||
| - Default (build per-agent + unified): | ||
| - `uv run --group docs python scripts/generate_docs.py` | ||
| - Per-agent only: | ||
| - `uv run --group docs python scripts/generate_docs.py --agents-only [--agents agent1 agent2]` | ||
| - Unified only: | ||
| - `uv run --group docs python scripts/generate_docs.py --unified-only` | ||
| - Via poe (root): | ||
| - `uv run poe docs` (same as default) | ||
| - Optional setup: `uv run poe docs-install` to sync the docs group once | ||
|
|
||
| ## Outputs | ||
| - Per-agent HTML: `agents/<agent>/docs/generated` | ||
| - Unified HTML: `docs/generated` | ||
|
|
||
| ## Path overrides (rarely needed) | ||
| - `--root`: repo root override | ||
| - `--agent-source` / `--agent-output`: agent-local source/output (relative to each agent unless absolute) | ||
| - `--unified-source` / `--unified-output`: unified source/output (relative to repo unless absolute) | ||
|
|
||
| ## Best practices | ||
| - Do not commit generated HTML; build in CI and publish artifacts or Pages instead. | ||
| - Keep `docs/source/_autosummary` out of git (already ignored); the build script clears it. | ||
| - Use `uv run poe docs` locally before releasing if you need to verify the output. | ||
|
|
||
| ## CI recommendation | ||
| - Add a GitHub Actions job that installs the docs group (`uv sync --group docs`) and runs `uv run poe docs`. | ||
| - Fail the job on Sphinx warnings/errors; optionally upload `docs/generated` as an artifact. | ||
|
|
||
| ## Per-agent tasks | ||
| - Agents may expose `poe docs` locally; agent1 example runs `uv run python ../../scripts/generate_docs.py --agents-only --agents agent1`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Agent 1 | ||
| ======= | ||
|
|
||
| Package Documentation | ||
| --------------------- | ||
|
|
||
| .. automodule:: python_agent_template.agents.agent1 | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| CLI Entry Point | ||
| --------------- | ||
|
|
||
| .. automodule:: python_agent_template.agents.agent1.__main__ | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| try: | ||
| import tomllib | ||
| except ModuleNotFoundError: # Python < 3.11 | ||
| try: | ||
| import tomli as tomllib # type: ignore[import-not-found] | ||
| except ModuleNotFoundError: | ||
| tomllib = None # type: ignore[assignment] | ||
|
|
||
| PROJECT_ROOT = Path(__file__).resolve().parents[2] | ||
| sys.path.insert(0, str(PROJECT_ROOT)) | ||
| for src_path in PROJECT_ROOT.glob("agents/*/src"): | ||
| sys.path.insert(0, str(src_path)) | ||
|
|
||
| project = "python-agent-template" | ||
| author = "python-agent-template maintainers" | ||
pmalarme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _get_project_version(default: str = "0.0.0") -> str: | ||
| """Return the project version from pyproject.toml, or a default.""" | ||
|
|
||
| pyproject_path = PROJECT_ROOT / "pyproject.toml" | ||
| if tomllib is None or not pyproject_path.is_file(): | ||
| return default | ||
|
|
||
| try: | ||
| with pyproject_path.open("rb") as f: | ||
| data = tomllib.load(f) | ||
| except OSError as exc: | ||
| logger.warning("Failed to read %s; falling back to default version.", pyproject_path, exc_info=exc) | ||
| return default | ||
| except tomllib.TOMLDecodeError as exc: # type: ignore[union-attr] | ||
| logger.warning("Failed to parse %s; falling back to default version.", pyproject_path, exc_info=exc) | ||
| return default | ||
|
|
||
| version = ( | ||
| data.get("project", {}).get("version") | ||
| or data.get("tool", {}).get("poetry", {}).get("version") | ||
| ) | ||
| return version or default | ||
|
|
||
|
|
||
| version = _get_project_version() | ||
| release = version | ||
|
|
||
| extensions = [ | ||
| "sphinx.ext.autodoc", | ||
| "sphinx.ext.autosummary", | ||
| "sphinx.ext.napoleon", | ||
| "sphinx.ext.viewcode", | ||
| ] | ||
|
|
||
| try: | ||
| if tomllib is not None: | ||
| # Only enable when the TOML parser (and therefore the extension's deps) is available. | ||
| # Import is intentionally unused; it fails fast if the dependency stack is missing. | ||
| import sphinx_autodoc_typehints # noqa: F401 # pyright: ignore[reportMissingImports,reportUnusedImport] | ||
| extensions.append("sphinx_autodoc_typehints") | ||
| except Exception: | ||
| logger.warning("sphinx_autodoc_typehints not enabled; dependency stack missing.", exc_info=True) | ||
|
|
||
| autosummary_generate = True | ||
| autodoc_typehints = "description" | ||
| autodoc_default_options = { | ||
| "members": True, | ||
| "undoc-members": True, | ||
| "show-inheritance": True, | ||
| } | ||
|
|
||
| napoleon_google_docstring = True | ||
| napoleon_numpy_docstring = False | ||
|
|
||
| templates_path: list[str] = [] # set to ["_templates"] when the directory is added | ||
| exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] | ||
|
|
||
| html_theme = "alabaster" | ||
| html_static_path: list[str] = [] # set to ["_static"] when the directory is added | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Python Agent Template | ||
| ================================ | ||
|
|
||
| Welcome to the documentation for all agents in the template. | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 3 | ||
|
|
||
| agents/agent1/index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.