Skip to content

Commit

Permalink
Allow building the website for a single example
Browse files Browse the repository at this point in the history
`nox -e example` will build example and then the website,
`nox -e docs` will build all examples and the website at the end
  • Loading branch information
Luthaf committed Mar 25, 2024
1 parent 458605d commit 479068f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ docs/src/examples/

*build*
*egg-info/
sg_execution_times.rst

.nox/
2 changes: 2 additions & 0 deletions docs/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sg_execution_times.rst
index.rst
15 changes: 0 additions & 15 deletions docs/src/index.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/src/index.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
COSMO Software Cookbook
=======================

.. include:: ../../README.rst
:start-after: marker-intro-start
:end-before: marker-intro-end
21 changes: 20 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,17 @@ def example(session, name=name):
session.run("python", "generate-gallery.py", f"examples/{name}")
os.unlink(f"docs/src/examples/{name}/index.rst")

if "--no-build-docs" not in session.posargs:
session.notify("build_docs")


@nox.session(venv_backend="none")
def docs(session):
"""Run all examples and build the documentation"""

for example in EXAMPLES:
session.run("nox", "-e", example, external=True)
session.run("nox", "-e", example, "--", "--no-build-docs", external=True)

session.run("nox", "-e", "build_docs", external=True)


Expand All @@ -113,6 +117,21 @@ def build_docs(session):
if should_reinstall_dependencies(session, requirements=requirements):
session.install("-r", requirements)

with open("docs/src/index.rst", "w") as output:
with open("docs/src/index.rst.in") as fd:
output.write(fd.read())

output.write(".. toctree::\n")
output.write(" :caption: Table of Contents\n")
output.write(" :maxdepth: 1\n")
output.write("\n")

for file in glob.glob("docs/src/examples/*/*.rst"):
if os.path.basename(file) != "sg_execution_times.rst":
path = file[9:-4]

output.write(f" {path}\n")

session.run("sphinx-build", "-W", "-b", "html", "docs/src", "docs/build/html")


Expand Down

0 comments on commit 479068f

Please sign in to comment.