|
| 1 | +## ======================================== |
| 2 | +## Commands for both workshop and lesson websites. |
| 3 | + |
| 4 | +# Settings |
| 5 | +MAKEFILES=Makefile $(wildcard *.mk) |
| 6 | +JEKYLL=bundle config set --local path .vendor/bundle && bundle install && bundle update && bundle exec jekyll |
| 7 | +PARSER=bin/markdown_ast.rb |
| 8 | +DST=_site |
| 9 | + |
| 10 | +# Find Docker |
| 11 | +DOCKER := $(shell which docker 2>/dev/null) |
| 12 | + |
| 13 | +# Check Python 3 is installed and determine if it's called via python3 or python |
| 14 | +# (https://stackoverflow.com/a/4933395) |
| 15 | +PYTHON3_EXE := $(shell which python3 2>/dev/null) |
| 16 | +ifneq (, $(PYTHON3_EXE)) |
| 17 | + ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE)))) |
| 18 | + PYTHON := $(PYTHON3_EXE) |
| 19 | + endif |
| 20 | +endif |
| 21 | + |
| 22 | +ifeq (,$(PYTHON)) |
| 23 | + PYTHON_EXE := $(shell which python 2>/dev/null) |
| 24 | + ifneq (, $(PYTHON_EXE)) |
| 25 | + PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1))) |
| 26 | + PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL}) |
| 27 | + ifeq (3, ${PYTHON_VERSION_MAJOR}) |
| 28 | + PYTHON := $(PYTHON_EXE) |
| 29 | + else |
| 30 | + PYTHON_NOTE = "Your system does not appear to have Python 3 installed." |
| 31 | + endif |
| 32 | + else |
| 33 | + PYTHON_NOTE = "Your system does not appear to have any Python installed." |
| 34 | + endif |
| 35 | +endif |
| 36 | + |
| 37 | + |
| 38 | +# Default target |
| 39 | +.DEFAULT_GOAL := commands |
| 40 | + |
| 41 | +## I. Commands for both workshop and lesson websites |
| 42 | +## ================================================= |
| 43 | + |
| 44 | +.PHONY: site docker-serve repo-check clean clean-rmd |
| 45 | + |
| 46 | +## * serve : render website and run a local server |
| 47 | +serve : lesson-md index.md |
| 48 | + ${JEKYLL} serve |
| 49 | + |
| 50 | +## * site : build website but do not run a server |
| 51 | +site : lesson-md index.md |
| 52 | + ${JEKYLL} build |
| 53 | + |
| 54 | +## * docker-serve : use Docker to serve the site |
| 55 | +docker-serve : |
| 56 | +ifeq (, $(DOCKER)) |
| 57 | + $(error Your system does not appear to have Docker installed) |
| 58 | +else |
| 59 | + @$(DOCKER) pull carpentries/lesson-docker:latest |
| 60 | + @$(DOCKER) run --rm -it \ |
| 61 | + -v $${PWD}:/home/rstudio \ |
| 62 | + -p 4000:4000 \ |
| 63 | + -p 8787:8787 \ |
| 64 | + -e USERID=$$(id -u) \ |
| 65 | + -e GROUPID=$$(id -g) \ |
| 66 | + carpentries/lesson-docker:latest |
| 67 | +endif |
| 68 | + |
| 69 | +## * repo-check : check repository settings |
| 70 | +repo-check : python |
| 71 | + @${PYTHON} bin/repo_check.py -s . |
| 72 | + |
| 73 | +## * clean : clean up junk files |
| 74 | +clean : |
| 75 | + @rm -rf ${DST} |
| 76 | + @rm -rf .sass-cache |
| 77 | + @rm -rf bin/__pycache__ |
| 78 | + @rm -rf .vendor |
| 79 | + @rm -rf .bundle |
| 80 | + @rm -f Gemfile.lock |
| 81 | + @find . -name .DS_Store -exec rm {} \; |
| 82 | + @find . -name '*~' -exec rm {} \; |
| 83 | + @find . -name '*.pyc' -exec rm {} \; |
| 84 | + |
| 85 | +## * clean-rmd : clean intermediate R files (that need to be committed to the repo) |
| 86 | +clean-rmd : |
| 87 | + @rm -rf ${RMD_DST} |
| 88 | + @rm -rf fig/rmd-* |
| 89 | + |
| 90 | + |
| 91 | +## |
| 92 | +## II. Commands specific to workshop websites |
| 93 | +## ================================================= |
| 94 | + |
| 95 | +.PHONY : workshop-check |
| 96 | + |
| 97 | +## * workshop-check : check workshop homepage |
| 98 | +workshop-check : python |
| 99 | + @${PYTHON} bin/workshop_check.py . |
| 100 | + |
| 101 | + |
| 102 | +## |
| 103 | +## III. Commands specific to lesson websites |
| 104 | +## ================================================= |
| 105 | + |
| 106 | +.PHONY : lesson-check lesson-md lesson-files lesson-fixme install-rmd-deps |
| 107 | + |
| 108 | +# RMarkdown files |
| 109 | +RMD_SRC = $(wildcard _episodes_rmd/*.Rmd) |
| 110 | +RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC)) |
| 111 | + |
| 112 | +# Lesson source files in the order they appear in the navigation menu. |
| 113 | +MARKDOWN_SRC = \ |
| 114 | + index.md \ |
| 115 | + CODE_OF_CONDUCT.md \ |
| 116 | + setup.md \ |
| 117 | + $(sort $(wildcard _episodes/*.md)) \ |
| 118 | + reference.md \ |
| 119 | + $(sort $(wildcard _extras/*.md)) \ |
| 120 | + LICENSE.md |
| 121 | + |
| 122 | +# Generated lesson files in the order they appear in the navigation menu. |
| 123 | +HTML_DST = \ |
| 124 | + ${DST}/index.html \ |
| 125 | + ${DST}/conduct/index.html \ |
| 126 | + ${DST}/setup/index.html \ |
| 127 | + $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \ |
| 128 | + ${DST}/reference.html \ |
| 129 | + $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \ |
| 130 | + ${DST}/license/index.html |
| 131 | + |
| 132 | +## * install-rmd-deps : Install R packages dependencies to build the RMarkdown lesson |
| 133 | +install-rmd-deps: |
| 134 | + @${SHELL} bin/install_r_deps.sh |
| 135 | + |
| 136 | +## * lesson-md : convert Rmarkdown files to markdown |
| 137 | +lesson-md : ${RMD_DST} |
| 138 | + |
| 139 | +_episodes/%.md: _episodes_rmd/%.Rmd install-rmd-deps |
| 140 | + @mkdir -p _episodes |
| 141 | + @$(SHELL) bin/knit_lessons.sh $< $@ |
| 142 | + |
| 143 | +## * lesson-check : validate lesson Markdown |
| 144 | +lesson-check : python lesson-fixme |
| 145 | + @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md |
| 146 | + |
| 147 | +## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace |
| 148 | +lesson-check-all : python |
| 149 | + @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive |
| 150 | + |
| 151 | +## * unittest : run unit tests on checking tools |
| 152 | +unittest : python |
| 153 | + @${PYTHON} bin/test_lesson_check.py |
| 154 | + |
| 155 | +## * lesson-files : show expected names of generated files for debugging |
| 156 | +lesson-files : |
| 157 | + @echo 'RMD_SRC:' ${RMD_SRC} |
| 158 | + @echo 'RMD_DST:' ${RMD_DST} |
| 159 | + @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC} |
| 160 | + @echo 'HTML_DST:' ${HTML_DST} |
| 161 | + |
| 162 | +## * lesson-fixme : show FIXME markers embedded in source files |
| 163 | +lesson-fixme : |
| 164 | + @grep --fixed-strings --word-regexp --line-number --no-messages FIXME ${MARKDOWN_SRC} || true |
| 165 | + |
| 166 | +## |
| 167 | +## IV. Auxililary (plumbing) commands |
| 168 | +## ================================================= |
| 169 | + |
| 170 | +.PHONY : commands python |
| 171 | + |
| 172 | +## * commands : show all commands. |
| 173 | +commands : |
| 174 | + @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST) |
| 175 | + |
| 176 | +python : |
| 177 | +ifeq (, $(PYTHON)) |
| 178 | + $(error $(PYTHON_NOTE)) |
| 179 | +else |
| 180 | + @: |
| 181 | +endif |
| 182 | + |
| 183 | +index.md : |
| 184 | +ifeq (, $(wildcard index.md)) |
| 185 | + $(error index.md not found) |
| 186 | +else |
| 187 | + @: |
| 188 | +endif |
0 commit comments