-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
520 lines (387 loc) · 9.92 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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# TODO:
# - build-deps:
# - --force-reinstall --ignore-installed ?
# - PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig" ./python -muv pip install mysqlclient
# - BERKELEYDB_DIR=$(brew --prefix "berkeley-db@4") ./python -muv pip install bsddb
SHELL:=/bin/bash
### Clean
.PHONY: clean-venv
clean-venv:
-rm -rf \
.venv*
.PHONY: clean-package
clean-package:
-rm -rf \
*.egg-info \
build \
dist \
.PHONY: _clean
_clean: clean-venv clean-package
-rm -rf \
*.sock \
.benchmarks \
.mypy_cache \
.pytest_cache \
### Venv
PYPROJECT_SRC=omdev/scripts/pyproject.py
PYPROJECT_PYTHON=python3
PYPROJECT=${PYPROJECT_PYTHON} ${PYPROJECT_SRC}
VENV?=default
PYPROJECT_VENV=${PYPROJECT} venv ${VENV}
PYTHON:=$$(${PYPROJECT_VENV} exe)
SRCS:=$$(${PYPROJECT_VENV} srcs)
.PHONY: python
python:
@echo "${PYTHON}"
.PHONY: srcs
srcs:
@echo ${SRCS}
#
.PHONY: venv
venv:
@${PYTHON} --version
@if [ "${VENV}" == "default" ] ; then \
${MAKE} _default_venv ; \
fi
.PHONY: _default_venv
_default_venv:
@if [ ! -d .venv ] ; then \
ln -s .venvs/default .venv ; \
fi
@.venv/bin/python3 -m omlish.diag._pycharm.runhack install -e || true
@if ! ${PYTHON} -c 'import importlib.util; exit(importlib.util.find_spec("llama_cpp") is None)' ; then \
if [ $$(uname) == "Linux" ] && [ $$(uname -m) == "x86_64" ] ; then \
LCW=$$(ls -1 ../llama_cpp_python-*-linux_x86_64.whl 2>/dev/null | tail -n1) && \
if [ ! -z "$$LCW" ] ; then \
${PYTHON} -m pip install "$$LCW" ; \
fi ; \
fi ; \
fi
@if ! ${PYTHON} -c 'import importlib.util; exit(importlib.util.find_spec("tinygrad.tensor") is None)' ; then \
${MAKE} tg ; \
fi
.PHONY: fresh-venv
fresh-venv:
rm -rf .venvs/default
${MAKE} venv
.PHONY: tg
tg:
git submodule update --init tinygrad
# FIXME: ${PYTHON} -m pip install -e tinygrad --use-pep517
ABS_PYTHON=$$(${PYTHON} -c 'import sys; print(sys.executable)') && \
(cd tinygrad && "$$ABS_PYTHON" -m pip install -e .)
.PHONY: tg-update
tg-update:
(cd tinygrad && git pull origin master)
### Deps
.PHONY: dep-list
dep-list:
@${PYTHON} -m pip freeze
.PHONY: dep-freeze
dep-freeze: venv
${PYTHON} -m pip freeze > requirements-frz.txt
${PYTHON} -m omdev.tools.pip filter-dev-deps -wq requirements-frz.txt
.PHONY: dep-unfreeze
dep-unfreeze: venv
${PYTHON} -m pip install -r requirements-frz.txt
.PHONY: dep-tree
dep-tree:
@${PYTHON} -m pipdeptree
.PHONY: dep-updates
dep-updates: venv
${PYTHON} -m pip list -o --format=columns
.PHONY: dep-refresh
dep-refresh: venv
${PYTHON} -m pip install --upgrade pip setuptools wheel
${PYTHON} -m pip install -r requirements-ext.txt
### Gen
.PHONY: gen
gen: gen-amalg gen-cmake gen-aws gen-manifest gen-pkg
.PHONY: gen-amalg
gen-amalg: venv
${PYTHON} -m omdev.amalg gen \
-m omdev \
-m ominfra \
-m omlish \
-m omserv \
${SRCS}
.PHONY: gen-cmake
gen-cmake:
${PYTHON} -m omdev.cexts.cmake gen ${SRCS}
.PHONY: gen-aws
gen-aws:
${PYTHON} -m ominfra.clouds.aws.models.gen gen-services
.PHONY: gen-manifest
gen-manifest:
${PYTHON} -m omdev.manifests gen -wq ${SRCS} x
.PHONY: gen-pkg
gen-pkg:
PYTHONPATH=. ${PYPROJECT} pkg gen
### Check
.PHONY: check
check: flake8 ruff mypy precheck
.PHONY: flake8
flake8: venv
${PYTHON} -m flake8 ${SRCS}
.PHONY: ruff
ruff: venv
${PYTHON} -m ruff check ${SRCS}
.PHONY: ruff-stats
ruff-stats: venv
${PYTHON} -m ruff check --statistics ${SRCS}
.PHONY: ruff-fix
ruff-fix: venv
if ! $$(git diff-files --quiet --ignore-submodules) ; then \
echo 'there are unstaged changes - refusing to run' ; \
exit 1 ; \
fi
${PYTHON} -m ruff check --fix ${SRCS}
.PHONY: fix-imports
fix-imports: venv
${PYTHON} -m ruff check --select I001 --fix ${SRCS}
.PHONY: mypy
mypy: venv
${PYTHON} -m mypy --check-untyped-defs ${SRCS}
.PHONY: precheck
precheck: venv
${PYTHON} -m omdev.precheck check ${SRCS}
## pre-commit
# FIXME: update .git/hooks/pre-commit to use *just* git-ish omdev.precheck's
GIT_BLACKLIST_FILES=\
.env \
secrets.yml \
.PHONY: pre-commit
pre-commit:
for F in ${GIT_BLACKLIST_FILES} ; do \
ST=$$(git status -s "$$F") ; \
if [ ! -z "$$ST" ] ; then \
echo "must not checkin $$F" ; \
exit 1 ; \
fi ; \
done
### Test
PYTEST_OPTS=
.PHONY: test-all
test-all: test test-docker test-13 test-13t test-lite
.PHONY: test
test:
if [ ! -z "${PYTEST_JUNIT_XML_PATH}" ] && [ -f "${PYTEST_JUNIT_XML_PATH}" ] ; then \
rm "${PYTEST_JUNIT_XML_PATH}" ; \
fi
${PYPROJECT_VENV} \
test \
-- \
${PYTEST_OPTS} \
--junitxml="${PYTEST_JUNIT_XML_PATH}" \
--no-slow \
### Alts
# all
.PHONY: venv-all
venv-all: venv venv-13 venv-13t venv-lite
# 13
.PHONY: venv-13
venv-13:
${PYPROJECT} venv 13 exe
.PHONY: test-13
test-13:
${PYPROJECT} venv 13 test -- ${PYTEST_OPTS} --ignore=omlish/sql
# 13t
.PHONY: venv-13t
venv-13t:
${PYPROJECT} venv 13t exe
.PHONY: test-13t
test-13t:
${PYPROJECT} venv 13t test -- ${PYTEST_OPTS} --ignore=omlish/sql
# 14
.PHONY: venv-14
venv-14:
${PYPROJECT} venv 14 exe
.PHONY: test-14
test-14:
${PYPROJECT} venv 14 test -- ${PYTEST_OPTS} --ignore=omlish/sql
# 14t
.PHONY: venv-14t
venv-14t:
${PYPROJECT} venv 14t exe
.PHONY: test-14t
test-14t:
${PYPROJECT} venv 14t test -- ${PYTEST_OPTS} --ignore=omlish/sql
# lite
LITE_VENVS=\
8 \
9 \
10 \
11 \
.PHONY: venv-lite
venv-lite:
for V in ${LITE_VENVS} ; do \
${PYPROJECT} venv $$V exe ; \
done
.PHONY: test-lite
test-lite:
LITE_PATHS=$$(${PYTHON} -m omdev.magic find --modules -k '@omlish-lite' ${SRCS}) ; \
for V in ${LITE_VENVS} ; do \
for T in $$LITE_PATHS ; do \
if [ -d $$(echo "$$T" | tr '.' '/') ] ; then \
$$(${PYPROJECT} venv $$V exe) -m unittest discover -vb $$T ; \
else \
$$(${PYPROJECT} venv $$V exe) -m unittest -vb $$T ; \
fi ; \
done ; \
done
# docker
.PHONY: venv-docker
venv-docker:
# FIXME: do this everywhere, even on darwin:
# BERKELEYDB_DIR=$(brew --prefix 'berkeley-db@4') .venv/bin/pip install bsddb3
if [ $$(arch) == "aarch64" ] || [ $$(arch) == "arm64" ]; then \
export BERKELEYDB_LIBDIR=/usr/lib/aarch64-linux-gnu ; \
export BERKELEYDB_INCDIR=/usr/include ; \
PYPROJECT_DOCKER_ENVS="-e BERKELEYDB_LIBDIR -e BERKELEYDB_INCDIR" ; \
fi ; \
\
${PYPROJECT} venv $$PYPROJECT_DOCKER_ENVS docker
.PHONY: test-docker
test-docker:
VENV=docker ${MAKE} test
# docker-amd64
.PHONY: venv-docker-amd64
venv-docker-amd64:
# VENV=docker-amd64 ${MAKE} venv # FIXME
${PYPROJECT} venv docker-amd64
.PHONY: test-docker-amd64
test-docker-amd64:
VENV=docker-amd64 ${MAKE} test
# deploy
.PHONY: venv-deploy
venv-deploy:
VENV=deploy ${MAKE} venv
# debug
.PHONY: venv-debug
venv-debug:
VENV=debug ${MAKE} venv
.PHONY: test-debug
test-debug:
VENV=debug ${MAKE} test
### Docker
DOCKER_USER=wrmsr
DOCKER_COMPOSE=docker compose -f docker/compose.yml
.PHONY: docker-stop
docker-stop:
${DOCKER_COMPOSE} stop
DOCKER_DEV_CONTAINERS=\
omlish-dev \
# omlish-dev-amd64 \
DOCKER_LITE_CONTAINERS=\
omlish-mysql \
omlish-postgres \
.PHONY: docker-rebuild
docker-rebuild: docker-stop
${DOCKER_COMPOSE} rm -f
${DOCKER_COMPOSE} build ${DOCKER_DEV_CONTAINERS}
.PHONY: docker-reup
docker-reup: docker-rebuild
${DOCKER_COMPOSE} up --attach-dependencies ${DOCKER_DEV_CONTAINERS}
.PHONY: docker-reup-lite
docker-reup-lite: docker-rebuild
${DOCKER_COMPOSE} up --attach-dependencies ${DOCKER_LITE_CONTAINERS}
.PHONY: docker-invalidate
docker-invalidate:
date +%s > docker/.timestamp
DOCKER_BASE_PORT=35220
.PHONY: docker-ports
docker-ports: venv
${PYTHON} -m omdev.tools.docker reset-compose-ports -wq ${DOCKER_BASE_PORT}
.PHONY: docker-updates
docker-updates: venv
${PYTHON} -m omdev.tools.docker compose-image-updates
### CI
CI_BASE_FILES=\
docker \
.PHONY: ci-image
ci-image:
tar ch \
${CI_BASE_FILES} \
| \
docker build \
--platform linux/x86_64 \
--tag "${DOCKER_USER}/omlish-ci-base" \
-f "docker/ci/Dockerfile" \
--target omlish-ci-base \
-
tar ch \
--exclude "__pycache__" \
${CI_BASE_FILES} \
${SRCS} \
.versions \
LICENSE \
Makefile \
pyproject.toml \
requirements-dev.txt \
requirements.txt \
| \
docker build \
--platform linux/x86_64 \
--tag "${DOCKER_USER}/omlish-ci" \
-f "docker/ci/Dockerfile" \
-
.PHONY: ci
ci: ci-image
${DOCKER_COMPOSE} run --quiet-pull --rm $$CI_DOCKER_OPTS -e CI=1 omlish-ci
.PHONY: _ci
_ci:
if [ ! -z "${PYTEST_JUNIT_XML_PATH}" ] && [ -f "${PYTEST_JUNIT_XML_PATH}" ] ; then \
rm "${PYTEST_JUNIT_XML_PATH}" ; \
fi
python \
-m pytest \
${PYTEST_OPTS} \
--junitxml="${PYTEST_JUNIT_XML_PATH}" \
${SRCS}
.PHONY: ci-bash
ci-bash: ci-image
${DOCKER_COMPOSE} run --rm -e CI=1 omlish-ci bash
### Package
.PHONY: package
package: gen check clean-package
PYTHONPATH=. ${PYTHON} ${PYPROJECT_SRC} pkg -b -r gen
.PHONY: test-install
test-install: venv
for EXT in '.tar.gz' '.whl' ; do \
D=$$(mktemp -d) ; \
echo "$$D" ; \
${PYTHON} -m venv "$$D/venv" ; \
find dist -name "*$$EXT" | xargs "$$D/venv/bin/python3" -m pip install --no-cache-dir || exit 1 ; \
rm -rf "$$D" ; \
done
### Publish
LOCAL_VERSION:=$$(${PYTHON} -c 'from omlish import __about__; print(__about__.__version__)')
PYPI_VERSION:=$$(${PYTHON} -m omdev.tools.pip lookup-latest-version omlish)
.PHONY: versions
versions: venv
echo "PyPI version: ${PYPI_VERSION}"
echo "Local version: ${LOCAL_VERSION}"
.PHONY: publish
publish: package test-install
ls -al dist/*
if [[ $$(git status --porcelain=v1 2>/dev/null) ]] ; then \
echo 'Uncommitted changes' ; \
exit 1 ; \
fi
${MAKE} versions
read -p "Press enter to publish"
${PYTHON} -m twine upload dist/*
# FIXME: enable *after* nuking big files from history
# git tag -a "v${LOCAL_VERSION}" -m "v${LOCAL_VERSION}"
${PYTHON} -m omdev.scripts.bumpversion -w omlish/__about__.py
${MAKE} gen
### Utils
.PHONY: my-repl
my-repl: venv
${PYTHON} -m omdev.tools.sqlrepl repl mysql docker/compose.yml:omlish-mysql
.PHONY: pg-repl
pg-repl: venv
${PYTHON} -m omdev.tools.sqlrepl repl postgres docker/compose.yml:omlish-postgres
.PHONY: secret-pg-repl
secret-pg-repl: venv
${PYTHON} -m omdev.tools.sqlrepl repl postgres ~/Dropbox/.dotfiles/secrets.yml:postgres