|
1 | | -.PHONY: html |
| 1 | +.PHONY: clean book |
2 | 2 |
|
3 | | -OBSHELL=/bin/bash |
| 3 | +.DEFAULT_GOAL = book |
4 | 4 |
|
5 | | -.DEFAULT_GOAL = html |
| 5 | +NB_DIR = modules |
| 6 | +EXEC_NB_DIR = book/_modules |
6 | 7 |
|
7 | | -LESSONS_DIR = lessons |
8 | | -GENERATED_LESSONS_DIR = site/lessons |
| 8 | +MARKDOWNS = $(wildcard $(NB_DIR)/*.md) |
| 9 | +NOTEBOOKS = $(patsubst $(NB_DIR)/%.md, $(EXEC_NB_DIR)/%.ipynb, $(MARKDOWNS)) |
9 | 10 |
|
10 | 11 | _requirements.installed: |
11 | 12 | pip install -q -r requirements.txt |
12 | 13 | touch _requirements.installed |
13 | 14 |
|
14 | | -MARKDOWNS = $(wildcard $(LESSONS_DIR)/*.md) |
15 | | -MD_OUTPUTS = $(patsubst $(LESSONS_DIR)/%.md, $(GENERATED_LESSONS_DIR)/%.md, $(MARKDOWNS)) |
16 | | -NOTEBOOKS = $(patsubst %.md, %.ipynb, $(MD_OUTPUTS)) |
| 15 | +$(EXEC_NB_DIR): |
| 16 | + mkdir book/_modules |
17 | 17 |
|
18 | | -.SECONDARY: $(MD_OUTPUTS) $(NOTEBOOKS) |
| 18 | +$(EXEC_NB_DIR)/%.ipynb:$(NB_DIR)/%.md $(EXEC_NB_DIR) |
| 19 | + @# Jupytext will also catch and print execution errors |
| 20 | + @# unless a cell is marked with the `raises-exception` tag |
| 21 | + jupytext --execute --to ipynb --output $@ $< |
19 | 22 |
|
20 | | -$(GENERATED_LESSONS_DIR)/%.ipynb:$(LESSONS_DIR)/%.md site/lessons site/lessons/images |
21 | | - # This does not work, due to bug in notedown; see https://github.com/aaren/notedown/issues/53 |
22 | | - #notedown --match=python --precode='%matplotlib inline' $< > $@ |
23 | | - notedown --match=python $< > $@ |
24 | | - jupyter nbconvert --execute --inplace $@ --ExecutePreprocessor.timeout=-1 |
25 | | - |
26 | | -%.md:%.ipynb |
27 | | - jupyter nbconvert --to=mdoutput --output="$(notdir $@)" --output-dir=$(GENERATED_LESSONS_DIR) $< |
28 | | -# $(eval NBSTRING := [📂 Download lesson notebook](.\/$(basename $(notdir $@)).ipynb)\n\n) |
29 | | -# sed -i'.bak' '1s/^/$(NBSTRING)/' $@ |
30 | | - |
31 | | -site/lessons: |
32 | | - mkdir -p book/lessons |
33 | | - |
34 | | -site/lessons/images: |
35 | | - ln -s ${PWD}/lessons/images ${PWD}/site/lessons/images |
36 | | - |
37 | | -html: site/lessons _requirements.installed $(NOTEBOOKS) $(MD_OUTPUTS) |
38 | | - @export SPHINXOPTS=-W; make -C site html |
39 | | - cp $(GENERATED_LESSONS_DIR)/*.ipynb book/build/html/lessons/ |
| 23 | +book: _requirements.installed $(NOTEBOOKS) |
| 24 | + @export SPHINXOPTS=-W; make -C book html |
40 | 25 |
|
41 | 26 | clean: |
42 | | - rm -rf $(GENERATED_LESSONS_DIR)/* |
| 27 | + make -C book clean |
| 28 | + |
0 commit comments