Skip to content
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

docs: optimise building with html-tutorial support #1146

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/1146.contributor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Optimised the documentation building workflow by providing control of whether
:ref:`tutorial <gv-tutorials>` ``jupyter notebook`` code cells are executed.
By default, code cells will only be executed when building the documentation
with either the ``make html`` or ``make html-tutorial`` commands.
(:user:`bjlittle`)
13 changes: 8 additions & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BUILDDIR = _build
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: Makefile clean doctest help html-docstring html-gallery html-noplot linkcheck serve-html
.PHONY: Makefile clean doctest help html-docstring html-gallery html-noplot html-tutorial linkcheck serve-html

clean:
-rm -rf $(BUILDDIR)
Expand All @@ -28,19 +28,22 @@ clean:
-rm -f $(SOURCEDIR)/gallery_carousel.txt

doctest:
@$(SPHINXBUILD) -b doctest -D plot_gallery=False -D plot_docstring=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/doctest"
@$(SPHINXBUILD) -b doctest -D plot_docstring=False -D plot_gallery=False -D plot_tutorial=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/doctest"

html-docstring:
@$(SPHINXBUILD) -b html -D plot_gallery=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
@$(SPHINXBUILD) -b html -D plot_gallery=False -D plot_tutorial=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"

html-gallery:
@$(SPHINXBUILD) -b html -D plot_docstring=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
@$(SPHINXBUILD) -b html -D plot_docstring=False -D plot_tutorial=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"

html-noplot:
@$(SPHINXBUILD) -b html -D plot_docstring=False -D plot_gallery=False -D plot_tutorial=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"

html-tutorial:
@$(SPHINXBUILD) -b html -D plot_docstring=False -D plot_gallery=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"

linkcheck:
@$(SPHINXBUILD) -b linkcheck -D plot_docstring=False -D plot_gallery=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/linkcheck"
@$(SPHINXBUILD) -b linkcheck -D plot_docstring=False -D plot_gallery=False -D plot_tutorial=False -d "$(BUILDDIR)/doctrees" $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/linkcheck"

# Spin up a local http server to view the rendered documentation.
# This is required for interactive examples to work.
Expand Down
31 changes: 24 additions & 7 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,28 @@ def generate_carousel(
Path(app.srcdir, fname).write_text(carousel)


def geovista_config(app: Sphinx) -> None:
def geovista_builder_inited(app: Sphinx) -> None:
"""Configure geovista sphinx options."""
# sanitise the config options
app.builder.config.plot_docstring = _bool_eval(app.builder.config.plot_docstring)
autolog(f"plot_docstring={app.builder.config.plot_docstring}", section="GeoVista")
plot_docstring = _bool_eval(app.builder.config.plot_docstring)
plot_gallery = _bool_eval(app.builder.config.plot_gallery)
plot_tutorial = _bool_eval(app.builder.config.plot_tutorial)

# overwrite the myst-nb sphinx configuration option that controls the
# notebook execution mode. this option has been pre-parsed by the sphinx
# state machine from this file (conf.py) or set by the default myst-nb app
# configuration. for further details see
# https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html
if not plot_tutorial:
# https://myst-nb.readthedocs.io/en/latest/configuration.html#execution
app.config["nb_execution_mode"] = "off"

# sanitise the config option from str to bool
app.builder.config.plot_docstring = plot_docstring

# report diagnostics
autolog(f"{plot_docstring=}", section="GeoVista")
autolog(f"{plot_gallery=}", section="GeoVista")
autolog(f"{plot_tutorial=}", section="GeoVista")


def geovista_carousel(
Expand All @@ -797,9 +812,11 @@ def setup(app: Sphinx) -> None:
# we require the output of this extension
app.setup_extension("sphinx_gallery.gen_gallery")
# register geovista options
app.add_config_value("plot_docstring", "True", "html")
# early configuration of geovista options
app.connect("builder-inited", geovista_config, priority=10)
app.add_config_value(name="plot_docstring", default="True", rebuild="html")
app.add_config_value(name="plot_tutorial", default="True", rebuild="html")
# early configuration of geovista options, see
# https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html
app.connect("builder-inited", geovista_builder_inited, priority=10)
# register callback for the autoapi event
app.connect("autoapi-skip-member", geovista_skip_member)
# register callback to generate gallery carousel
Expand Down
3 changes: 2 additions & 1 deletion docs/src/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ A collection of themed practical lessons to work though.

.. grid-item-card::
:text-align: center
:link: region-manifold-extraction.html
:link: gv-tutorials-region-manifold-extraction
:link-type: ref
bjlittle marked this conversation as resolved.
Show resolved Hide resolved

.. image:: ../_static/images/region-manifold-extraction.png
:alt: Region Manifold Extraction
Expand Down