-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (125 loc) · 3.57 KB
/
Makefile
File metadata and controls
149 lines (125 loc) · 3.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
# Shell / Make config
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.SILENT:
MAKEFLAGS += --no-print-directory
# -----------------------------
# User-configurable variables (edit this)
# INFRA_SERVICES: long-running infra (db, broker, cache, ...)
# INFRA_INIT_SERVICES: one-shot services that prepare INFRA_SERVICES
# -----------------------------
PROJECT_NAME ?= $(notdir $(abspath .))
INFRA_SERVICES ?= db_pg
INFRA_INIT_SERVICES ?=
# -----------------------------
# Internal vars / aliases
# -----------------------------
DOCKER_COMPOSE := docker compose -p $(PROJECT_NAME)
PIP_AUDIT := scripts/makefile/pip_audit.sh
SLOTSCHECK := scripts/makefile/slotscheck.sh
DOCKER_ENV := scripts/makefile/docker_env.sh
LOCAL_ENV := scripts/makefile/local_env.sh
DOCKER_PRUNE := scripts/makefile/docker_prune.sh
PYCACHE_DEL := scripts/makefile/pycache_del.sh
DISHKA_PLOT_DATA := scripts/dishka/plot_dependencies_data.py
# Test stack is isolated by project name
TEST_PROJECT ?= $(PROJECT_NAME)-test
DC_TEST_DOCKER := docker compose \
-p $(TEST_PROJECT) \
-f docker-compose.yml \
-f docker-compose.test.yml
TEST_RUNNER := $(TEST_PROJECT)-runner
# Pytest paths
PYTEST_PATHS_LIGHT := \
tests/sanity \
tests/unit \
tests/integration/no_infra
PYTEST_PATHS_ALL := \
$(PYTEST_PATHS_LIGHT) \
tests/smoke \
tests/integration/with_infra
# Pytest args
PYTEST_ARGS_VERBOSE := -s -vv
PYTEST_ARGS_COV := \
--cov=src \
--cov-report=term-missing \
--cov-report=html
PYTEST_ARGS_COV_DOCKER := \
--cov=src \
--cov-report=term-missing
# Safety
.PHONY: pip-audit
pip-audit:
$(PIP_AUDIT)
# Code quality
.PHONY: slotscheck lint test check
slotscheck:
$(SLOTSCHECK) src
lint:
ruff check --fix
ruff format
tombi format
tombi lint
deptry
$(MAKE) slotscheck
lint-imports
mypy
test:
pytest -v \
$(PYTEST_PATHS_LIGHT) \
$(PYTEST_ARGS_COV)
check: lint test
coverage html
# Docker compose
.PHONY: docker-env local-env upd up upd-local up-local down stop-all
docker-env:
$(DOCKER_ENV)
local-env:
$(LOCAL_ENV)
upd: docker-env
$(DOCKER_COMPOSE) up -d --build --force-recreate
up: docker-env
$(DOCKER_COMPOSE) up --build --force-recreate
upd-local: local-env
$(DOCKER_COMPOSE) up -d --build --force-recreate $(INFRA_SERVICES) $(INFRA_INIT_SERVICES)
up-local: local-env
$(DOCKER_COMPOSE) up --build --force-recreate $(INFRA_SERVICES) $(INFRA_INIT_SERVICES)
down:
$(DOCKER_COMPOSE) down
stop-all:
docker ps -q | xargs -r docker stop
# Tests (with infra)
.PHONY: test-docker
test-docker: docker-env
rc=0; \
$(DC_TEST_DOCKER) down -v --remove-orphans >/dev/null 2>&1 || true; \
if [ -n "$(strip $(INFRA_SERVICES))" ]; then \
$(DC_TEST_DOCKER) up -d --build --wait --wait-timeout 180 $(INFRA_SERVICES); \
if [ -n "$(strip $(INFRA_INIT_SERVICES))" ]; then \
$(DC_TEST_DOCKER) up --build $(INFRA_INIT_SERVICES) >/dev/null; \
fi; \
else \
echo "INFRA_SERVICES is empty, skipping infra startup"; \
fi; \
$(DC_TEST_DOCKER) run --build --name $(TEST_RUNNER) app \
pytest $(PYTEST_ARGS_VERBOSE) \
$(PYTEST_PATHS_ALL) \
$(PYTEST_ARGS_COV_DOCKER) \
|| rc=$$?; \
docker cp $(TEST_RUNNER):/tmp/.coverage ./.coverage.docker 2>/dev/null || true; \
docker rm $(TEST_RUNNER) >/dev/null 2>&1 || true; \
$(DC_TEST_DOCKER) down -v --remove-orphans; \
coverage html --data-file=.coverage.docker -d htmlcov-docker && \
echo "Coverage HTML report: htmlcov-docker/index.html" || true; \
exit $$rc
.PHONY: prune
prune:
$(DOCKER_PRUNE)
# Project structure visualization
.PHONY: pycache-del tree plot-data
pycache-del:
$(PYCACHE_DEL)
tree: pycache-del
tree
plot-data:
APP_LOGGING_LEVEL=CRITICAL python $(DISHKA_PLOT_DATA)