This repository was archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
243 lines (204 loc) · 6.66 KB
/
Makefile
File metadata and controls
243 lines (204 loc) · 6.66 KB
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
234
235
236
237
238
239
240
241
242
243
.PHONY: clean data lint requirements
#################################################################################
# GLOBALS #
#################################################################################
SHELL:=/bin/bash
CONDA=conda
PYTHON := $(shell command -v python3 2> /dev/null)
ifndef PYTHON
$(error Python3 is not available on your system, please install python3.6)
endif
NPM := $(shell command -v npm 2> /dev/null)
ifndef NPM
$(error npm is not available on your system, please install npm)
endif
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROFILE = default
PROJECT_NAME = zippy
TOPIC=
DATA_DIR="data"
MODELS_DIR="output/models"
FILENAME=
TEST_ARGS=--reruns 3
TEST_ON_DOVECOT=
COVERAGE?=
COV_ARGS?=
ifeq ($(COVERAGE), true)
COV_ARGS+=--cov=./
endif
COLOR=\x1b[36m
NO_COLOR=\x1b[m
#################################################################################
# COMMANDS #
#################################################################################
.PHONY: data
## Data related operations
data:
@echo -e "${COLOR}make data:push FILENAME=<DATA_FILENAME>${NO_COLOR}\tTo push specific dataset to Azure."
@echo -e "${COLOR}make data:pull FILENAME=<DATA_FILENAME>${NO_COLOR}\tTo pull specific dataset from Azure."
@echo -e "${COLOR}make <DATA_FILENAME>${NO_COLOR}\t\t\tTo build dataset locally."
@echo -e "\nFollowing files are available:"
@echo -e "$$(egrep '^(data/.+)\:' ${MAKEFILE_LIST} | sed -e 's/:.*\s*/:/' -e 's/^\(.\+\):\(.*\)/\t\${COLOR}\1\${NO_COLOR}\2/')"
.PHONY: data\:push
data\:push:
ifndef FILENAME
$(info Missing FILENAME argument)
$(error Usage: "make data:push FILENAME=path/to/the/file")
else
$(PYTHON) scripts/utils.py push $(FILENAME)
endif
.PHONY: data\:pull
data\:pull:
ifndef FILENAME
$(info Missing FILENAME argument)
$(error Usage: "make data:pull FILENAME=path/to/the/file")
else
$(PYTHON) scripts/utils.py pull $(FILENAME)
endif
# Data pipelines
data/raw/emails.csv:
kaggle datasets download -d wcukierski/enron-email-dataset --path $(shell dirname $@) --unzip
.PHONY: models
## Models related operations
models:
@echo -e "${COLOR}make models:push FILENAME=<MODEL_FILENAME>${NO_COLOR}\tTo push specific model to Azure."
@echo -e "${COLOR}make models:pull FILENAME=<MODEL_FILENAME>${NO_COLOR}\tTo pull specific model from Azure."
@echo -e "${COLOR}make <MODEL_FILENAME>${NO_COLOR}\t\t\tTo train model locally."
@echo -e "\nFollowing files are available:"
@echo -e "$$(egrep '^(output/models/.+)\:' ${MAKEFILE_LIST} | sed -e 's/:.*\s*/:/' -e 's/^\(.\+\):\(.*\)/\t\\x1b[36m\1\\x1b[m\2/')"
.PHONY: models\:push
models\:push:
ifndef FILENAME
$(info Missing FILENAME argument)
$(error Usage: "make models:push FILENAME=path/to/the/file")
else
$(PYTHON) scripts/utils.py push $(FILENAME)
endif
.PHONY: models\:pull
models\:pull:
ifndef FILENAME
$(info Missing FILENAME argument)
$(error Usage: "make models:pull FILENAME=path/to/the/file")
else
$(PYTHON) scripts/utils.py pull $(FILENAME)
endif
# model pipelines
#################################################################################
.PHONY: clean
## Delete all compiled Python files
clean:
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
.PHONY: lint
## Lint using flake8
lint:
@echo -e "Use ${COLOR}make lint:fix${NO_COLOR} to fix linter issues. \n"
$(PYTHON) -m isort -c --diff
$(PYTHON) -m black . --check --diff
$(PYTHON) -m pylint zippy/pipeline zippy/server zippy/utils zippy/client tests scripts
$(PYTHON) -m flake8
$(PYTHON) -m pydocstyle zippy/pipeline zippy/server zippy/utils zippy/client tests scripts
.PHONY: lint\:fix
lint\:fix:
$(PYTHON) -m isort -y
$(PYTHON) -m black .
.PHONY: notebook
## Create notebook
notebook:
ifndef TOPIC
$(info Missing TOPIC argument)
$(error Usage: "make notebook TOPIC=<topic>")
else
$(PYTHON) scripts/utils.py create_nb $(TOPIC)
endif
.PHONY: run
## Run jupyter notebook
run:
$(PYTHON) -m jupyter lab
.PHONY: log-server
## Run logger
log-server:
$(PYTHON) scripts/json_server.py
.PHONY: docs
## Make docs
docs:
# Sphinx searches in _static dir for static files
# Create one if it doesnot exist.
mkdir -p docs/_static
cd docs && make html SPHINXOPTS=-W
.PHONY: test
## Run tests
test:
$(PYTHON) -m pytest $(COV_ARGS) $(TEST_ARGS)
.PHONY: type-check
## Run mypy for typecheck
type-check:
$(PYTHON) -m mypy zippy/**/*.py tests/*py scripts/*py
.PHONY: package
## Make zippy available as a package
package:
$(PYTHON) -m pip install -e . --no-use-pep517
#################################################################################
# PROJECT RULES #
#################################################################################
#################################################################################
# Self Documenting Commands #
#################################################################################
.DEFAULT_GOAL := help
# Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
# sed script explained:
# /^##/:
# * save line in hold space
# * purge line
# * Loop:
# * append newline + line to hold space
# * go to next line
# * if line starts with doc comment, strip comment character off and loop
# * remove target prerequisites
# * append hold space (+ newline) to line
# * replace newline plus comments by `---`
# * print line
# Separate expressions are necessary because labels cannot be delimited by
# semicolon; see <http://stackoverflow.com/a/11799865/1968>
.PHONY: help
## Show this help message
help:
@echo -e "Usage:\n\tmake <target>\n"
@echo "$$(tput bold)Available targets:$$(tput sgr0)"
@echo
@sed -n -e "/^## / { \
h; \
s/.*//; \
:doc" \
-e "H; \
n; \
s/^## //; \
t doc" \
-e "s/:.*//; \
G; \
s/\\n## /---/; \
s/\\n/ /g; \
p; \
}" ${MAKEFILE_LIST} \
| LC_ALL='C' sort --ignore-case \
| awk -F '---' \
-v ncol=$$(tput cols) \
-v indent=19 \
-v col_on="$$(tput setaf 6)" \
-v col_off="$$(tput sgr0)" \
'{ \
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
n = split($$2, words, " "); \
line_length = ncol - indent; \
for (i = 1; i <= n; i++) { \
line_length -= length(words[i]) + 1; \
if (line_length <= 0) { \
line_length = ncol - indent - length(words[i]) - 1; \
printf "\n%*s ", -indent, " "; \
} \
printf "%s ", words[i]; \
} \
printf "\n"; \
}' \
| more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')
@echo -e $$(echo "version commit@" && git rev-parse --short HEAD)