Skip to content

Commit f344732

Browse files
Merge pull request #1 from python-accelerator-middle-layer/notebooks-sphinx-gallery
Modifications to use sphinx gallery for the tutorials.
2 parents d21d478 + dccc4a2 commit f344732

13 files changed

Lines changed: 113 additions & 89 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Deploy Sphinx docs to GitHub Pages
33
on:
44
push:
55
branches: [main]
6+
pull_request:
67
workflow_dispatch:
78

89
permissions:
@@ -29,7 +30,7 @@ jobs:
2930
- name: Install docs dependencies
3031
run: |
3132
python -m pip install --upgrade pip
32-
pip install -r requirements.txt
33+
pip install -r docs-requirements.txt
3334
3435
- name: Build Sphinx docs
3536
run: ./build-docs.sh
@@ -44,6 +45,7 @@ jobs:
4445

4546
deploy:
4647
needs: build
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
4749
runs-on: ubuntu-latest
4850
environment:
4951
name: github-pages

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ instance/
7070

7171
# Sphinx documentation
7272
docs/_build/
73-
docs/source/_static/tutorials.zip
73+
docs/source/sg_execution_times.rst
74+
docs/source/tutorials/
7475

7576
# PyBuilder
7677
.pybuilder/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The documentation follows the [Diataxis approach](https://diataxis.fr/).
55
## Building the Docs
66

77
1. Create a virtual environment and activate it.
8-
2. Install the requirements with `pip install -r requirements.txt`.
8+
2. Install the requirements with `pip install -r docs-requirements.txt`.
99
3. Create a new branch. The main branch is protected so you can't push to it directly.
1010
4. Build the docs locally with `./build-docs.sh`. The new version is available in `docs/build/html/index.html`.
1111
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.

build-docs.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,4 @@ set -euo pipefail
55
rm -rf docs/build .jupyter_cache
66
mkdir -p docs/source/_static
77

8-
python - <<'PY'
9-
from pathlib import Path
10-
from zipfile import ZipFile, ZIP_DEFLATED
11-
12-
tutorials_dir = Path("docs/source/tutorials")
13-
archive = Path("docs/source/_static/tutorials.zip")
14-
15-
with ZipFile(archive, "w", compression=ZIP_DEFLATED) as zf:
16-
for path in tutorials_dir.rglob("*.ipynb"):
17-
zf.write(path, path.relative_to(tutorials_dir.parent))
18-
PY
19-
20-
sphinx-build -E -a -b html docs/source docs/build/html
21-
228
sphinx-build -E -a -b html docs/source docs/build/html

docs-requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sphinx~= 8.1
2+
pydata-sphinx-theme
3+
sphinx_copybutton
4+
myst_nb
5+
myst-parser
6+
sphinx_design
7+
sphinx-gallery

docs/source/_static/custom.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
a.gh-link,
22
a.gh-link:visited {
33
color: black !important;
4-
}
4+
}
5+
6+
.sphx-glr-download-link-note,
7+
.binder-badge,
8+
.lite-badge,
9+
.sphx-glr-download-jupyter,
10+
.sphx-glr-download-python,
11+
.sphx-glr-download-zip {
12+
display: none;
13+
}

docs/source/conf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"sphinx_copybutton",
1919
"myst_nb",
2020
"sphinx_design",
21+
"sphinx_gallery.gen_gallery",
2122
]
2223

2324
templates_path = ['_templates']
@@ -29,6 +30,28 @@
2930
"attrs_inline",
3031
]
3132

33+
sphinx_gallery_conf = {
34+
"examples_dirs": "tutorials_src",
35+
"gallery_dirs": "tutorials",
36+
37+
# Binder (cloud notebook)
38+
"binder": {
39+
"org": "python-accelerator-middle-layer",
40+
"repo": "documentation",
41+
"branch": "main",
42+
"binderhub_url": "https://mybinder.org",
43+
"dependencies": ["../../requirements.txt"],
44+
"use_jupyter_lab": True,
45+
},
46+
}
47+
48+
exclude_patterns += [
49+
"tutorials/*.ipynb",
50+
"tutorials/*.py",
51+
"tutorials/*.zip",
52+
"tutorials/*.codeobj.json",
53+
"tutorials_src/GALLERY_HEADER.rst"
54+
]
3255

3356
# -- Options for HTML output -------------------------------------------------
3457
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
@@ -42,3 +65,6 @@
4265
html_sidebars = {
4366
"reference/index": [],
4467
}
68+
html_theme_options = {
69+
"secondary_sidebar_items": ["page-toc","sg_download_links", "sg_launcher_links"],
70+
}

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The features include, among others:
1919
:hidden:
2020
:maxdepth: 1
2121
22-
tutorials/index
22+
Tutorials <tutorials/index>
2323
how-to/index
2424
explanation/index
2525
reference/index

docs/source/tutorials/index.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/source/tutorials/test_notebook.ipynb

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)