-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
257 lines (206 loc) · 5.57 KB
/
Makefile
File metadata and controls
257 lines (206 loc) · 5.57 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
GITDIR := $(shell git rev-parse --show-toplevel)
FIND_GITIGNORE_FILTER = 'for path; do git check-ignore -q "$$path" || echo "$$path" ;done'
PY_SOURCE_GLOB = $(shell find * -not -path '*/\.*' -name "*.py" -exec sh -c \
$(FIND_GITIGNORE_FILTER) \
find-sh {} +)
SH_SOURCE_GLOB = $(shell find * -not -path '*/\.*' -type f -name "*.sh" -exec sh -c \
$(FIND_GITIGNORE_FILTER) \
find-sh {} +)
IGNORE_PEP = E203,E221,E241,E272,E501,F811,W503
MAX_LINE_LENGTH = 100
BLACK_ARGS =
ifneq ($(wildcard setup.py),)
PACKAGE_NAME=$(shell sed -n "s/PACKAGE_NAME[ ]*=[ ]*[\",\']\(.*\)[\",\'].*/\1/p" setup.py)
endif
.PHONY: all
all : clean lint
.PHONY: test
test: shelltest pytest
.PHONY: lint
lint: check-black pylint pycodestyle flake8 mypy shellcheck
.PHONY: format
format: black
.PHONY: print_target
print_target:
@echo "----------------------------------------------------------------------"
@echo ":: $(target)"
@echo "----------------------------------------------------------------------"
.PHONY: clean
clean:
@$(MAKE) target=$@ print_target
rm -rf dist/* .pytype .mypy_cache
.PHONY: dist
dist:
@$(MAKE) target=$@ print_target
@if [ -f "setup.py" ]; then \
python3 setup.py sdist bdist_wheel; \
else \
echo "'setup.py' not found. Please ensure this folder is a package"; \
fi
.PHONY: pytest
pytest:
@$(MAKE) target=$@ print_target
@if [ -d "tests" ]; then \
pytest --cov=$(PACKAGE_NAME) --cov-report term-missing tests/; \
else \
echo "'tests' directory does not exist. Please ensure you have unit test in this package"; \
fi
.PHONY: shelltest
shelltest:
@$(MAKE) target=$@ print_target
ifeq ($(SH_SOURCE_GLOB),)
@echo "No shell file found"
else
# bash '-n': check the syntax of a script without having to execute it
@for sh_file in $(SH_SOURCE_GLOB); do \
bash -n "$${sh_file}" || exit 1 ; \
done
endif
.PHONY: pylint
# E0202: https://www.technovelty.org/python/pylint-and-hiding-of-attributes.html
# W0511: (warning notes in code comments; message varies)
# R0801: Similar lines in %s files
pylint:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
pylint \
--rcfile="$(GITDIR)/.pylintrc" \
--disable=C0330,E0202,W0511,R0801,cyclic-import \
$(PY_SOURCE_GLOB)
endif
.PHONY: pycodestyle
pycodestyle:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
pycodestyle \
--statistics \
--max-line-length $(MAX_LINE_LENGTH) \
--count \
--ignore="$(IGNORE_PEP)" \
$(PY_SOURCE_GLOB)
endif
.PHONY: flake8
flake8:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
flake8 \
--max-line-length $(MAX_LINE_LENGTH) \
--ignore="$(IGNORE_PEP)" \
$(PY_SOURCE_GLOB)
endif
.PHONY: mypy
mypy:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
MYPYPATH="stubs/" mypy \
$(PY_SOURCE_GLOB)
endif
.PHONY: pytype
pytype:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
rm -rf .pytype
pytype \
--config=$(GITDIR)/setup.cfg \
--disable=import-error,pyi-error \
$(PY_SOURCE_GLOB)
endif
.PHONY: shellcheck
shellcheck:
@$(MAKE) target=$@ print_target
ifeq ($(SH_SOURCE_GLOB),)
@echo "No shell file found"
else
shellcheck \
$(SH_SOURCE_GLOB)
endif
.PHONY: check-black
# Run the black tool in check mode only (won't modify files)
check-black:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
@echo "Checking black with code format"
black \
--check \
--line-length $(MAX_LINE_LENGTH) \
$(BLACK_ARGS) \
$(PY_SOURCE_GLOB)
endif
.PHONY: black
black:
@$(MAKE) target=$@ print_target
ifeq ($(PY_SOURCE_GLOB),)
@echo "No Python file found"
else
black \
--line-length $(MAX_LINE_LENGTH) \
$(BLACK_ARGS) \
$(PY_SOURCE_GLOB)
endif
.PHONY: install-githook
install-githook:
@$(MAKE) target=$@ print_target
# cleanup existing pre-commit configuration (if any)
pre-commit clean
pre-commit gc
# setup pre-commit
# Ensures pre-commit hooks point to latest versions
pre-commit autoupdate
pre-commit install
pre-commit install --hook-type pre-push
pre-commit install --hook-type commit-msg
.PHONY: uninstall-githook
uninstall-githook:
@$(MAKE) target=$@ print_target
pre-commit clean
pre-commit gc
pre-commit uninstall
pre-commit uninstall --hook-type pre-push
pre-commit uninstall --hook-type commit-msg
.PHONY: develop
develop:
@$(MAKE) target=$@ print_target
pip3 install -r $(GITDIR)/requirements.txt
pip3 install -r $(GITDIR)/requirements-dev.txt
$(MAKE) install-githook
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
python3 setup.py --verbose develop
.PHONY: undevelop
undevelop:
@$(MAKE) target=$@ print_target
python3 setup.py --verbose develop --uninstall
.PHONY: deploy-version
deploy-version:
@if [ ! -f "setup.py" ]; then \
echo "'setup.py' not found. Please ensure this folder is a package"; \
exit 1; \
fi; \
if [ ! -f "VERSION" ]; then \
echo "'VERSION' file doesn't exist. Please ensure have VERSION file in this package"; \
exit 1; \
fi; \
sed -i "s/VERSION = .*/VERSION = \"$$(cat VERSION)\"/" $(PACKAGE_NAME)/version.py
.PHONY: bump-version
bump-version:
@newVersion=$$(awk -F. '{print $$1"."$$2"."$$3+1}' < VERSION) \
&& echo $${newVersion} > VERSION \
&& git add VERSION \
&& git commit -m "$${newVersion}" > /dev/null \
&& echo "Bumped version to $${newVersion}"
.PHONY: update-requirements
update-requirements:
pip-compile -q -o requirements.txt requirements.in
pip-compile -q -o requirements-dev.txt requirements-dev.in