|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import logging |
4 | 3 | import subprocess |
| 4 | +from functools import partial |
| 5 | +from multiprocessing import Pool |
5 | 6 | from pathlib import Path |
6 | 7 |
|
7 | | -logger = logging.getLogger(__name__) |
8 | | - |
9 | 8 | # TODO: Only update files changed since last run |
10 | 9 | # TODO: Add conversion tool from existing answer notebooks |
| 10 | +# TODO: add test for errors when individual tasks fail |
11 | 11 |
|
12 | 12 |
|
13 | 13 | def answer2exercise(infile, outfile): |
14 | 14 | """ |
15 | 15 | Convert answer notebooks to exercise notebooks |
16 | | - |
| 16 | +
|
17 | 17 | TODO: Fail if output notebook is empty? |
18 | 18 |
|
19 | 19 | """ |
@@ -49,23 +49,20 @@ def run_slide(infile): |
49 | 49 | def main(): |
50 | 50 | p = Path(".") |
51 | 51 |
|
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") |
67 | 64 | # print(f'{answer_nb} -> {exercise_nb}') |
68 | | - answer2exercise(str(answer_nb), exercise_nb) |
| 65 | + pool.starmap(answer2exercise, zip(answer_nbs, exercise_nbs)) |
69 | 66 |
|
70 | 67 | # copy over assets |
71 | 68 |
|
|
0 commit comments