Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/nbval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: nbval

on: [push]

jobs:
docker-build-and-nbval:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('poetry.lock') }}

# This build and push step does the same thing as `make docker-build`, but
# makes it easier to store and load caches, which is why we use it instead
- name: Build and Save Layers Locally
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: python4compscience

- name: List Available Images
run: docker images

- name: Run NBVAL over all chapters
run: make docker-nbval
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM debian:bullseye-slim

RUN apt-get update -y && apt-get install -y texlive-xetex latexmk texlive-xetex \
texlive-fonts-extra fonts-freefont-otf python3 python3-pip git zile
texlive-fonts-extra fonts-freefont-otf python3 python3-pip git zile wget

COPY poetry.lock pyproject.toml /opt/

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ pdf: book/*-*.ipynb
poetry run jupyter-book build book --builder pdflatex

nbval:
poetry run pytest -v --nbval book/*.ipynb --sanitize-with book/static/nbval_sanitize.cfg
@echo "Testing all chapters (apart from 18) with --nbval"
poetry run pytest -v --nbval book --sanitize-with book/static/nbval_sanitize.cfg \
--ignore=book/18-environments.ipynb --ignore=book/_build
@echo "Testing chapter 18 with --nbval-lax"
poetry run pytest -v --nbval-lax book/18-environments.ipynb



docker-all:
Expand Down
13,465 changes: 41 additions & 13,424 deletions book/15-visualising-data.ipynb

Large diffs are not rendered by default.

8,098 changes: 47 additions & 8,051 deletions book/16-scipy.ipynb

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions book/18-environments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@
"id": "82715cd6",
"metadata": {},
"source": [
"**Tidy up**"
"**Tidy up**: remove files created in this section"
]
},
{
Expand All @@ -1647,16 +1647,9 @@
"outputs": [],
"source": [
"!rm -rf /tmp/cowsay-python\n",
"!rm -rf myvirtualenv-copy"
"!rm -rf myvirtualenv-copy\n",
"!rm -f requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bd9e1fa3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
19 changes: 19 additions & 0 deletions book/info.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* <2022-01-05 Wed 07:42> Notes on nbval:

** Chapters with matplotlib output
- for chapter 15 (matplotlib) [and other with matplotlib], we run into fails if svg+xml output is saved
- For some of the fails, I have created entries in [file:static/nbvas_sanitize.cfg] to ignore the changes (and commented out)
- Update on closer inspection: in the past, we didn't save the output, and thus the problem never occurred.
- But what does nbval do if the cells are empty, and it computes output?
- if we do not save output, then nbval will not complain about the empty cells
- if an exception occurs, it will report a fail.
- So --nbval on empty output cells behaves like --nbval-lax on saved output
- So not saving the output might be the right way, as jupyter-book executes the
notebooks anyway when computing pdf and html
(And that's what we did before my recent changes, I just had to remind myself ...)

** Extra treatment of Chapter 18 Environments
- should not execute automatically (because the description of creating
virtual envs is tailored to running it on a mac with Anaconda).
- achieved via instruction in [file:_config.yml]
- should be skipped by nbval for same reasons (use --ignore switch for that)
22 changes: 22 additions & 0 deletions book/static/nbval_sanitize.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,25 @@ replace: TIMEIT-OUTPUT
[dictionary-keys-values-items]
regex: dict_[\s\S]*\(\[[\s\S]*\]\)
replace: DICTIONARY-DATA

# The following rules are helpful if we attempt to include the svg+xml output from matplotlib in the notebooks.
#
#[matplotlib-path-id]
#regex: id="[0-9a-zA-Z]+"
#replace: PATH-ID
#
#[matplotlib-clip-path-url]
#regex: clip-path="url\(#[0-9a-zA-Z]+\)"
#replace: CLIPPATH-URL
#
#[matplotlib-xlink-href]
#regex: xlink:href="#[0-9a-zA-Z]+"
#replace: XLINK-HREF
#
#[date-stamp]
#regex: \d{2,4}-\d{1,2}-\d{2,4}
#replace: DATE-STAMP
#
#[time-stamp]
#regex: \d{2}:\d{2}:\d{2}.\d{6}
#replace: TIME-STAMP