Skip to content

Commit 0f2a23b

Browse files
authored
Merge pull request #31 from fangohr/nbval-review
- Making nbval pass - Add additional workflow for nbval
2 parents fa44c70 + 7fc607c commit 0f2a23b

File tree

8 files changed

+177
-21487
lines changed

8 files changed

+177
-21487
lines changed

.github/workflows/nbval.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: nbval
2+
3+
on: [push]
4+
5+
jobs:
6+
docker-build-and-nbval:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Set up Docker Buildx
12+
uses: docker/setup-buildx-action@v1
13+
14+
- name: Cache Docker layers
15+
uses: actions/cache@v2
16+
with:
17+
path: /tmp/.buildx-cache
18+
key: ${{ runner.os }}-buildx-${{ hashFiles('poetry.lock') }}
19+
restore-keys: |
20+
${{ runner.os }}-buildx-${{ hashFiles('poetry.lock') }}
21+
22+
# This build and push step does the same thing as `make docker-build`, but
23+
# makes it easier to store and load caches, which is why we use it instead
24+
- name: Build and Save Layers Locally
25+
uses: docker/build-push-action@v2
26+
with:
27+
context: ./
28+
file: ./Dockerfile
29+
load: true
30+
cache-from: type=local,src=/tmp/.buildx-cache
31+
cache-to: type=local,dest=/tmp/.buildx-cache
32+
tags: python4compscience
33+
34+
- name: List Available Images
35+
run: docker images
36+
37+
- name: Run NBVAL over all chapters
38+
run: make docker-nbval

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM debian:bullseye-slim
22

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

66
COPY poetry.lock pyproject.toml /opt/
77

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ pdf: book/*-*.ipynb
2222
poetry run jupyter-book build book --builder pdflatex
2323

2424
nbval:
25-
poetry run pytest -v --nbval book/*.ipynb --sanitize-with book/static/nbval_sanitize.cfg
25+
@echo "Testing all chapters (apart from 18) with --nbval"
26+
poetry run pytest -v --nbval book --sanitize-with book/static/nbval_sanitize.cfg \
27+
--ignore=book/18-environments.ipynb --ignore=book/_build
28+
@echo "Testing chapter 18 with --nbval-lax"
29+
poetry run pytest -v --nbval-lax book/18-environments.ipynb
30+
2631

2732

2833
docker-all:

book/15-visualising-data.ipynb

Lines changed: 41 additions & 13424 deletions
Large diffs are not rendered by default.

book/16-scipy.ipynb

Lines changed: 47 additions & 8051 deletions
Large diffs are not rendered by default.

book/18-environments.ipynb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@
16361636
"id": "82715cd6",
16371637
"metadata": {},
16381638
"source": [
1639-
"**Tidy up**"
1639+
"**Tidy up**: remove files created in this section"
16401640
]
16411641
},
16421642
{
@@ -1647,16 +1647,9 @@
16471647
"outputs": [],
16481648
"source": [
16491649
"!rm -rf /tmp/cowsay-python\n",
1650-
"!rm -rf myvirtualenv-copy"
1650+
"!rm -rf myvirtualenv-copy\n",
1651+
"!rm -f requirements.txt"
16511652
]
1652-
},
1653-
{
1654-
"cell_type": "code",
1655-
"execution_count": null,
1656-
"id": "bd9e1fa3",
1657-
"metadata": {},
1658-
"outputs": [],
1659-
"source": []
16601653
}
16611654
],
16621655
"metadata": {

book/info.org

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* <2022-01-05 Wed 07:42> Notes on nbval:
2+
3+
** Chapters with matplotlib output
4+
- for chapter 15 (matplotlib) [and other with matplotlib], we run into fails if svg+xml output is saved
5+
- For some of the fails, I have created entries in [file:static/nbvas_sanitize.cfg] to ignore the changes (and commented out)
6+
- Update on closer inspection: in the past, we didn't save the output, and thus the problem never occurred.
7+
- But what does nbval do if the cells are empty, and it computes output?
8+
- if we do not save output, then nbval will not complain about the empty cells
9+
- if an exception occurs, it will report a fail.
10+
- So --nbval on empty output cells behaves like --nbval-lax on saved output
11+
- So not saving the output might be the right way, as jupyter-book executes the
12+
notebooks anyway when computing pdf and html
13+
(And that's what we did before my recent changes, I just had to remind myself ...)
14+
15+
** Extra treatment of Chapter 18 Environments
16+
- should not execute automatically (because the description of creating
17+
virtual envs is tailored to running it on a mac with Anaconda).
18+
- achieved via instruction in [file:_config.yml]
19+
- should be skipped by nbval for same reasons (use --ignore switch for that)

book/static/nbval_sanitize.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,25 @@ replace: TIMEIT-OUTPUT
1313
[dictionary-keys-values-items]
1414
regex: dict_[\s\S]*\(\[[\s\S]*\]\)
1515
replace: DICTIONARY-DATA
16+
17+
# The following rules are helpful if we attempt to include the svg+xml output from matplotlib in the notebooks.
18+
#
19+
#[matplotlib-path-id]
20+
#regex: id="[0-9a-zA-Z]+"
21+
#replace: PATH-ID
22+
#
23+
#[matplotlib-clip-path-url]
24+
#regex: clip-path="url\(#[0-9a-zA-Z]+\)"
25+
#replace: CLIPPATH-URL
26+
#
27+
#[matplotlib-xlink-href]
28+
#regex: xlink:href="#[0-9a-zA-Z]+"
29+
#replace: XLINK-HREF
30+
#
31+
#[date-stamp]
32+
#regex: \d{2,4}-\d{1,2}-\d{2,4}
33+
#replace: DATE-STAMP
34+
#
35+
#[time-stamp]
36+
#regex: \d{2}:\d{2}:\d{2}.\d{6}
37+
#replace: TIME-STAMP

0 commit comments

Comments
 (0)