File size: 715 Bytes
079c32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
JUPYTER ?= $(shell which jupyter)
NBCONVERT ?= ${JUPYTER} nbconvert

SOURCE  ?= .
IPYNBS  := $(shell find ${SOURCE} -name *.ipynb -not -name *.result.ipynb)
RESULTS := $(addsuffix .result.ipynb, $(basename ${IPYNBS}))

%.result.ipynb: %.ipynb
	cp "$(shell readlink -f $<)" "$(shell readlink -f $@)" && \
		cd "$(shell dirname $(shell readlink -f $<))" && \
		PYTHONPATH="$(shell dirname $(shell readlink -f $<)):${PYTHONPATH}" \
		$(NBCONVERT) --to notebook --inplace --execute "$(shell readlink -f $@)"

build: ${RESULTS}

all: build

clean:
	rm -rf \
		$(shell find ${SOURCE} -name *.result.ipynb)
	for nb in ${IPYNBS}; do \
		if [ -f $$nb ]; then \
			$(NBCONVERT) --clear-output --inplace $$nb; \
		fi; \
	done;