diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 19dc5ac..9760eef 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -3,6 +3,7 @@ name: Deploy Sphinx docs to GitHub Pages on: push: branches: [main] + pull_request: workflow_dispatch: permissions: @@ -29,7 +30,7 @@ jobs: - name: Install docs dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install -r docs-requirements.txt - name: Build Sphinx docs run: ./build-docs.sh @@ -44,6 +45,7 @@ jobs: deploy: needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest environment: name: github-pages diff --git a/.gitignore b/.gitignore index b12da35..3516b81 100644 --- a/.gitignore +++ b/.gitignore @@ -70,7 +70,8 @@ instance/ # Sphinx documentation docs/_build/ -docs/source/_static/tutorials.zip +docs/source/sg_execution_times.rst +docs/source/tutorials/ # PyBuilder .pybuilder/ diff --git a/README.md b/README.md index 2339160..5e72f47 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The documentation follows the [Diataxis approach](https://diataxis.fr/). ## Building the Docs 1. Create a virtual environment and activate it. -2. Install the requirements with `pip install -r requirements.txt`. +2. Install the requirements with `pip install -r docs-requirements.txt`. 3. Create a new branch. The main branch is protected so you can't push to it directly. 4. Build the docs locally with `./build-docs.sh`. The new version is available in `docs/build/html/index.html`. 5. When the local version looks good, push your changes and make a pull request. Pushes to main will build and deploy the new version. diff --git a/build-docs.sh b/build-docs.sh index 4cc4a62..67c3cdc 100755 --- a/build-docs.sh +++ b/build-docs.sh @@ -5,18 +5,4 @@ set -euo pipefail rm -rf docs/build .jupyter_cache mkdir -p docs/source/_static -python - <<'PY' -from pathlib import Path -from zipfile import ZipFile, ZIP_DEFLATED - -tutorials_dir = Path("docs/source/tutorials") -archive = Path("docs/source/_static/tutorials.zip") - -with ZipFile(archive, "w", compression=ZIP_DEFLATED) as zf: - for path in tutorials_dir.rglob("*.ipynb"): - zf.write(path, path.relative_to(tutorials_dir.parent)) -PY - -sphinx-build -E -a -b html docs/source docs/build/html - sphinx-build -E -a -b html docs/source docs/build/html diff --git a/docs-requirements.txt b/docs-requirements.txt new file mode 100644 index 0000000..1f9e5bb --- /dev/null +++ b/docs-requirements.txt @@ -0,0 +1,7 @@ +sphinx~= 8.1 +pydata-sphinx-theme +sphinx_copybutton +myst_nb +myst-parser +sphinx_design +sphinx-gallery \ No newline at end of file diff --git a/docs/source/_static/custom.css b/docs/source/_static/custom.css index 5485571..3e7ff8d 100644 --- a/docs/source/_static/custom.css +++ b/docs/source/_static/custom.css @@ -1,4 +1,13 @@ a.gh-link, a.gh-link:visited { color: black !important; -} \ No newline at end of file +} + +.sphx-glr-download-link-note, +.binder-badge, +.lite-badge, +.sphx-glr-download-jupyter, +.sphx-glr-download-python, +.sphx-glr-download-zip { + display: none; +} diff --git a/docs/source/conf.py b/docs/source/conf.py index 75095c3..1e8aaf9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,6 +18,7 @@ "sphinx_copybutton", "myst_nb", "sphinx_design", + "sphinx_gallery.gen_gallery", ] templates_path = ['_templates'] @@ -29,6 +30,28 @@ "attrs_inline", ] +sphinx_gallery_conf = { + "examples_dirs": "tutorials_src", + "gallery_dirs": "tutorials", + + # Binder (cloud notebook) + "binder": { + "org": "python-accelerator-middle-layer", + "repo": "documentation", + "branch": "main", + "binderhub_url": "https://mybinder.org", + "dependencies": ["../../requirements.txt"], + "use_jupyter_lab": True, + }, +} + +exclude_patterns += [ + "tutorials/*.ipynb", + "tutorials/*.py", + "tutorials/*.zip", + "tutorials/*.codeobj.json", + "tutorials_src/GALLERY_HEADER.rst" +] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output @@ -42,3 +65,6 @@ html_sidebars = { "reference/index": [], } +html_theme_options = { + "secondary_sidebar_items": ["page-toc","sg_download_links", "sg_launcher_links"], +} diff --git a/docs/source/index.md b/docs/source/index.md index befb39a..6c870f9 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -19,7 +19,7 @@ The features include, among others: :hidden: :maxdepth: 1 -tutorials/index +Tutorials how-to/index explanation/index reference/index diff --git a/docs/source/tutorials/index.md b/docs/source/tutorials/index.md deleted file mode 100644 index 532d104..0000000 --- a/docs/source/tutorials/index.md +++ /dev/null @@ -1,16 +0,0 @@ -# Tutorials - -Here you can find learning-oriented tutorials that guide you through the functionality of pyAML step by step. - -```{toctree} -:maxdepth: 1 - -test_notebook - -``` - -```{button-link} ../_static/tutorials.zip -:color: primary - -Download all tutorials -``` \ No newline at end of file diff --git a/docs/source/tutorials/test_notebook.ipynb b/docs/source/tutorials/test_notebook.ipynb deleted file mode 100644 index 6498186..0000000 --- a/docs/source/tutorials/test_notebook.ipynb +++ /dev/null @@ -1,48 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0fff98ba", - "metadata": {}, - "source": [ - "# Test notebook" - ] - }, - { - "cell_type": "markdown", - "id": "37d41d05", - "metadata": {}, - "source": [ - "```{note}\n", - "Download this notebook as {nb-download}`test_notebook.ipynb`." - ] - }, - { - "cell_type": "markdown", - "id": "e34e0556", - "metadata": {}, - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "pyaml-documentation", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.15" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/source/tutorials_src/GALLERY_HEADER.rst b/docs/source/tutorials_src/GALLERY_HEADER.rst new file mode 100644 index 0000000..331b3f6 --- /dev/null +++ b/docs/source/tutorials_src/GALLERY_HEADER.rst @@ -0,0 +1,4 @@ +Tutorials +========= + +Here you can find learning-oriented tutorials that guide you through the functionality of pyAML step by step. diff --git a/docs/source/tutorials_src/test_page.py b/docs/source/tutorials_src/test_page.py new file mode 100644 index 0000000..48e9d92 --- /dev/null +++ b/docs/source/tutorials_src/test_page.py @@ -0,0 +1,56 @@ +""" +Test page +================= + +This is a minimal Sphinx-Gallery example you can use to verify that: + +- the page is picked up by Sphinx-Gallery +- code cells are executed +- plots are rendered +- the Binder button appears on the generated page +""" + +# %% +# Imports +# ------- + +import numpy as np +import matplotlib.pyplot as plt + +# %% +# Create some data +# ---------------- + +x = np.linspace(0, 2 * np.pi, 200) +y = np.sin(x) + +# %% +# Plot the data +# ------------- + +fig, ax = plt.subplots(figsize=(6, 4)) +ax.plot(x, y, label="sin(x)") +ax.set_xlabel("x") +ax.set_ylabel("y") +ax.set_title("Sphinx-Gallery test plot") +ax.grid(True) +ax.legend() + +plt.show() + +# %% +# A second cell +# ------------- + +x2 = np.linspace(0, 2 * np.pi, 30) +y2 = np.cos(x2) + +fig, ax = plt.subplots(figsize=(6, 4)) +ax.scatter(x2, y2, label="cos(x)", marker="o") +ax.set_xlabel("x") +ax.set_ylabel("y") +ax.set_title("Second plot") +ax.grid(True) +ax.legend() + +plt.show() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 66ff829..515baaf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,3 @@ -sphinx~= 8.1 -pydata-sphinx-theme -sphinx_copybutton -myst_nb -myst-parser -sphinx_design \ No newline at end of file +numpy +matplotlib +pyaml \ No newline at end of file