Skip to content

Commit e2aa67a

Browse files
committed
Add script to update notebook output
1 parent e5a8647 commit e2aa67a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.internal/update_notebooks.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# all this script does is wrap the line:
4+
# find . -type f -name "*.ipynb" | xargs -P3 -I{} jupyter nbconvert --to notebook --execute --inplace {}
5+
6+
7+
#
8+
# 1) Initialization - `git pull` + create-new-branch
9+
#
10+
echo "======= Init ======="
11+
cd "$(git rev-parse --show-toplevel)"
12+
13+
git checkout main
14+
git pull
15+
16+
echo
17+
git checkout -b "updating_notebooks_$(date '+%Y.%m.%d_%H.%M')"
18+
echo
19+
20+
echo "Updating pip"
21+
python -m pip install -U -r requirements.txt -r requirements_tests.txt
22+
23+
#
24+
# 2) Update the notebooks
25+
#
26+
echo
27+
echo
28+
echo "======= Updating notebooks ======="
29+
# disable popping browser for `show(qprog)`
30+
export BROWSER=echo
31+
32+
# note: there's a max of 3 running jobs per user, so we limit the threads to 3
33+
# # test all bernstein-vazirani notebooks
34+
# find . -type f -name "*bernstein*.ipynb" | xargs -P2 -I{} jupyter nbconvert --to notebook --execute --inplace {}
35+
# test all algorithms
36+
# find algorithms/ -type f -name "*.ipynb" | xargs -P3 -I{} jupyter nbconvert --to notebook --execute --inplace {}
37+
find algorithms/ -type f -name "*.ipynb" | xargs -P3 -I{} sh -c 'cd "$(dirname {})" && jupyter nbconvert --to notebook --execute --inplace "$(basename {})"'
38+
# # test 3 notebooks
39+
# find . -type f -name "*.ipynb" | head -n 3 | xargs -P3 -I{} jupyter nbconvert --to notebook --execute --inplace {}
40+
# # test all notebooks
41+
# find algorithms applications tutorials -type f -name "*.ipynb" | xargs -P3 -I{} jupyter nbconvert --to notebook --execute --inplace {}
42+
43+
#
44+
# 3) Commit the changes + open PR
45+
#
46+
echo
47+
echo
48+
echo "======= Creating PR ======="
49+
# running twice so that we'd include the pre-commit updates
50+
git commit -a -m "Updating notebooks output" || git commit -a -m "Updating notebooks output"
51+
# # running once, so that failure on pre-commit would fail this script
52+
# git commit -a -m "Updating notebooks output" || { echo "pre-commit failed. please fix manually"; exit 1; }
53+
54+
gh pr create --fill
55+
gh pr view --web

0 commit comments

Comments
 (0)