-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (60 loc) · 2.27 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
.PHONY: macbook check uninstall install compile init clean
macbook: compile
stow git
VENV := ./.virtualenv
# Ensure base dependencies are installed
check:
@which stow
# Create a virtualenv into which we will install python dependencies
# We have to stick a stow ignore file in there, or else a user could
# stow it into their homedir...
install: check
ifeq ($(shell which python3),)
@virtualenv $(VENV)
else
@pyvenv $(VENV)
endif
@source $(VENV)/bin/activate && pip install yasha yamlreader
@source $(VENV)/bin/activate && which yasha
@source $(VENV)/bin/activate && which yamlreader
echo ".*" > $(VENV)/.stow-local-ignore
# Remove virtualenv, which will essentially uninstall the python dependencies
uninstall:
rm -rf $(VENV)
PACKAGES = $(shell find . -maxdepth 1 -type d -not -path "$(VENV)" -not -name .git -not -name .)
TEMPLATES = $(shell find . -name "*.j2" -not -path "$(VENV)/*")
RENDERED = $(shell find . -name "*.j2" -not -path "$(VENV)/*" |sed 's/.j2//')
KERNEL = $(shell uname -s)
# 1. Merge template config files (secret and non) into a temp file; note that the yamlreader
# merge will use whichever file specified last in the parameter order as the winner when
# duplicates are found.
# 2. Render all of the jinja templates in the project, excepting for the virtualenv created to
# store our dependencies.
compile:
$(eval VARFILE = $(shell mktemp -t XXXXXX.yaml))
@source $(VENV)/bin/activate && yamlreader environment.yaml secrets.yaml > $(VARFILE)
@$(foreach f, ${TEMPLATES}, \
echo rendering $f; \
source $(VENV)/bin/activate && yasha -v $(VARFILE) --kernel=$(KERNEL) $f; \
)
@rm -f $(VARFILE)
# List the templates in this project
list:
@$(foreach f, ${TEMPLATES}, \
echo $f; \
)
# CAUTION: this is destructive, it is for development only.
# This will result in broken symlinks if you did not uninstall the package first
# with `stow -D`. If you then try to recompile (`make compile`) and reinstall using
# stow, stow will complain and you will manually need to unlink the original broken symlink.
clean:
@$(foreach f, ${RENDERED}, \
git clean -fX $f; \
)
# generate the project-specific gitignores
build:
@$(foreach d, ${PACKAGES}, \
pushd $d >/dev/null; \
find . -name '*.j2' -print | sed -e 's|^\./||' -e 's/.j2//' > .gitignore; \
popd >/dev/null; \
)