-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (106 loc) · 3.63 KB
/
Makefile
File metadata and controls
124 lines (106 loc) · 3.63 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
##########################################################################
# Makefile — fastapi-tenancy developer workflow #
#------------------------------------------------------------------------#
# #
# Quick reference #
#------------------------------------------------------------------------#
# make dev Install package in editable mode with all extras #
# make lint ruff check + ruff format #
# make fmt Auto-fix formatting with ruff #
# make type mypy --strict #
# make security bandit SAST scan #
# make check lint + type + security #
# #
# make test Unit tests only #
# make test-int Integration tests (starts Docker automatically) #
# make test-e2e End-to-end tests (starts Docker automatically) #
# make test-all Full suite (starts Docker automatically) #
# make coverage Full suite → HTML report in htmlcov/ #
# #
# make docker-up Start PostgreSQL 16 + MySQL 8 + Redis 7 #
# make docker-down Tear down all test containers + volumes #
# #
# make build Build wheel + sdist #
# make clean Remove all build / test artefacts #
##########################################################################
.PHONY: dev lint fmt type security check \
test test-int test-e2e test-all coverage \
docker-up docker-down \
build clean
##########
# Config #
##########
COMPOSE_FILE := docker-compose.test.yml
PYTEST := python -m pytest
COV_FLAGS := --cov=fastapi_tenancy \
--cov-report=term-missing \
--cov-report=html:htmlcov \
--cov-report=xml:coverage.xml
WAIT_SECS := 20
PYTHON_VER := 3.12
#####################
# Development setup #
#####################
dev:
uv sync --all-extras --python $(PYTHON_VER)
###################
# Static analysis #
###################
lint:
uv run ruff check src tests
uv run ruff format --check src tests
echo "Code Linted Successfully"
fmt:
uv run ruff check --fix src tests
uv run ruff format src tests
type:
uv run mypy src tests
security:
uv run bandit -r src/fastapi_tenancy -ll -ii
check: lint type security
##########
# Docker #
##########
docker-up:
@echo "Checking if test services are running..."
@if [ -z "$$(docker compose -f $(COMPOSE_FILE) ps -q)" ]; then \
echo "Services not running. Starting them..."; \
docker compose -f $(COMPOSE_FILE) up -d; \
echo "Waiting $(WAIT_SECS)s for services to become healthy…"; \
sleep $(WAIT_SECS); \
else \
echo "Services already running. Skipping startup."; \
fi
@docker compose -f $(COMPOSE_FILE) ps
@echo
@echo
docker-down:
docker compose -f $(COMPOSE_FILE) down -v --remove-orphans
#########
# Tests #
#########
test:
uv run $(PYTEST) -m unit tests/ --tb=short -v
test-int: docker-up
uv run $(PYTEST) -m integration tests/ --tb=short -v $(COV_FLAGS)
test-e2e: docker-up
uv run $(PYTEST) -m e2e tests/ --tb=short -v $(COV_FLAGS)
test-all: docker-up
uv run $(PYTEST) tests/ --tb=short -v $(COV_FLAGS) 2>&1 | tee test-results.txt
coverage: docker-up
uv run $(PYTEST) tests/ --tb=short $(COV_FLAGS)
@echo ""
@echo "HTML report → htmlcov/index.html"
#########
# Build #
#########
build:
uv build
################
# Housekeeping #
################
clean:
rm -rf dist build htmlcov coverage.xml test-results.txt .coverage
rm -rf .pytest_cache .mypy_cache .ruff_cache .tox
find . -name "*.pyc" -delete
find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true