-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·213 lines (149 loc) · 4.65 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/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
# target: tox - Run tox on project.
.PHONY: tox
tox:
@${py} -m tox
# target: build - Build pip package.
.PHONY: build
build: clean-build
@${py} setup.py bdist_wheel
@twine check dist/*
# target: release - Upload dist folder to pip. First runs tox and builds code
.PHONY: release
release: tox build
@twine upload dist/*
# target: install-local-build - Install dist package locally.
.PHONY: install-local-build
install-local-build:
@${pip} uninstall treevizer
@${pip} install dist/*.whl
# target: validate - Validate code with pylint
.PHONY: validate
validate:
@pylint --rcfile=.pylintrc treevizer
# 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 unittest discover tests.unit
$(MAKE) clean-py
# 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 unittest discover tests.integration
$(MAKE) clean-py
# target: test - Run tests and display code coverage
.PHONY: test
test: validate
@$(ECHO) "$(ACTION)---> Running all tests in tests/" "$(NO_COLOR)"
@${py} \
-m coverage run --rcfile=.coveragerc \
-m unittest discover tests
${py} -m coverage report --rcfile=.coveragerc
$(MAKE) clean
## 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-build - Remove all build files
.PHONY: clean-build
clean-build: clean-py
rm -rf treevizer.egg-info
rm -rf dist
rm -rf build
# target: clean - Remove all generated files
.PHONY: clean
clean: clean-py clean-build clean-cov
find . -name '*~' -exec rm -f {} +
find . -name '*.log*' -exec rm -fr {} +
# target: install - Install all Python packages specified in requirement.txt (requirements/prod.txt)
.PHONY: install
install:
${pip} install -r requirements.txt
# target: install-test - Install Python packages specified in requirement/test.txt
.PHONY: install-test
install-test:
${pip} install -r requirements/test.txt
# target: install-pip - Install Python packages specified in requirement/pip.txt
.PHONY: install-pip
install-pip:
${pip} install -r requirements/pip.txt
# target: setup-venv - Install venv and update to pip to latest. Run before make install.
.PHONY: setup-venv
setup-venv:
python3 -m venv .venv
. .venv/bin/activate && pip3 install --upgrade pip