Skip to content

Commit

Permalink
Update win_batch_md2ipynb.py
Browse files Browse the repository at this point in the history
  • Loading branch information
astonzhang authored Dec 19, 2018
1 parent 71089e9 commit e7b92e5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions build/win_batch_md2ipynb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from distutils.dir_util import copy_tree
import glob
import nbformat
import notedown
Expand All @@ -6,34 +7,36 @@
import sys
import time

# To access data/imgs/gluonbook in upper level.
os.chdir('build')

def mkdir_if_not_exist(path):
if not os.path.exists(os.path.join(*path)):
os.makedirs(os.path.join(*path))

# timeout for each notebook, in sec
# Timeout for each notebook, in sec
timeout = 20 * 60

# the files will be ingored for execution
ignore_execution = []
# The files will be ingored for execution
ignore_execution = ['chapter_computational-performance/async-computation.md']

reader = notedown.MarkdownReader(match='strict')

do_eval = int(os.environ.get('EVAL', True))

for chap in glob.glob('chapter_*'):
for chap in glob.glob(os.path.join('..', 'chapter_*')):
mkdir_if_not_exist(['build', 'win_ipynb', chap])
mds = filter(lambda x: x.endswith('md'), os.listdir(chap))
for md in mds:
if md != 'index.md':
in_md = os.path.join(chap, md)
out_nb = os.path.join('build', 'win_ipynb', in_md[:-2] + '.ipynb')
print('---', in_md)
out_nb = os.path.join('win_ipynb', in_md[3:-2] + '.ipynb')
print('---', in_md[3:])
# read
with open(in_md, 'r', encoding="utf8") as f:
notebook = reader.read(f)

if do_eval and not any([i in input_fn for i in ignore_execution]):
if do_eval and chap[3:] + '/' + md not in ignore_execution:
tic = time.time()
notedown.run(notebook, timeout)
print('=== Finished evaluation in %f sec'%(time.time()-tic))
Expand All @@ -44,5 +47,3 @@ def mkdir_if_not_exist(path):

with open(out_nb, 'w', encoding="utf8") as f:
f.write(nbformat.writes(notebook))


0 comments on commit e7b92e5

Please sign in to comment.