-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (195 loc) · 7.24 KB
/
Makefile
File metadata and controls
238 lines (195 loc) · 7.24 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
# =============================================================================
# MedX — Medical AI Intelligence System
# Development Makefile
# =============================================================================
.PHONY: help install dev test lint format clean \
infra-up infra-down infra-logs infra-health infra-clean \
db-migrate db-revision db-downgrade db-history db-current db-reset \
run-api run-ui run \
test-infra test-cov test-fast \
check docker-build docker-up docker-down docker-logs docker-clean \
index-kb docs check-python setup-db
# Default target
help:
@echo "MedX Development Commands"
@echo "========================="
@echo ""
@echo "Setup:"
@echo " make install Install production dependencies"
@echo " make dev Install development dependencies"
@echo " make setup-db Start infra + run migrations"
@echo ""
@echo "Infrastructure:"
@echo " make infra-up Start PostgreSQL, Redis, Qdrant containers"
@echo " make infra-down Stop infrastructure containers"
@echo " make infra-logs View infrastructure logs"
@echo " make infra-health Check infrastructure health"
@echo " make infra-clean Stop infra and remove volumes (DESTRUCTIVE)"
@echo ""
@echo "Database:"
@echo " make db-migrate Run Alembic migrations"
@echo " make db-revision Create new migration"
@echo " make db-downgrade Rollback last migration"
@echo " make db-history Show migration history"
@echo " make db-current Show current migration"
@echo " make db-reset Reset database (DESTRUCTIVE)"
@echo ""
@echo "Development:"
@echo " make run-api Start FastAPI server (uvicorn, port 8000)"
@echo " make run-ui Start Reflex UI"
@echo " make run Start full stack (infra + API + UI)"
@echo ""
@echo "Testing:"
@echo " make test Run all tests"
@echo " make test-infra Run infrastructure tests"
@echo " make test-cov Run tests with coverage"
@echo " make test-fast Run tests, stop on first failure"
@echo ""
@echo "Code Quality:"
@echo " make lint Run linters (ruff, mypy)"
@echo " make format Format code (black, isort)"
@echo " make check Format + lint + test"
@echo ""
@echo "Docker:"
@echo " make docker-build Build Docker images"
@echo " make docker-up Start all services via Docker Compose"
@echo " make docker-down Stop all services"
@echo " make docker-logs Follow Docker Compose logs"
@echo " make docker-clean Stop, remove volumes and images"
@echo ""
@echo "Utilities:"
@echo " make index-kb Index knowledge base into Qdrant"
@echo " make clean Remove cache and build artifacts"
@echo " make check-python Verify Python version"
@echo ""
# =============================================================================
# Setup & Installation
# =============================================================================
install:
pip install -r requirements.txt
dev:
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .
setup-db: infra-up db-migrate
@echo "Database setup complete"
# =============================================================================
# Infrastructure Management
# =============================================================================
infra-up:
docker compose up -d postgres redis qdrant
@echo "Waiting for services to be healthy..."
@sleep 5
@make infra-health
infra-down:
docker compose down
infra-logs:
docker compose logs -f postgres redis qdrant
infra-health:
@echo "=== PostgreSQL ==="
@docker compose exec postgres pg_isready -U medex -d medex || echo "PostgreSQL not ready"
@echo ""
@echo "=== Redis ==="
@docker compose exec redis redis-cli ping || echo "Redis not ready"
@echo ""
@echo "=== Qdrant ==="
@curl -s http://localhost:6333/readyz || echo "Qdrant not ready"
@echo ""
infra-clean:
docker compose down -v
@echo "Infrastructure volumes removed"
# =============================================================================
# Database Management (Alembic)
# =============================================================================
db-migrate:
alembic upgrade head
@echo "Migrations applied successfully"
db-revision:
@read -p "Migration message: " msg; \
alembic revision --autogenerate -m "$$msg"
db-downgrade:
alembic downgrade -1
@echo "Rolled back one migration"
db-history:
alembic history --verbose
db-current:
alembic current
db-reset:
@echo "WARNING: This will delete all data!"
@read -p "Are you sure? [y/N] " confirm; \
if [ "$$confirm" = "y" ]; then \
alembic downgrade base; \
alembic upgrade head; \
echo "Database reset complete"; \
fi
# =============================================================================
# Development Servers
# =============================================================================
run-api:
uvicorn run_api:app --reload --host 0.0.0.0 --port 8000
run-ui:
cd ui && python run.py
run: infra-up
@echo "Starting API and UI..."
@make run-api &
@sleep 2
@make run-ui
# =============================================================================
# Testing
# =============================================================================
test:
pytest tests/ -v --asyncio-mode=auto
test-infra:
pytest tests/test_infrastructure.py -v --asyncio-mode=auto
test-cov:
pytest tests/ -v --asyncio-mode=auto --cov=src/medex --cov-report=html --cov-report=term-missing
@echo "Coverage report: htmlcov/index.html"
test-fast:
pytest tests/ -v --asyncio-mode=auto -x -q
# =============================================================================
# Code Quality
# =============================================================================
lint:
ruff check src/ tests/
mypy src/ --ignore-missing-imports
format:
black src/ tests/
isort src/ tests/
ruff check --fix src/ tests/
check: format lint test
@echo "All checks passed!"
# =============================================================================
# Docker
# =============================================================================
docker-build:
docker compose build
docker-up:
docker compose up -d
docker-down:
docker compose down
docker-logs:
docker compose logs -f
docker-clean:
docker compose down -v --rmi local
docker system prune -f
# =============================================================================
# Utilities
# =============================================================================
clean:
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
find . -type d -name ".mypy_cache" -exec rm -rf {} + 2>/dev/null || true
find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
find . -type d -name "htmlcov" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name ".coverage" -delete 2>/dev/null || true
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf build/ dist/
@echo "Cleaned up cache and build artifacts"
index-kb:
python scripts/index_knowledge_base.py
docs:
python -m pdoc --html --output-dir docs/api src/medex
check-python:
@python --version
@echo "Required: Python 3.10+"