1 ## ========================================
2 ## Commands for both workshop and lesson websites.
5 MAKEFILES=Makefile $(wildcard *.mk)
8 PARSER=bin/markdown_ast.rb
11 # Check Python 3 is installed and determine if it's called via python3 or python
12 # (https://stackoverflow.com/a/4933395)
13 PYTHON3_EXE := $(shell which python3 2>/dev/null)
14 ifneq (, $(PYTHON3_EXE))
15 ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
21 PYTHON_EXE := $(shell which python 2>/dev/null)
22 ifneq (, $(PYTHON_EXE))
23 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
24 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
25 ifneq (3, ${PYTHON_VERSION_MAJOR})
26 $(error "Your system does not appear to have Python 3 installed.")
30 $(error "Your system does not appear to have any Python installed.")
36 .PHONY : commands clean files
40 ## commands : show all commands.
42 @grep -h -E '^##' ${MAKEFILES} | sed -e "s/## //g"
44 ## docker-serve : use docker to build the site
46 docker run --rm -it -v ${PWD}:/srv/jekyll -p 127.0.0.1:4000:4000 jekyll/jekyll:${JEKYLL_VERSION} make serve
48 ## serve : run a local server.
52 ## site : build files but do not run a server.
56 # repo-check : check repository settings.
58 @bin/repo_check.py -s .
60 ## clean : clean up junk files.
64 @rm -rf bin/__pycache__
65 @find . -name .DS_Store -exec rm {} \;
66 @find . -name '*~' -exec rm {} \;
67 @find . -name '*.pyc' -exec rm {} \;
69 ## clean-rmd : clean intermediate R files (that need to be committed to the repo).
74 ## ----------------------------------------
75 ## Commands specific to workshop websites.
77 .PHONY : workshop-check
79 ## workshop-check : check workshop homepage.
81 @${PYTHON} bin/workshop_check.py .
83 ## ----------------------------------------
84 ## Commands specific to lesson websites.
86 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
89 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
90 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
92 # Lesson source files in the order they appear in the navigation menu.
97 $(sort $(wildcard _episodes/*.md)) \
99 $(sort $(wildcard _extras/*.md)) \
102 # Generated lesson files in the order they appear in the navigation menu.
105 ${DST}/conduct/index.html \
106 ${DST}/setup/index.html \
107 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
108 ${DST}/reference/index.html \
109 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
110 ${DST}/license/index.html
112 ## lesson-md : convert Rmarkdown files to markdown
113 lesson-md : ${RMD_DST}
115 _episodes/%.md: _episodes_rmd/%.Rmd
116 @bin/knit_lessons.sh $< $@
118 ## lesson-check : validate lesson Markdown.
119 lesson-check : lesson-fixme
120 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
122 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
124 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
126 ## unittest : run unit tests on checking tools.
128 @${PYTHON} bin/test_lesson_check.py
130 ## lesson-files : show expected names of generated files for debugging.
132 @echo 'RMD_SRC:' ${RMD_SRC}
133 @echo 'RMD_DST:' ${RMD_DST}
134 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
135 @echo 'HTML_DST:' ${HTML_DST}
137 ## lesson-fixme : show FIXME markers embedded in source files.
139 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
141 #-------------------------------------------------------------------------------
142 # Include extra commands if available.
143 #-------------------------------------------------------------------------------