-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
194 lines (138 loc) · 4.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env make -f
#
# Makefile for recipe static site generator
#
# ---------------------------------------------------------------------------
#
# General setup
#
# Set default target
.DEFAULT_GOAL := test
# Decide if use python3 or python
ifeq (, $(@shell which python3))
py = python3
else
py = python
endif
# Decide if use pip3 or pip
ifeq (, $(@shell which pip3))
pip = pip3
else
pip = pip
endif
# Decide if use firefox or firefox.exe
ifeq (, $(@shell which firefox.exe))
browser = firefox.exe
else
browser = firefox
endif
# Detect OS
OS = $(shell uname -s)
# Defaults
ECHO = echo
# Make adjustments based on OS
ifneq (, $(findstring CYGWIN, $(OS)))
ECHO = /bin/echo -e
endif
# Colors and helptext
NO_COLOR = \033[0m
ACTION = \033[32;01m
OK_COLOR = \033[32;01m
ERROR_COLOR = \033[31;01m
WARN_COLOR = \033[33;01m
# Which makefile am I in?
WHERE-AM-I = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_MAKEFILE := $(call WHERE-AM-I)
# Echo some nice helptext based on the target comment
HELPTEXT = $(ECHO) "$(ACTION)--->" `egrep "^\# target: $(1) " $(THIS_MAKEFILE) | sed "s/\# target: $(1)[ ]*-[ ]* / /g"` "$(NO_COLOR)"
# ----------------------------------------------------------------------------
#
# Highlevel targets
#
# target: help - Displays help with targets available.
.PHONY: help
help:
@$(call HELPTEXT,$@)
@echo "Usage:"
@echo " make [target] ..."
@echo "target:"
@egrep "^# target:" Makefile | sed 's/# target: / /g'
# target: info - Displays versions.
.PHONY: info
info:
@${py} --version
@${py} -m pip --version
#@virtualenv --version
# target: validate - Validate code with pylint
.PHONY: validate
validate:
@pylint --rcfile=.pylintrc app tests
# target: validate-docker - Validate Dockerfile with hadolint
.PHONY: validate-docker
validate-docker:
@docker run --rm -i hadolint/hadolint < docker/Dockerfile_prod
@docker run --rm -i hadolint/hadolint < docker/Dockerfile_test
# target: validate-ci - Validate CircleCi config with CircleCi CLI
.PHONY: validate-ci
validate-ci:
@circleci config validate
# target: test-integration - Run tests in tests/integration with coverage.py
.PHONY: test-integration
test-integration: clean
@$(ECHO) "$(ACTION)---> Running all tests in tests/integration" "$(NO_COLOR)"
@${py} \
-m coverage run --rcfile=.coveragerc \
-m py.test -c .pytest.ini tests/integration
$(MAKE) clean-py
# target: test-unit - Run tests in tests/unit with coverage.py
.PHONY: test-unit
test-unit: clean
@$(ECHO) "$(ACTION)---> Running all tests in tests/unit" "$(NO_COLOR)"
@${py} \
-m coverage run --rcfile=.coveragerc \
-m py.test -c .pytest.ini tests/unit
$(MAKE) clean-py
# target: run-test test=test-file.py - Run one test file
.PHONY: run-test
run-test:
@${py} \
-m pytest --pylint --pylint-rcfile=.pylintrc $(test)
## target: exec-tests - Run all tests in tests/ with coverage.py
.PHONY: exec-tests
exec-tests: test-unit test-integration
# target: test - Run tests and display code coverage
.PHONY: test
test: validate exec-tests
${py} -m coverage report --rcfile=.coveragerc
$(MAKE) clean-cov
## target: test-html - Run tests and display detailed code coverage with html
.PHONY: test-html
test-html: exec-tests
${py} -m coverage html --rcfile=.coveragerc && ${browser} tests/coverage_html/index.html &
## target: clean-py - Remove generated python files
.PHONY: clean-py
clean-py:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
find . -name '.pytest_cache' -exec rm -fr {} +
## target: clean-cov - Remove generated coverage files
.PHONY: clean-cov
clean-cov:
rm -f .coverage
rm -rf tests/coverage_html
# target: clean - Remove all generated files
.PHONY: clean
clean: clean-py clean-cov
find . -name '*~' -exec rm -f {} +
find . -name '*.log*' -exec rm -fr {} +
# target: install - Install all Python packages specified in the .requirement.txt file
.PHONY: install
install:
${pip} install -r .requirements.txt
# target: install-dev - Install all Python packages for development
.PHONY: install-dev
install-dev:
${pip} install --upgrade pip
${pip} install --upgrade setuptools
${pip} install -r requirements/dev.txt