Skip to content

Commit 4bdcb69

Browse files
ColCarrolltwiecki
authored andcommitted
Add file to run all notebooks
1 parent a28bdac commit 4bdcb69

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/run_notebooks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@
88
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
99
NOTEBOOK_DIR = os.path.join(BASE_DIR, 'docs', 'source', 'notebooks')
1010

11+
1112
def list_notebooks():
1213
"""Get an iterator of filepaths to notebooks in NOTEBOOK_DIR"""
1314
return glob.glob(os.path.join(NOTEBOOK_DIR, '*.ipynb'))
1415

16+
1517
def execute_notebook(notebook_path):
1618
"""Run and overwrite a notebook file."""
1719
ep = ExecutePreprocessor(timeout=-1)
1820
with open(notebook_path, 'r') as buff:
1921
nb = nbformat.read(buff, as_version=nbformat.NO_CONVERT)
2022
try:
2123
t0 = time.time()
22-
_ = ep.preprocess(nb, {'metadata': {'path': NOTEBOOK_DIR}})
24+
ep.preprocess(nb, {'metadata': {'path': NOTEBOOK_DIR}})
2325
t1 = time.time()
2426

27+
except KeyboardInterrupt:
28+
raise
29+
2530
except BaseException as e:
2631
t1 = time.time()
2732
return False, 'Failed after {:.1f}s:\n{}'.format(t1 - t0, str(e))
@@ -31,8 +36,9 @@ def execute_notebook(notebook_path):
3136

3237
return True, 'Succeeded after {:.1f}s'.format(t1 - t0)
3338

39+
3440
def run_all_notebooks():
35-
"""Tries to re-run all notebooks. Prints failures at end."""
41+
"""Try to re-run all notebooks. Print failures at end."""
3642
failed = []
3743
for notebook_path in list_notebooks():
3844
print('Executing {}'.format(os.path.basename(notebook_path)))
@@ -46,6 +52,5 @@ def run_all_notebooks():
4652
print('\n'.join(failed))
4753

4854

49-
5055
if __name__ == '__main__':
5156
run_all_notebooks()

0 commit comments

Comments
 (0)