clarify comment on python check block
[rnaseq-cwl-training.git] / Makefile
1 ## ========================================
2 ## Commands for both workshop and lesson websites.
3
4 # Settings
5 MAKEFILES=Makefile $(wildcard *.mk)
6 JEKYLL=jekyll
7 JEKYLL_VERSION=3.8.5
8 PARSER=bin/markdown_ast.rb
9 DST=_site
10
11 # Check Python 3 is installed and determine if it's called via python3 or python
12 # (https://stackoverflow.com/a/4933395)
13 ifneq (, $(shell which python3))
14   PYTHON := python3
15 else ifneq (, $(shell which python))
16   PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
17   PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
18   ifneq (3, ${PYTHON_VERSION_MAJOR})
19     $(error "Your system does not appear to have Python 3 installed.")
20   endif
21   PYTHON := python
22 else
23     $(error "Your system does not appear to have any Python installed.")
24 endif
25
26
27 # Controls
28 .PHONY : commands clean files
29 .NOTPARALLEL:
30 all : commands
31
32 ## commands         : show all commands.
33 commands :
34         @grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'
35
36 ## docker-serve     : use docker to build the site
37 docker-serve :
38         docker run --rm -it -v ${PWD}:/srv/jekyll -p 127.0.0.1:4000:4000 jekyll/jekyll:${JEKYLL_VERSION} make serve
39
40 ## serve            : run a local server.
41 serve : lesson-md
42         ${JEKYLL} serve
43
44 ## site             : build files but do not run a server.
45 site : lesson-md
46         ${JEKYLL} build
47
48 # repo-check        : check repository settings.
49 repo-check :
50         @bin/repo_check.py -s .
51
52 ## clean            : clean up junk files.
53 clean :
54         @rm -rf ${DST}
55         @rm -rf .sass-cache
56         @rm -rf bin/__pycache__
57         @find . -name .DS_Store -exec rm {} \;
58         @find . -name '*~' -exec rm {} \;
59         @find . -name '*.pyc' -exec rm {} \;
60
61 ## clean-rmd        : clean intermediate R files (that need to be committed to the repo).
62 clean-rmd :
63         @rm -rf ${RMD_DST}
64         @rm -rf fig/rmd-*
65
66 ## ----------------------------------------
67 ## Commands specific to workshop websites.
68
69 .PHONY : workshop-check
70
71 ## workshop-check   : check workshop homepage.
72 workshop-check :
73         @${PYTHON} bin/workshop_check.py .
74
75 ## ----------------------------------------
76 ## Commands specific to lesson websites.
77
78 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
79
80 # RMarkdown files
81 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
82 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
83
84 # Lesson source files in the order they appear in the navigation menu.
85 MARKDOWN_SRC = \
86   index.md \
87   CODE_OF_CONDUCT.md \
88   setup.md \
89   $(sort $(wildcard _episodes/*.md)) \
90   reference.md \
91   $(sort $(wildcard _extras/*.md)) \
92   LICENSE.md
93
94 # Generated lesson files in the order they appear in the navigation menu.
95 HTML_DST = \
96   ${DST}/index.html \
97   ${DST}/conduct/index.html \
98   ${DST}/setup/index.html \
99   $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
100   ${DST}/reference/index.html \
101   $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
102   ${DST}/license/index.html
103
104 ## lesson-md        : convert Rmarkdown files to markdown
105 lesson-md : ${RMD_DST}
106
107 _episodes/%.md: _episodes_rmd/%.Rmd
108         @bin/knit_lessons.sh $< $@
109
110 ## lesson-check     : validate lesson Markdown.
111 lesson-check : lesson-fixme
112         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
113
114 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
115 lesson-check-all :
116         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
117
118 ## unittest         : run unit tests on checking tools.
119 unittest :
120         @${PYTHON} bin/test_lesson_check.py
121
122 ## lesson-files     : show expected names of generated files for debugging.
123 lesson-files :
124         @echo 'RMD_SRC:' ${RMD_SRC}
125         @echo 'RMD_DST:' ${RMD_DST}
126         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
127         @echo 'HTML_DST:' ${HTML_DST}
128
129 ## lesson-fixme     : show FIXME markers embedded in source files.
130 lesson-fixme :
131         @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
132
133 #-------------------------------------------------------------------------------
134 # Include extra commands if available.
135 #-------------------------------------------------------------------------------
136
137 -include commands.mk