This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
233 lines (183 loc) Β· 4.43 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
DEBUG := 1
ENVIRON := development
FLASK := application.py
_HOST := ::1
_PORT := 5000
CMD_GIT := git
CMD_NPM := npm
CMD_VENV := virtualenv
DIR_VENV := venv
VER_PY := 3.9
CMD_PIP := $(DIR_VENV)/bin/pip$(VER_PY)
CMD_PY := $(DIR_VENV)/bin/python$(VER_PY)
CMD_FLASK := $(DIR_VENV)/bin/flask
CMD_BLACK := $(DIR_VENV)/bin/black
CMD_ISORT := $(DIR_VENV)/bin/isort
CMD_PYLINT := $(DIR_VENV)/bin/pylint
CMD_PYREV := $(DIR_VENV)/bin/pyreverse
CMD_PYTEST := $(DIR_VENV)/bin/pytest
DIR_SHORTER := shorter
DIR_TESTS := tests
DIR_THEMES := themes
DIR_DTHEME := $(DIR_THEMES)/default
DIR_DTSTAT := $(DIR_DTHEME)/static
DIR_DNDMOD := $(DIR_DTHEME)/node_modules
TGT_BULMA := $(DIR_DTSTAT)/bulma.min.css
.PHONY: help
help:
@echo "make shorter"
@echo "ββββββββββββ"
@echo
@echo "venv install virtualenv"
@echo "requirements install requirements into venv"
@echo
@echo "lint run pylint"
@echo "plot run pyreverse"
@echo "sort run isort"
@echo "black run black"
@echo "test run pytest"
@echo "tcov, tcovh run test coverage (html)"
@echo
@echo "clean show files to clean"
@echo "cleanup clean files unknown to git"
@echo
@echo "run run application"
@echo "shell launch a shell"
@echo
@echo " π¦"
@echo
###
# plumbing
$(DIR_VENV):
$(CMD_VENV) -p "python$(VER_PY)" "$(DIR_VENV)"
$(CMD_PIP) install -U pip setuptools wheel
.PHONY: requirements requirements-dev requirements-mysql
requirements: $(CMD_FLASK)
$(CMD_FLASK): $(DIR_VENV)
$(CMD_PIP) install -r "requirements.txt"
requirements-dev: $(CMD_BLACK) $(CMD_ISORT) $(CMD_PYLINT) $(CMD_PYREV) $(CMD_PYTEST)
$(CMD_BLACK) $(CMD_ISORT) $(CMD_PYLINT) $(CMD_PYREV) $(CMD_PYTEST): $(DIR_VENV)
$(CMD_PIP) install -r "requirements-dev.txt"
requirements-mysql: $(DIR_VENV)
$(CMD_PIP) install -r "requirements-mysql.txt"
$(DIR_DNDMOD):
$(CMD_NPM) --prefix $(DIR_DTHEME) install
###
# service
define PYLINT_MESSAGE_TEMPLATE
{C} {path}:{line}:{column} - {msg}
βͺ {category} {module}.{obj} ({symbol} {msg_id})
endef
export PYLINT_MESSAGE_TEMPLATE
define _lint
$(CMD_PYLINT) \
--disable "C0111" \
--disable "R0801" \
--msg-template="$$PYLINT_MESSAGE_TEMPLATE" \
--output-format="colorized" \
$(1)
endef
.PHONY: lint lintt
lint: $(CMD_PYLINT)
$(call _lint,"$(DIR_SHORTER)")
lintt: $(CMD_PYLINT)
$(call _lint,"$(DIR_TESTS)")
define _reverse
$(CMD_PYREV) \
--all-ancestors \
--filter-mode="ALL" \
--module-names="yes" \
--output png \
--project="$(1)$(2)" \
$(1)
endef
.PHONY: plot plott
plot: $(CMD_PYREV)
$(call _reverse,$(DIR_SHORTER))
plott: $(CMD_PYREV)
$(call _reverse,$(DIR_TESTS),_$(DIR_SHORTER))
define _sort
$(CMD_ISORT) \
--combine-star \
--ensure-newline-before-comments \
--force-grid-wrap 0 \
--force-sort-within-sections \
--line-width="79" \
--multi-line "VERTICAL_HANGING_INDENT" \
--py "$(subst .,,$(VER_PY))" \
--trailing-comma \
--use-parentheses \
$(1)
endef
.PHONY: sort sortt
sort: $(CMD_ISORT)
$(call _sort,"$(DIR_SHORTER)")
sortt: $(CMD_ISORT)
$(call _sort,"$(DIR_TESTS)")
define _black
$(CMD_BLACK) \
--line-length=79 \
$(1)
endef
.PHONY: black
black: $(CMD_BLACK)
$(call _black,$(DIR_SHORTER))
.PHONY: blackt
blackt: $(CMD_BLACK)
$(call _black,$(DIR_TESTS))
define _test
$(CMD_PYTEST) -vv -rw $(1) --durations=10 "$(DIR_TESTS)"
endef
define _tcov
$(call _test,$(1) --cov="$(DIR_SHORTER)" --cov="$(DIR_TESTS)")
endef
.PHONY: test tcov tcovh
test: $(CMD_PYTEST)
$(call _test,)
tcov: $(CMD_PYTEST)
$(call _tcov,)
tcovh: $(CMD_PYTEST)
$(call _tcov,--cov-report="html:htmlcov")
tcovh-open: tcovh
$(CMD_PY) -m webbrowser -t "htmlcov/index.html"
###
# cleanup
define _gitclean
$(CMD_GIT) clean \
-e "*.py" \
-e "*.sqlite" \
-e ".env" \
-e "secret.key" \
-e "$(DIR_THEMES)/*_dev" \
-e "$(DIR_VENV)/" \
$(1)
endef
.PHONY: clean cleanup
clean:
$(call _gitclean,-ndx)
cleanup:
$(call _gitclean,-fdx)
###
# flask
define _flask
FLASK_DEBUG="$(DEBUG)" \
FLASK_ENV="$(ENVIRON)" \
FLASK_APP="$(FLASK)" \
LOG_LVL="debug" \
$(CMD_FLASK) $(1)
endef
.PHONY: shell run
run: $(CMD_FLASK) $(TGT_BULMA)
$(call _flask,run --host "$(_HOST)" --port "$(_PORT)")
shell: $(CMD_FLASK)
$(call _flask,shell)
###
# assets
$(TGT_BULMA): $(DIR_DNDMOD)
$(CMD_NPM) --prefix $(DIR_DTHEME) run build
.PHONY: assets
assets: $(TGT_BULMA)
###
# continuous integration
.PHONY: travis
travis: tcov