-
Notifications
You must be signed in to change notification settings - Fork 0
Add API docs GH page and README updates #10
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
4 commits
Select commit
Hold shift + click to select a range
b2a4511
Add pydoctor API doc generation and GitHub Pages publishing
cretz 274c490
Replace pydoctor with Sphinx and autodoc_pydantic for API docs
cretz 46c1141
Remove temporary PR trigger from docs workflow
cretz e947398
Hide class prefix in right-hand TOC member entries
cretz 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Docs | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pages: write | ||
| id-token: write | ||
|
|
||
| # Allow one concurrent deployment, cancelling in-progress runs. | ||
| concurrency: | ||
| group: pages | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: github-pages | ||
| url: ${{ steps.deployment.outputs.page_url }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - run: uv sync | ||
|
|
||
| - name: Generate docs | ||
| run: uv run poe generate-docs | ||
|
|
||
| - uses: actions/upload-pages-artifact@v3 | ||
| with: | ||
| path: _site | ||
|
|
||
| - id: deployment | ||
| uses: actions/deploy-pages@v4 | ||
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 |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| .pytest_cache | ||
| .ruff_cache | ||
| .venv | ||
| .doctrees | ||
| __pycache__ | ||
| _site | ||
| scripts/docgen/api |
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,9 @@ | ||
| /* Hide the bottom-of-page footer bar. */ | ||
| .bottom-of-page { | ||
| display: none; | ||
| } | ||
|
|
||
| /* Restore bottom spacing the hidden bar used to provide below the prev/next links. */ | ||
| .related-pages { | ||
| margin-bottom: 1.5rem; | ||
| } |
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,5 @@ | ||
| {{ objname | escape | underline }} | ||
|
|
||
| .. currentmodule:: {{ module }} | ||
|
|
||
| .. auto{{ objtype }}:: {{ objname }} |
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,5 @@ | ||
| {{ objname | escape | underline }} | ||
|
|
||
| .. currentmodule:: {{ module }} | ||
|
|
||
| .. autoclass:: {{ objname }} |
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,59 @@ | ||
| {# Modules listed here only expose the named classes in the left nav. Every | ||
| class is still listed in the on-page table below and gets its own page (the | ||
| non-nav ones are generated as orphans by _generate_class_pages in conf.py). | ||
| Keep in sync with NAV_ONLY in conf.py. #} | ||
| {% set nav_only = { | ||
| "baseten.client.managementapi": ["ApiClient", "AsyncApiClient"], | ||
| "baseten.client.inferenceapi": ["ApiClient", "AsyncApiClient"], | ||
| "baseten.client.modelconfig": ["ModelConfig"], | ||
| } %} | ||
| {{ fullname | escape | underline }} | ||
|
|
||
| .. automodule:: {{ fullname }} | ||
| :no-members: | ||
|
|
||
| {% block classes %} | ||
| {% if classes %} | ||
| .. rubric:: Classes | ||
|
|
||
| .. autosummary:: | ||
| {% if fullname not in nav_only %}:toctree: | ||
| {% endif %}:nosignatures: | ||
| {% for item in classes %} | ||
| {{ item }} | ||
| {%- endfor %} | ||
| {% endif %} | ||
| {% endblock %} | ||
|
|
||
| {% block functions %} | ||
| {% if functions %} | ||
| .. rubric:: Functions | ||
|
|
||
| .. autosummary:: | ||
| :toctree: | ||
| {% for item in functions %} | ||
| {{ item }} | ||
| {%- endfor %} | ||
| {% endif %} | ||
| {% endblock %} | ||
|
|
||
| {% if fullname in nav_only %} | ||
| .. toctree:: | ||
| :hidden: | ||
| {% for item in nav_only[fullname] %} | ||
| {{ fullname }}.{{ item }} | ||
| {%- endfor %} | ||
| {% endif %} | ||
|
|
||
| {% block modules %} | ||
| {% if modules %} | ||
| .. rubric:: Modules | ||
|
|
||
| .. autosummary:: | ||
| :toctree: | ||
| :recursive: | ||
| {% for item in modules %} | ||
| {{ item }} | ||
| {%- endfor %} | ||
| {% endif %} | ||
| {% endblock %} |
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,86 @@ | ||
| """Sphinx configuration for the API docs. | ||
|
|
||
| Build with ``poe generate-docs``, which runs ``sphinx-build`` over this | ||
| directory into ``_site``. Uses autosummary (recursive) to walk the package and | ||
| autodoc to import and document it, with autodoc_pydantic rendering the pydantic | ||
| models. | ||
| """ | ||
|
|
||
| import importlib | ||
| import inspect | ||
| import pathlib | ||
|
|
||
| project = "Baseten Python SDK" | ||
| html_title = "Baseten SDK" | ||
| html_theme = "furo" | ||
| templates_path = ["_templates"] | ||
| html_static_path = ["_static"] | ||
| html_css_files = ["custom.css"] | ||
|
|
||
| extensions = [ | ||
| "sphinx.ext.autodoc", | ||
| "sphinx.ext.autosummary", | ||
| "sphinx.ext.intersphinx", | ||
| "sphinx.ext.napoleon", | ||
| "sphinxcontrib.autodoc_pydantic", | ||
| ] | ||
|
|
||
| # httpx ships no Sphinx inventory (objects.inv), so it cannot be linked here. | ||
| intersphinx_mapping = { | ||
| "python": ("https://docs.python.org/3", None), | ||
| "pydantic": ("https://docs.pydantic.dev/latest", None), | ||
| } | ||
|
|
||
| autosummary_generate = True | ||
| # The public API is re-exported into package __init__s via imports; without this | ||
| # autosummary would treat those names as imported members and skip them. | ||
| autosummary_imported_members = True | ||
| autodoc_default_options = {"members": True, "show-inheritance": True} | ||
| autodoc_typehints = "description" | ||
| # Members are one-per-class-page, so drop the class prefix in the right-hand TOC. | ||
| toc_object_entries_show_parents = "hide" | ||
|
|
||
| # Render pydantic models without the inherited BaseModel boilerplate. | ||
| autodoc_pydantic_model_show_config_summary = False | ||
| autodoc_pydantic_model_show_validator_summary = False | ||
| autodoc_pydantic_model_show_json = False | ||
| autodoc_pydantic_model_member_order = "bysource" | ||
|
|
||
| # For these modules, only the listed classes appear in the left nav. Every other | ||
| # class still gets its own page (generated as an orphan below) and is listed in | ||
| # the module's on-page table, but is kept out of the sidebar. Keep in sync with | ||
| # the matching table in _templates/autosummary/module.rst. | ||
| NAV_ONLY = { | ||
| "baseten.client.managementapi": ["ApiClient", "AsyncApiClient"], | ||
| "baseten.client.inferenceapi": ["ApiClient", "AsyncApiClient"], | ||
| "baseten.client.modelconfig": ["ModelConfig"], | ||
| } | ||
|
|
||
|
|
||
| def _generate_class_pages(app): | ||
| """Generate per-class stub pages for the NAV_ONLY modules. | ||
|
|
||
| autosummary couples page generation to nav inclusion (its ``:toctree:`` | ||
| both writes the stub and adds it to the sidebar). To give every class a | ||
| page while keeping only the allowlisted ones in the nav, we generate the | ||
| stubs ourselves: allowlisted classes are normal pages (wired into the nav by | ||
| a hidden toctree in the module template), the rest are orphans. | ||
| """ | ||
| api_dir = pathlib.Path(app.srcdir) / "api" | ||
| api_dir.mkdir(exist_ok=True) | ||
| for module_name, nav_classes in NAV_ONLY.items(): | ||
| module = importlib.import_module(module_name) | ||
| for name in getattr(module, "__all__", []): | ||
| if not inspect.isclass(getattr(module, name)): | ||
| continue | ||
| header = ":orphan:\n\n" if name not in nav_classes else "" | ||
| (api_dir / f"{module_name}.{name}.rst").write_text( | ||
| f"{header}{name}\n{'=' * len(name)}\n\n" | ||
| f".. currentmodule:: {module_name}\n\n" | ||
| f".. autoclass:: {name}\n", | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
|
|
||
| def setup(app): | ||
| app.connect("builder-inited", _generate_class_pages) |
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,13 @@ | ||
| Baseten Python SDK | ||
| ================== | ||
|
|
||
| This site is the **API reference** for the Baseten Python SDK, generated from | ||
| the source. For installation, usage, and examples, see the project on GitHub: | ||
| `basetenlabs/baseten-python <https://github.com/basetenlabs/baseten-python>`_. | ||
|
|
||
| .. autosummary:: | ||
| :toctree: api | ||
| :recursive: | ||
| :caption: API Reference | ||
|
|
||
| baseten.client |
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.