Makefile 1.89 KB
Newer Older
1
# Minimal Makefile for Sphinx documentation
Lianmin Zheng's avatar
Lianmin Zheng committed
2
3
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
4
SPHINXAUTOBUILD ?= sphinx-autobuild
Lianmin Zheng's avatar
Lianmin Zheng committed
5
6
SOURCEDIR     = .
BUILDDIR      = _build
7
PORT          ?= 8003
Lianmin Zheng's avatar
Lianmin Zheng committed
8
9
10

help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
11
12
13
	@echo ""
	@echo "Additional targets:"
	@echo "  serve       to build and serve documentation with auto-build and live reload"
Lianmin Zheng's avatar
Lianmin Zheng committed
14

15
# Compile Notebook files and record execution time
Chayenne's avatar
Chayenne committed
16
compile:
17
18
19
20
21
22
23
24
25
	@set -e; \
	echo "Starting Notebook compilation..."; \
	mkdir -p logs; \
	echo "Notebook execution timings:" > logs/timing.log; \
	START_TOTAL=$$(date +%s); \
	find $(SOURCEDIR) -path "*/_build/*" -prune -o -name "*.ipynb" -print0 | \
		parallel -0 -j3 --halt soon,fail=1 ' \
		NB_NAME=$$(basename {}); \
		START_TIME=$$(date +%s); \
26
27
		retry --delay=0 --times=3 -- \
			jupyter nbconvert --to notebook --execute --inplace "{}" \
28
29
30
31
32
33
34
35
36
37
38
39
40
			--ExecutePreprocessor.timeout=600 \
			--ExecutePreprocessor.kernel_name=python3; \
		RET_CODE=$$?; \
		END_TIME=$$(date +%s); \
		ELAPSED_TIME=$$((END_TIME - START_TIME)); \
		echo "$${NB_NAME}: $${ELAPSED_TIME}s" >> logs/timing.log; \
		exit $$RET_CODE' || exit 1; \
	END_TOTAL=$$(date +%s); \
	TOTAL_ELAPSED=$$((END_TOTAL - START_TOTAL)); \
	echo "---------------------------------" >> logs/timing.log; \
	echo "Total execution time: $${TOTAL_ELAPSED}s" >> logs/timing.log; \
	echo "All Notebook execution timings:" && cat logs/timing.log

41
42
43
44
45
46
47
# Serve documentation with auto-build and live reload
serve:
	@echo "Starting auto-build server at http://localhost:$(PORT)"
	@$(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)/html" \
		--port $(PORT) \
		--watch $(SOURCEDIR) \
		--re-ignore ".*\.(ipynb_checkpoints|pyc|pyo|pyd|git)"
Chayenne's avatar
Chayenne committed
48

49
.PHONY: help Makefile compile clean serve
Lianmin Zheng's avatar
Lianmin Zheng committed
50
51
52
53
54

%: Makefile
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean:
55
56
57
	find . -name "*.ipynb" -exec nbstripout {} \;
	rm -rf $(BUILDDIR)
	rm -rf logs