Skip to content

Commit 5ef3abe

Browse files
committed
Use multiprocessing for build
1 parent 830bcdf commit 5ef3abe

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

build.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/usr/bin/env python3
22

3-
import logging
43
import subprocess
4+
from functools import partial
5+
from multiprocessing import Pool
56
from pathlib import Path
67

7-
logger = logging.getLogger(__name__)
8-
98
# TODO: Only update files changed since last run
109
# TODO: Add conversion tool from existing answer notebooks
10+
# TODO: add test for errors when individual tasks fail
1111

1212

1313
def answer2exercise(infile, outfile):
1414
"""
1515
Convert answer notebooks to exercise notebooks
16-
16+
1717
TODO: Fail if output notebook is empty?
1818
1919
"""
@@ -49,23 +49,20 @@ def run_slide(infile):
4949
def main():
5050
p = Path(".")
5151

52-
# TODO: add test for errors
53-
slide_fns = p.glob("*slides.ipynb")
54-
for slide_fn in sorted(slide_fns):
55-
print(f"Running {slide_fn}")
56-
run_slide(slide_fn)
57-
58-
print("ipynb slides -> reveal.js html")
59-
slide_fns = p.glob("*slides.ipynb")
60-
for slide_fn in sorted(slide_fns):
61-
slide2html(slide_fn)
62-
63-
print("Convert answers to exercises")
64-
answers = p.glob("*answers.ipynb")
65-
for answer_nb in sorted(answers):
66-
exercise_nb = str(answer_nb).replace("answer", "exercise")
52+
slide_fns = sorted(str(x) for x in p.glob("*slides.ipynb"))
53+
answer_nbs = sorted(str(x) for x in p.glob("*answers.ipynb"))
54+
exercise_nbs = [x.replace("answer", "exercise") for x in answer_nbs]
55+
56+
with Pool(4) as pool:
57+
print("Running notebooks")
58+
pool.map(run_slide, slide_fns)
59+
60+
print("ipynb slides -> reveal.js html")
61+
pool.map(slide2html, slide_fns)
62+
63+
print("Convert answers to exercises")
6764
# print(f'{answer_nb} -> {exercise_nb}')
68-
answer2exercise(str(answer_nb), exercise_nb)
65+
pool.starmap(answer2exercise, zip(answer_nbs, exercise_nbs))
6966

7067
# copy over assets
7168

0 commit comments

Comments
 (0)