-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
480 lines (378 loc) · 11.5 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
SHELL:=/bin/bash
PROJECT:=iceworm
PYTHON_VERSION:=3.7.12
PYTHON_38_VERSION:=3.8.12
PYENV_ROOT:=$(shell if [ -z "$${PYENV_ROOT}" ]; then echo "$${HOME}/.pyenv" ; else echo "$${PYENV_ROOT%/}" ; fi)
PYENV_BIN:=$(shell if [ -f "$${HOME}/.pyenv/bin/pyenv" ] ; then echo "$${HOME}/.pyenv/bin/pyenv" ; else echo pyenv ; fi)
PIP_ARGS:=
PYENV_BREW_DEPS:= \
openssl \
readline \
sqlite3 \
zlib \
BREW_DEPS:= \
$(PYENV_BREW_DEPS) \
graphviz \
libyaml \
node \
pipx \
protobuf \
ANTLR_VERSION=4.8
### Toplevel
all: venv gen build flake test
### Clean
.PHONY: clean
clean:
-rm -rf $(PROJECT).egg-info
-rm -rf .benchmarks
-rm -rf .cache
-rm -rf .mypy_cache
-rm -rf .pytest_cache
-rm -rf .venv*
-rm -rf build
-rm -rf dist
find $(PROJECT) \
\
-name '*.dylib' -delete -or \
-name '*.exe' -delete -or \
-name '*.pyc' -delete -or \
-name '*.pyo' -delete -or \
-name '*.so' -delete -or \
-name '.revision' -delete -or \
-name '__pycache__' -delete -or \
\
-name NeVeRmAtCh
(cd $(PROJECT)-js && make clean)
(cd $(PROJECT)-jvm && make clean)
(cd $(PROJECT)-rs && make clean)
### Env
.PHONY: brew-install
brew-install:
brew install $(BREW_DEPS)
.PHONY: brew-upgrade
brew-upgrade:
brew upgrade $(BREW_DEPS)
define do-venv
set -e ; \
\
if [ -z "$$DEBUG" ] && [ "$$(python --version)" = "Python $(2)" ] ; then \
virtualenv $(1) ; \
\
else \
PYENV_INSTALL_DIR="$(2)" ; \
PYENV_INSTALL_FLAGS="-s -v"; \
if [ ! -z "$$DEBUG" ] ; then \
PYENV_INSTALL_DIR="$$PYENV_INSTALL_DIR"-debug ; \
PYENV_INSTALL_FLAGS="$$PYENV_INSTALL_FLAGS -g" ; \
fi ; \
\
if [ "$$(uname)" = "Darwin" ] && command -v brew ; then \
PYENV_CFLAGS="" ; \
PYENV_LDFLAGS="" ; \
for DEP in $(PYENV_BREW_DEPS); do \
DEP_PREFIX="$$(brew --prefix "$$DEP")" ; \
PYENV_CFLAGS="-I$$DEP_PREFIX/include $$PYENV_CFLAGS" ; \
PYENV_LDFLAGS="-L$$DEP_PREFIX/lib $$PYENV_LDFLAGS" ; \
done ; \
\
PYTHON_CONFIGURE_OPTS="--enable-framework" ; \
if brew --prefix tcl-tk ; then \
TCL_TK_PREFIX="$$(brew --prefix tcl-tk)" ; \
TCL_TK_VER="$$(brew ls --versions tcl-tk | head -n1 | egrep -o '[0-9]+\.[0-9]+')" ; \
PYTHON_CONFIGURE_OPTS="$$PYTHON_CONFIGURE_OPTS --with-tcltk-includes='-I$$TCL_TK_PREFIX/include'" ; \
PYTHON_CONFIGURE_OPTS="$$PYTHON_CONFIGURE_OPTS --with-tcltk-libs='-L$$TCL_TK_PREFIX/lib -ltcl$$TCL_TK_VER -ltk$$TCL_TK_VER'" ; \
fi ; \
\
CFLAGS="$$PYENV_CFLAGS $$CFLAGS" \
LDFLAGS="$$PYENV_LDFLAGS $$LDFLAGS" \
PKG_CONFIG_PATH="$$(brew --prefix openssl)/lib/pkgconfig:$$PKG_CONFIG_PATH" \
PYTHON_CONFIGURE_OPTS="$$PYTHON_CONFIGURE_OPTS" \
"$(PYENV_BIN)" install $$PYENV_INSTALL_FLAGS $(2) ; \
\
else \
"$(PYENV_BIN)" install $$PYENV_INSTALL_FLAGS $(2) ; \
\
fi ; \
\
"$(PYENV_ROOT)/versions/$$PYENV_INSTALL_DIR/bin/python" -m venv $(1) ; \
fi ; \
\
$(1)/bin/pip install --upgrade pip setuptools wheel
endef
define do-deps
(cat requirements.txt ; (if [ $(2) == "1" ] ; then cat requirements-dev.txt ; fi) ; echo) | \
egrep -o '^[^#]+' | \
egrep -v '[ ]*-r' | \
egrep -v omnibus | \
xargs $(1)/bin/pip $(PIP_ARGS) install ; \
\
OMNIBUS_LOCAL=$$($(1)/bin/pip freeze | egrep '^omnibus ' | cut -d@ -f3) ; \
OMNIBUS_REMOTE=$$(git ls-remote https://github.com/wrmsr/omnibus wrmsr_working | awk '{print $$1}') ; \
echo "omnibus local:$$OMNIBUS_LOCAL remote:$$OMNIBUS_REMOTE" ; \
if [ "$$OMNIBUS_LOCAL" != "$$OMNIBUS_REMOTE" ] ; then \
A="" ; \
$(1)/bin/pip freeze | grep omnibus | egrep -o '^[^ ]+' | xargs -n1 .venv/bin/pip uninstall -y ; \
if [ $(2) == "1" ] ; then \
export __OMNIBUS_DIST=all ; \
A="$$A --no-build-isolation" ; \
fi ; \
$(1)/bin/pip install $$A $(PIP_ARGS) git+https://github.com/wrmsr/omnibus@wrmsr_working ; \
fi ; \
\
if [ -d "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/" ] ; then \
if $(1)/bin/python -c 'import sys; exit(0 if sys.version_info < (3, 7) else 1)' ; then \
$(1)/bin/python "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/setup_cython.py" build_ext --inplace ; \
fi ; \
fi
endef
.PHONY: venv
venv:
if [ ! -d .venv ] ; then \
$(call do-venv,.venv,$(PYTHON_VERSION)) ; \
$(call do-deps,.venv,1) ; \
fi
.PHONY: venv-38
venv-38:
if [ ! -d .venv-38 ] ; then \
$(call do-venv,.venv-38,$(PYTHON_38_VERSION)) ; \
$(call do-deps,.venv-38,1) ; \
fi
.PHONY: venv-inst
venv-inst:
if [ ! -d .venv-inst ] ; then \
$(call do-venv,.venv-inst,$(PYTHON_VERSION)) ; \
$(call do-deps,.venv-inst,0) ; \
fi
### Gen
.PHONY: gen
gen: antlr proto
true
.PHONY: antlr
antlr: venv
.venv/bin/python -m omnibus.dev.projects.antlr gen $(PROJECT)
.PHONY: proto
proto: venv
.venv/bin/python -m $(PROJECT).protos.gen gen
.PHONY: vers
vers: venv
VER=$$(.venv/bin/python -c 'from $(PROJECT) import __about__; print(__about__.__version__)') ; \
echo "$$VER" ; \
\
T=$$(mktemp) && cat $(PROJECT)-jvm/pom.xml >$$T && \
sed "1,/^ <version>.*/s/^ <version>.*/ <version>$$VER<\\/version>/" <$$T >$(PROJECT)-jvm/pom.xml ; \
\
for D in $$(cd $(PROJECT)-jvm && find . -name '$(PROJECT)-*' -maxdepth 1 -type d) ; do \
F="$(PROJECT)-jvm/$$D/pom.xml" ; \
if [ -f "$$F" ] ; then \
T=$$(mktemp) && cat "$$F" >$$T && \
sed "1,/^ <version>.*/s/^ <version>.*/ <version>$$VER<\\/version>/" <$$T >"$$F" ; \
T=$$(mktemp) && cat "$$F" >$$T && \
sed "1,/^ <version>.*/s/^ <version>.*/ <version>$$VER<\\/version>/" <$$T >"$$F" ; \
fi ; \
done ; \
\
T=$$(mktemp) && cat $(PROJECT)-js/ui/package.json >$$T && \
sed "1,/^ \"version\": .*/s/^ \"version\": .*/ \"version\": \"$$VER\",/" <$$T >$(PROJECT)-js/ui/package.json ; \
\
T=$$(mktemp) && cat $(PROJECT)-rs/Cargo.toml >$$T && \
sed "1,/^version = .*/s/^version = .*/version = \"$$VER\"/" <$$T >$(PROJECT)-rs/Cargo.toml ; \
### Build
define do-build
$(1)/bin/python setup.py build_ext --inplace
endef
.PHONY: build
build: venv
$(call do-build,.venv)
.PHONY: build-38
build-38: venv-38 gen
$(call do-build,.venv-38)
.PHONY: build-all
build-all: build
(cd $(PROJECT)-js && make build) && \
(cd $(PROJECT)-jvm && make build) && \
(cd $(PROJECT)-rs && make build) && \
\
true
### Check
.PHONY: flake
flake: venv
.venv/bin/flake8 $(PROJECT)
.PHONY: typecheck
typecheck: venv
.venv/bin/mypy $(PROJECT)
### Test
.PHONY: test
test: build
.venv/bin/pytest -v $(PROJECT)
.PHONY: test-offline
test-offline: build
.venv/bin/pytest -v --no-online $(PROJECT)
.PHONY: test-38
test-38: build-38
.venv-38/bin/pytest -v -n auto $(PROJECT)
.PHONY: test-parallel
test-parallel: build
.venv/bin/pytest -v -n auto $(PROJECT)
.PHONY: test-verbose
test-verbose: build
.venv/bin/pytest -svvv $(PROJECT)
### Deps
.PHONY: deps
deps: venv dep-unfreeze
$(call do-deps,.venv,1)
$(MAKE) dep-freeze dep-setup
.PHONY: deps-38
deps-38: venv-38
$(call do-deps,.venv-38,$(REQUIREMENTS_TXT))
.PHONY: dep-freze
dep-freeze: venv
.venv/bin/pip freeze > requirements-frz.txt
.PHONY: dep-unfreeze
dep-unfreeze: venv
.venv/bin/pip install -r requirements-frz.txt
.PHONY: dep-tree
dep-tree: venv
.venv/bin/pipdeptree
.PHONY: dep-updates
dep-updates: venv
.venv/bin/pip list -o --format=columns
.PHONY: dep-cyaml
dep-cyaml: venv
.venv/bin/python setup.py cyaml
.PHONY: dep-setup
dep-setup: venv
echo -e "\n\
with open('setup.py', 'r') as f: \n\
lines = [l.rstrip() for l in f.readlines()] \n\
[pos] = [i for i, l in enumerate(lines) if l.strip() == '# @omnibus-dep@'] \n\
import subprocess \n\
[dep] = [l for l in subprocess.check_output(['.venv/bin/pip', 'freeze']).decode('utf-8').splitlines() for l in [l.strip()] if l.startswith('omnibus')] \n\
print(dep) \n\
lines[pos+1] = ' ' + chr(39) + dep + chr(39) + ',' \n\
with open('setup.py', 'w') as f: \n\
f.write('\\\\n'.join(lines + [''])) \n\
" | .venv/bin/python -
### Dist
define do-dist
rm -rf build
mkdir build
$(eval DIST_BUILD_PYTHON:=$(shell echo "$(shell pwd)/$(1)/bin/python"))
cp -rv \
LICENSE \
$(PROJECT) \
README.md \
\
build/
cp -rv \
LICENSE-* \
\
build/ || :
rm build/$(PROJECT)/conftest.py
cp setup.py build/setup.py
cp MANIFEST.in build/MANIFEST.in
cd build && "$(DIST_BUILD_PYTHON)" setup.py clean
git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty > "build/$(PROJECT)/.revision"
if [ "$(1)" = ".venv" ] ; then \
cd build && "$(DIST_BUILD_PYTHON)" setup.py sdist --formats=zip ; \
fi
cd build && "$(DIST_BUILD_PYTHON)" setup.py bdist_wheel
if [ ! -d ./dist ] ; then \
mkdir dist ; \
fi
cp build/dist/* ./dist/
endef
.PHONY: dist
dist: venv
$(call do-dist,.venv,0)
.PHONY: dist-38
dist-38: venv-38
$(call do-dist,.venv-38,0)
### Docker
## Proxies
.PHONY: docker-clean-venv
docker-clean-venv:
rm -rf .venv-docker
.PHONY: docker-venv
docker-venv:
./docker-dev make _docker-venv
.PHONY: _docker-venv
_docker-venv:
if [ ! -d .venv-docker ] ; then \
$(call do-venv,.venv-docker,$(PYTHON_VERSION)) ; \
$(call do-deps,.venv-docker,1) ; \
fi
.PHONY: docker-venv-38
docker-venv-38:
./docker-dev make _docker-venv-38
.PHONY: _docker-venv-38
_docker-venv-38:
if [ ! -d .venv-docker-38 ] ; then \
$(call do-venv,.venv-docker-38,$(PYTHON_38_VERSION)) ; \
$(call do-deps,.venv-docker-38,1) ; \
fi
.PHONY: docker-venv-inst
docker-venv-inst:
./docker-dev make _docker-venv-inst
.PHONY: _docker-venv-inst
_docker-venv-inst:
if [ ! -d .venv-docker-inst ] ; then \
$(call do-venv,.venv-docker-inst,$(PYTHON_VERSION)) ; \
$(call do-deps,.venv-docker-inst,0) ; \
fi
.PHONY: docker-deps
docker-deps:
./docker-dev make _docker-deps
.PHONY: _docker-deps
_docker-deps: _docker-venv
$(call do-deps,.venv-docker,1)
.PHONY: docker-build
docker-build: docker-venv
./docker-dev make _docker-build
.PHONY: _docker-build
_docker-build: _docker-venv
$(call do-build,.venv-docker)
.PHONY: docker-build-38
docker-build-38: docker-venv-38
./docker-dev make _docker-build-38
.PHONY: _docker-build-38
_docker-build-38: _docker-venv-38
$(call do-build,.venv-docker-38)
.PHONY: docker-test
docker-test: docker-build
./docker-dev .venv-docker/bin/pytest -v $(PROJECT)
.PHONY: docker-test-38
docker-test-38: docker-build-38
./docker-dev .venv-docker-38/bin/pytest -v $(PROJECT)
.PHONY: docker-dist
docker-dist: docker-venv
./docker-dev make _docker-dist
.PHONY: _docker-dist
_docker-dist: _docker-venv
$(call do-dist,.venv-docker,0,1)
## Compose
.PHONY: docker-clean
docker-clean:
(cd docker && $(MAKE) clean)
.PHONY: docker-stop
docker-stop:
(cd docker && $(MAKE) stop)
.PHONY: docker-rmdev
docker-rmdev:
(cd docker && $(MAKE) rmdev)
.PHONY: docker-reup
docker-reup:
(cd docker && $(MAKE) reup)
## Images
.PHONY: docker-invalidate
docker-invalidate:
date +%s > .dockertimestamp
### Utils
.PHONY: pg-repl
pg-repl: venv
export $$(.venv/bin/python -c "import yaml; dct = yaml.safe_load(open('docker/docker-compose.yml', 'r').read()); cfg = dct['services']['iceworm-postgres']; print('PG_USER=' + cfg['environment']['POSTGRES_USER']); print('PG_PASSWORD=' + cfg['environment']['POSTGRES_PASSWORD']); print('PG_PORT=' + cfg['ports'][0].split(':')[0])" | xargs) && \
PGPASSWORD="$$PG_PASSWORD" .venv/bin/pgcli --user "$$PG_USER" --host localhost --port "$$PG_PORT"
.PHONY: sf-repl
sf-repl:
export $$(cat .env | sed 's/#.*//g' | xargs) && \
export $$(.venv/bin/python -c "import os, configparser; parser = configparser.ConfigParser(); parser.read_file(open(os.environ['ICEWORM_SNOWFLAKE_CONFIG_PATH'], 'r')); print(' '.join(f'SF_{k.upper()}={v}' for k, v in parser.items('snowflake')))" | xargs) && \
snowsql --username "$$SF_USER" --host "$$SF_HOST" --accountname "$$SF_ACCOUNT" --authenticator "$$SF_AUTHENTICATOR" --schemaname "$$SF_SCHEMA"