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