From 524cd1cf68519121767a9249090b6d3ff76bb3dc Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Tue, 19 Mar 2024 17:43:06 -0400 Subject: [PATCH] attempt to get jupyter book running --- .github/workflows/build-gh-pages.yaml | 4 ++++ .../preprocess-notebook-attachments.py | 22 +++++++++++++++++++ _config.yml | 2 +- _toc.yml | 7 ++++-- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/preprocess-notebook-attachments.py diff --git a/.github/workflows/build-gh-pages.yaml b/.github/workflows/build-gh-pages.yaml index 8c9eef9..2949afa 100644 --- a/.github/workflows/build-gh-pages.yaml +++ b/.github/workflows/build-gh-pages.yaml @@ -24,6 +24,10 @@ jobs: pip install -r requirements.txt pip install jupyter-book + - name: Preprocess attachments + run: | + python .github/workflows/preprocess-notebook-attachments.py + # Build the book - name: Build the book run: | diff --git a/.github/workflows/preprocess-notebook-attachments.py b/.github/workflows/preprocess-notebook-attachments.py new file mode 100644 index 0000000..9d1098c --- /dev/null +++ b/.github/workflows/preprocess-notebook-attachments.py @@ -0,0 +1,22 @@ +# from https://github.com/executablebooks/jupyter-book/issues/1087#issuecomment-1969119486 + +import base64 +import json +import glob + +filenames = glob.glob('*ipynb') + +for fn in filenames: + with open(fn) as f: + nb = json.load(f) + + attachments = [cell.get('attachments') for cell in nb['cells']] + attachments = [a for a in attachments if a] + + for attachment in attachments: + for name, data in attachment.items(): + for filetype, encoded in data.items(): + print(f'{name} ({filetype})') + img_data = base64.b64decode(encoded) + with open(f'attachment:{name}', 'wb') as img: + img.write(img_data) diff --git a/_config.yml b/_config.yml index 9108cae..8bda60d 100644 --- a/_config.yml +++ b/_config.yml @@ -12,7 +12,7 @@ only_build_toc_files: false # Force re-execution of notebooks on each build. # See https://jupyterbook.org/content/execute.html execute: - execute_notebooks: auto + execute_notebooks: 'off' # Define the name of the latex output file for PDF builds latex: diff --git a/_toc.yml b/_toc.yml index 118d362..5aa986a 100644 --- a/_toc.yml +++ b/_toc.yml @@ -2,6 +2,9 @@ # Learn more at https://jupyterbook.org/customize/toc.html format: jb-book -root: Tutorial 0 - Overview +root: README chapters: -- file: Tutorial 1 - \ No newline at end of file +- file: pvanalytics-slideshow +- file: RdTools tutorial +- file: rdtools-availability +- file: solar-data-tools-demo