Skip to content

Commit

Permalink
Generate API docs as part of Sphinx's build process
Browse files Browse the repository at this point in the history
This change has the benefit of supporting ReadTheDocs builds as
discussed in readthedocs/readthedocs.org#1139
  • Loading branch information
MarkusH committed Oct 2, 2020
1 parent 8aecccd commit b9988b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Generate and test API docs
run: |
make apidocs html
make html
env:
SPHINXOPTS: "-n -v -W --keep-going"
working-directory: ./docs
5 changes: 0 additions & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ help:

.PHONY: help Makefile


apidocs:
git clean -fdx "$(SOURCEDIR)/ref"
sphinx-apidoc --ext-autodoc --ext-intersphinx --separate --implicit-namespaces --no-toc -o "$(SOURCEDIR)/ref" ../crate

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
19 changes: 19 additions & 0 deletions docs/source/crate_operator_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,31 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import pathlib

from docutils.nodes import Element
from sphinx.addnodes import pending_xref
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
from sphinx.errors import NoUri


def run_apidoc(_):
from sphinx.ext import apidoc

argv = [
"--ext-autodoc",
"--ext-intersphinx",
"--separate",
"--implicit-namespaces",
"--no-toc",
"-o",
str(pathlib.Path(__file__).parent / "ref"),
str(pathlib.Path(__file__).parent.parent.parent / "crate"),
]
apidoc.main(argv)


def missing_reference(
app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: Element
) -> Element:
Expand Down Expand Up @@ -49,4 +67,5 @@ def missing_reference(


def setup(app):
app.connect("builder-inited", run_apidoc)
app.connect("missing-reference", missing_reference)

0 comments on commit b9988b9

Please sign in to comment.