forked from betagouv/ComparIA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
249 lines (200 loc) · 9.72 KB
/
Copy pathMakefile
File metadata and controls
249 lines (200 loc) · 9.72 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
239
240
241
242
243
244
245
246
247
248
249
.PHONY: help install install-backend install-frontend test test-backend test-dataset dev dev-redis dev-backend dev-frontend dev-controller build-frontend db-generate-init-old db db-prd-local docker-app-up docker-app-down docker-app-logs clean redis models-doc up-fr down-fr logs-fr display-env-fr up-da down-da logs-da display-env-da dataset-export-fr
# Variables
PYTHON := python3
UV := uv
NPM := yarn
BACKEND_PORT := 8008
FRONTEND_PORT := 5173
CONTROLLER_PORT := 21001
COMPARIA_REDIS_HOST ?= localhost
export COMPARIA_REDIS_HOST
KEEPASS_DB ?= $(HOME)/comparia_dev.kdbx
KEEPASS_GROUP_FR ?= instances/fr
KEEPASS_GROUP_DA ?= instances/da
help: ## Display this help
@echo "Available commands for compar:IA:"
@echo ""
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}'
###################################
# Shared - PostgreSQL and Redis init using docker
###################################
network: ## Create shared Docker network (idempotent)
@docker network create comparia-net 2>/dev/null || true
db-generate-init-old: ## (legacy) Create comparia_da and apply old SQL schema to both databases via docker exec
@bash devops/instances/postgres/generate-init-db.sh
@docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -c "CREATE DATABASE comparia_da OWNER comparia;" 2>/dev/null || true
@sed -e 's/"languia-dev"/"comparia"/g' -e 's/"languia-prd"/"comparia"/g' -e 's/"languia"/"comparia"/g' \
devops/instances/postgres/schema.sql | \
docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -d comparia
@sed -e 's/"languia-dev"/"comparia"/g' -e 's/"languia-prd"/"comparia"/g' -e 's/"languia"/"comparia"/g' \
devops/instances/postgres/schema.sql | \
docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -d comparia_da
db: ## Launch Postgres database using docker compose (empty schema, use db-migrate to apply)
@$(MAKE) network
@echo "Starting PostgreSQL database..."
docker compose -f devops/instances/postgres/postgres-simple.compose.yml up -d
db-reset-data:
@echo "Removing docker dev data (volumes)..."
@docker compose -f devops/instances/postgres/postgres-simple.compose.yml down -v
db-migrate: ## Apply pending Alembic migrations (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic upgrade head
db-migrate-generate: ## Generate a new Alembic migration (usage: make db-migrate-generate MSG="description", requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic revision --autogenerate -m "$(MSG)"
db-migrate-status: ## Show current Alembic migration status (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic current
db-schema-dump: ## Dump current database schema (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
pg_dump "$$COMPARIA_DB_URI" --schema-only --no-owner --no-privileges
redis: ## Launch Redis using docker compose
@$(MAKE) network
@echo "Starting Redis..."
docker compose -f devops/instances/redis/redis.compose.yml up -d
redis-down: ## Stop Redis
docker compose -f devops/instances/redis/redis.compose.yml down
###################################
# Instance fr docker
###################################
up-fr: ## Launch FR instance (frontend + backend + postgres + redis)
@$(MAKE) redis
@$(MAKE) db
eval $$(uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_FR)") && \
docker compose -f devops/instances/fr/app.compose.fr.yml up -d --build
down-fr: ## Stop FR instance
docker compose -f devops/instances/fr/app.compose.fr.yml down
logs-fr: ## Show logs for FR instance
docker compose -f devops/instances/fr/app.compose.fr.yml logs -f
display-env-fr: ## Display env vars loaded from KeePass for FR instance
uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_FR)" --mask
###################################
# Instance da docker
###################################
up-da: ## Launch DA instance (frontend + backend + postgres + redis)
eval $$(uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_DA)") && \
docker compose -f devops/instances/da/app.compose.da.yml up -d --build
down-da: ## Stop DA instance
docker compose -f devops/instances/da/app.compose.da.yml down
logs-da: ## Show logs for DA instance
docker compose -f devops/instances/da/app.compose.da.yml logs -f
display-env-da: ## Display env vars loaded from KeePass for DA instance
uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_DA)" --mask
###################################
# Development with local code
###################################
test: test-dataset ## Run all tests
test-dataset: ## Run dataset export tests (no DB required)
$(UV) run --group data python tests/dataset/test_comparison_to_turns.py
$(UV) run --group data python tests/dataset/test_streaming_export.py
install: install-backend install-frontend ## Install all dependencies (backend + frontend)
install-backend: ## Install Python backend dependencies with uv
@echo "Installing backend dependencies..."
@if ! command -v uv &> /dev/null; then \
echo "uv is not installed. Installing..."; \
curl -LsSf https://astral.sh/uv/install.sh | sh; \
fi
$(UV) sync
install-frontend: ## Install npm frontend dependencies
@echo "Installing frontend dependencies..."
cd frontend && $(NPM) install || npm install --legacy-peer-deps
dev: ## Launch backend and frontend (env vars must be exported, e.g. source .env)
$(MAKE) -j 2 dev-backend dev-frontend
dev-backend: ## Launch only the backend (FastAPI + Gradio)
@echo "Starting backend on port $(BACKEND_PORT)..."
$(UV) run uvicorn backend.main:app --reload --host 0.0.0.0 --port $(BACKEND_PORT) --timeout-graceful-shutdown 1
dev-frontend: ## Launch only the frontend (Vite + SvelteKit)
@echo "Starting frontend on port $(FRONTEND_PORT)..."
cd frontend && $(NPM) run dev
build-frontend: ## Build the frontend for production
@echo "Building frontend..."
cd frontend && $(NPM) run build
lint-python: ## Check python code
@echo "Checking python code..."
uv run mypy .
lint-frontend: ## Check frontend code
@echo "Checking frontend code..."
cd frontend && $(NPM) run lint
format-python: ## Format python code
@echo "Formatting python code..."
uv run autoflake .
uv run isort .
uv run black .
format-frontend: ## Format frontend code
@echo "Formatting frontend code..."
cd frontend && $(NPM) run format
check-requirements: ## Check that required tools are installed
@echo "Checking prerequisites..."
@command -v $(PYTHON) >/dev/null 2>&1 || { echo "Python 3 is required but not installed."; exit 1; }
@command -v $(NPM) >/dev/null 2>&1 || { echo "npm is required but not installed."; exit 1; }
@command -v $(UV) >/dev/null 2>&1 || { echo "uv is not installed. Run 'make install-backend' to install it."; }
@echo "All prerequisites are installed ✓"
clean: ## Clean generated files
@echo "Cleaning..."
rm -rf frontend/node_modules
rm -rf frontend/.svelte-kit
rm -rf frontend/build
rm -rf .venv
rm -rf __pycache__
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
###################################
# i18n utilities
###################################
i18n-clean-locales: ## Remove locales keys not present in fr
@echo "Cleaning frontend locales keys..."
cd frontend/locales && python maintenance.py
i18n-build-suggestions: ## generate frontend i18n prompt suggestions file
@echo "Generating frontend prompt suggestions..."
$(UV) run python -m utils.suggestions.build_suggestions
i18n-build-news: ## generate news files
@echo "Generating news files..."
$(UV) run python -m utils.news.build_news
###################################
# Models utilities
###################################
models-build: ## Build/generate model files from JSON sources
@echo "Generating models..."
$(UV) run python -m utils.models.build_models
models-maintenance: ## Run the models maintenance script
@echo "Models maintenance..."
$(UV) run python -m utils.models.maintenance
models-doc: ## Build/generate llm doc and JSON schemas
@echo "Generating LLM specs documentation and JSON schemas..."
$(UV) run python -m utils.models.schemas.build_doc
###################################
# Dataset utilities
###################################
dataset-export: ## Export FR datasets to HuggingFace (requires HF_PUSH_DATASET_KEY, HF_PUSH_DATASET_PATH and COMPARIA_DB_URI)
@echo "Exporting datasets..."
@if [ -z "$$COMPARIA_DB_URI" ]; then \
echo "Error: COMPARIA_DB_URI is not defined"; \
exit 1; \
fi
@if [ -z "$$HF_PUSH_DATASET_KEY" ]; then \
echo "Error: HF_PUSH_DATASET_KEY is not defined"; \
exit 1; \
fi
@if [ -z "$$HF_PUSH_DATASET_PATH" ]; then \
echo "Error: HF_PUSH_DATASET_PATH is not defined"; \
exit 1; \
fi
$(UV) run python -m utils.dataset.run fr
dataset-export-da: ## Export DA datasets to HuggingFace (requires HF_PUSH_DATASET_KEY, HF_PUSH_DATASET_PATH and COMPARIA_DB_URI)
@echo "Exporting datasets..."
@if [ -z "$$COMPARIA_DB_URI" ]; then \
echo "Error: COMPARIA_DB_URI is not defined"; \
exit 1; \
fi
@if [ -z "$$HF_PUSH_DATASET_KEY" ]; then \
echo "Error: HF_PUSH_DATASET_KEY is not defined"; \
exit 1; \
fi
@if [ -z "$$HF_PUSH_DATASET_PATH" ]; then \
echo "Error: HF_PUSH_DATASET_PATH is not defined"; \
exit 1; \
fi
$(UV) run python -m utils.dataset.run da