Skip to content

Commit

Permalink
Add test that nbs load
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed Jul 8, 2019
1 parent 2a16a4a commit c5eb6a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ jobs:
versionSpec: '3.6'
architecture: 'x64'

# Install nbformat
- script: |
pip install nbformat
displayName: 'Install nbformat'
continueOnError: false
# check that notebooks are stripped out. if they aren't that means the committer doesn't have the correct configuration for the stripout filter.
- script: |
echo "Trying to load all notebooks"
tools/read-nbs
echo "Check we are starting with clean git checkout"
if [ -n "$(git status -uno -s)" ]; then echo "git status is not clean"; false; fi
Expand All @@ -51,4 +60,5 @@ jobs:
git status -s # display the status to see which nbs need cleaning up
if [ -n "$(git status -uno -s)" ]; then echo -e "!!! Detected unstripped out notebooks\n!!!Remember to run tools/run-after-git-clone"; false; fi
displayName: 'Detect unstripped out notebook commits'
failOnStderr: true
continueOnError: false
17 changes: 17 additions & 0 deletions tools/read-nbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import nbformat, os
from pathlib import Path

def read_nbs(path):
"Check all notebooks in `path` (and subfolders) can be opened"
path,nb_files = Path(path),[]
for p,d,f in os.walk(path): nb_files += [Path(p)/f_ for f_ in f if f_.endswith('.ipynb')]
for nb in nb_files:
try:
with open(nb, 'r') as f: _ = nbformat.reads(f.read(), as_version=4)
except Exception as e:
print(f"{nb} is corrupted and can't be opened.")
raise e

read_nbs('nbs')

0 comments on commit c5eb6a7

Please sign in to comment.