Skip to content

Commit d36180c

Browse files
authored
Merge pull request #8 from afeld/check-change
check the change for every notebook in CI
2 parents 68851c8 + 7c68993 commit d36180c

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- lecture_2.ipynb
3232
- lecture_3.ipynb
3333
- lecture_4.ipynb
34-
- lecture_5.ipynb
34+
# - lecture_5.ipynb # gets a different .similarity() score locally vs. CI
3535
# - lecture_5_exercise.ipynb # has incomplete code
3636
- lecture_6.ipynb
3737
steps:
@@ -55,4 +55,4 @@ jobs:
5555
run: pipenv install
5656

5757
- name: Confirm notebook hasn't changed
58-
run: pipenv run ./scripts/update.sh ${{ matrix.notebook }}
58+
run: pipenv run ./scripts/check_change.sh ${{ matrix.notebook }}

scripts/diffable.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,46 @@
22
import re
33
import sys
44

5+
6+
def is_pip_upgrade_msg(line):
7+
return isinstance(line, str) and re.match(r"WARNING.+pip version|upgrade pip", line)
8+
9+
10+
def is_vid(cell):
11+
try:
12+
text = cell["outputs"][0]["data"]["text/plain"][0]
13+
except (IndexError, KeyError, TypeError):
14+
return False
15+
16+
return text == "<IPython.core.display.Video object>"
17+
18+
519
input_str = sys.stdin.read()
620
notebook = json.loads(input_str)
721

22+
# nbconvert wants to embed videos, so skip them
23+
notebook["cells"] = [cell for cell in notebook["cells"] if not is_vid(cell)]
24+
825
for cell in notebook["cells"]:
26+
if "execution_count" in cell:
27+
# ignore all the execution count numbers
28+
cell["execution_count"] = None
29+
930
if cell["cell_type"] != "code":
1031
continue
1132

33+
# ignore any system command output
34+
if cell["source"][0].startswith("!"):
35+
cell["outputs"] = []
36+
37+
# filter out pip upgrade warnings
38+
cell["outputs"] = [line for line in cell["outputs"] if not is_pip_upgrade_msg(line)]
39+
1240
for output in cell["outputs"]:
41+
if "execution_count" in output:
42+
# ignore all the execution count numbers
43+
output["execution_count"] = 1
44+
1345
# clear HTML output, since it often has generated IDs (from displacy, plotly, etc.) that change with each execution
1446
if "data" in output and "text/html" in output["data"]:
1547
cell["outputs"] = []

0 commit comments

Comments
 (0)