-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_and_export.py
More file actions
executable file
·35 lines (26 loc) · 861 Bytes
/
run_and_export.py
File metadata and controls
executable file
·35 lines (26 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# This could be easier done in bash but I prefer to just do it in python
import glob,subprocess,os,shutil,sys
os.chdir(os.path.dirname(__file__))
files = sys.argv[1:]
if not files:
files = glob.glob('*.ipynb')
for nb in files:
nb = os.path.splitext(nb)[0]
cmd = ['jupyter-nbconvert',
'--ExecutePreprocessor.timeout=-1',
'--to','notebook',
'--execute',
f'{nb}.ipynb',
'--output',f'{nb}.tmp.ipynb']
s = subprocess.call(cmd)
if s:
raise subprocess.CalledProcessError()
shutil.move(f'{nb}.tmp.ipynb',f'{nb}.ipynb')
cmd = ['jupyter-nbconvert',
'--to','html',
'--output',f'{nb}.html',
f'{nb}.ipynb']
s = subprocess.call(cmd)
if s:
raise subprocess.CalledProcessError()