From 479068f62a62bf3e018d8d217ca33d45b71be001 Mon Sep 17 00:00:00 2001 From: Luthaf Date: Mon, 25 Mar 2024 17:22:34 +0100 Subject: [PATCH] Allow building the website for a single example `nox -e example` will build example and then the website, `nox -e docs` will build all examples and the website at the end --- .gitignore | 1 - docs/src/.gitignore | 2 ++ docs/src/index.rst | 15 --------------- docs/src/index.rst.in | 6 ++++++ noxfile.py | 21 ++++++++++++++++++++- 5 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 docs/src/.gitignore delete mode 100644 docs/src/index.rst create mode 100644 docs/src/index.rst.in diff --git a/.gitignore b/.gitignore index 902390c1..1d8a3459 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ docs/src/examples/ *build* *egg-info/ -sg_execution_times.rst .nox/ diff --git a/docs/src/.gitignore b/docs/src/.gitignore new file mode 100644 index 00000000..74b62391 --- /dev/null +++ b/docs/src/.gitignore @@ -0,0 +1,2 @@ +sg_execution_times.rst +index.rst diff --git a/docs/src/index.rst b/docs/src/index.rst deleted file mode 100644 index e79fda36..00000000 --- a/docs/src/index.rst +++ /dev/null @@ -1,15 +0,0 @@ -COSMO Software Cookbook -======================= - -.. include:: ../../README.rst - :start-after: marker-intro-start - :end-before: marker-intro-end - -.. toctree:: - :caption: Table of Contents - :maxdepth: 1 - - examples/roy-gch/roy-gch - examples/lode-linear/lode-linear - examples/sample-selection/sample-selection - examples/gaas-map/gaas-map diff --git a/docs/src/index.rst.in b/docs/src/index.rst.in new file mode 100644 index 00000000..5cd31331 --- /dev/null +++ b/docs/src/index.rst.in @@ -0,0 +1,6 @@ +COSMO Software Cookbook +======================= + +.. include:: ../../README.rst + :start-after: marker-intro-start + :end-before: marker-intro-end diff --git a/noxfile.py b/noxfile.py index ed7dfd65..f9c1ec5e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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) @@ -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")