-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
304 lines (249 loc) · 7.63 KB
/
Makefile
File metadata and controls
304 lines (249 loc) · 7.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
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
# -- General
SHELL := /bin/bash
# -- Docker
COMPOSE = docker compose
COMPOSE_UP = $(COMPOSE) up -d --remove-orphans
TYCHO_UV = cd src/tycho && direnv exec .
OCR_UV = cd src/ocr && direnv exec .
NOTEBOOK_UV = cd src/notebook && direnv exec .
DEV_UV = cd dev && direnv exec .
default: help
## -- Files
.pre-commit-cache:
mkdir .pre-commit-cache
.git/hooks/pre-commit:
cp bin/git-pre-commit-hook .git/hooks/pre-commit
.git/hooks/commit-msg:
cp bin/git-commit-msg-hook .git/hooks/commit-msg
### BOOTSTRAP
setup: ## copy example env files to local files
@cp src/tycho/.envrc.sample src/tycho/.envrc
@cp src/notebook/.envrc.sample src/notebook/.envrc
@cp src/ocr/.envrc.sample src/ocr/.envrc
@cp env.d/tycho-example env.d/tycho
@cp env.d/ocr-example env.d/ocr
@cp env.d/notebook-example env.d/notebook
@cp env.d/postgresql-example env.d/postgresql
@cd src/tycho && direnv allow
@cd src/ocr && direnv allow
@cd src/notebook && direnv allow
@echo "✅ Environment files copied. Please edit env.d/* with your actual values."
.PHONY: setup
bootstrap: ## setup development environment (build dev service and install git hooks)
bootstrap: \
run-postgres \
run-qdrant \
setup-qdrant \
build \
migrate \
create-superuser \
jupytext--to-ipynb
.PHONY: bootstrap
git-hooks: ## install pre-commit hook
git-hooks: \
.pre-commit-cache \
.git/hooks/pre-commit \
.git/hooks/commit-msg
.PHONY: git-hooks
### BUILD
build: ## build services image
build: \
build-dev \
build-tycho \
build-ocr \
build-notebook
.PHONY: build
build-dev: ## build development environment image
@$(DEV_UV) uv sync --locked
.PHONY: build-dev
build-notebook: ### setup notebook kernels natively
@$(NOTEBOOK_UV) uv sync --locked
.PHONY: build-notebook
build-tycho: ## build tycho image
# not using @ which suppress the command's echoing in terminal
$(TYCHO_UV) uv sync --group dev --locked
.PHONY: build-tycho
build-ocr:
$(OCR_UV) uv sync --group dev --locked
.PHONY: build-ocr
jupytext--to-md: ## convert local ipynb files into md
cd src/notebook && uv run jupytext --to md *.ipynb && cd ../..
.PHONY: jupytext--to-md
jupytext--to-ipynb: ## convert remote md files into ipynb
cd src/notebook && uv run jupytext --to ipynb *.md && cd ../..
.PHONY: jupytext--to-ipynb
### LOGS
logs: ## display all services logs (follow mode)
@$(COMPOSE) logs -f
.PHONY: logs
migrate: ## migrate tycho database
@echo "Migrating tycho database…"
@bin/manage migrate
.PHONY: migrate
create-superuser: ## create tycho super user
@echo "Creating tycho super user…"
@bin/manage createsuperuser --noinput || true
.PHONY: create-superuser
setup-qdrant: ## setup qdrant collection if not exists
@echo "Setting up Qdrant collection…"
@$(TYCHO_UV) python config/setup-qdrant.py
.PHONY: setup-qdrant
### SASS
sass-compile: ## compile SCSS files to CSS
@bin/sass compile
.PHONY: sass-compile
sass-watch: ## watch and compile SCSS files on changes
@bin/sass watch
.PHONY: sass-watch
### RUN
run-all: ## run the whole stack
run-all: \
run-notebook \
run-es
.PHONY: run-all
run-notebook: ## run the notebook service
$(NOTEBOOK_UV) jupyter lab --ip=0.0.0.0 --port=8888 --no-browser
.PHONY: run-notebook
run-es: ## run the elasticsearch service
$(COMPOSE_UP) elasticsearch
.PHONY: run-es
run-postgres: ## run the DB service
$(COMPOSE_UP) postgresql
.PHONY: run-postgres
run-qdrant: ## run the Qdrant vector database service
$(COMPOSE_UP) qdrant
.PHONY: run-qdrant
run-tycho: ## run the tycho service
@bin/manage runserver
.PHONY: run-tycho
run-ocr: ## run the ocr service
$(OCR_UV) uvicorn api.main:app --reload --port=8001
.PHONY: run-ocr
dev: ## run tycho with sass watch and browser auto-reload
@echo "🚀 Starting development server with auto-reload..."
@echo " Press Ctrl+C to stop all processes"
@trap 'kill 0' EXIT; \
bin/sass watch & \
bin/manage runserver
.PHONY: dev
## LINT
# -- Global linting
lint: ## lint all sources
lint: \
lint-notebook \
lint-tycho \
lint-ocr
.PHONY: lint
lint-fix: ## lint and fix all sources
lint-fix: \
lint-notebook-fix \
lint-tycho-fix \
lint-ocr-fix
.PHONY: lint-fix
# -- Per-service linting
lint-notebook: ## lint notebook python sources
@echo 'lint:notebook started (warnings only)…'
$(NOTEBOOK_UV) ruff check . || true
$(NOTEBOOK_UV) ruff format --check . || true
.PHONY: lint-notebook
lint-notebook-fix: ## lint and fix notebook python sources
@echo 'lint:notebook-fix started (warnings only)…'
$(NOTEBOOK_UV) ruff check --fix . || true
$(NOTEBOOK_UV) ruff format . || true
.PHONY: lint-notebook-fix
lint-tycho: ## lint tycho python sources
lint-tycho: \
lint-tycho-ruff \
lint-tycho-djlint \
lint-tycho-mypy
.PHONY: lint-tycho
lint-tycho-fix: ## lint and fix tycho python sources
lint-tycho-fix: \
lint-tycho-ruff-fix \
lint-tycho-djlint-fix \
lint-tycho-mypy
.PHONY: lint-tycho-fix
lint-tycho-ruff: ## lint tycho python sources with ruff (check only, like CI)
@echo 'lint:tycho-ruff started…'
$(TYCHO_UV) ruff check .
$(TYCHO_UV) ruff format --check .
.PHONY: lint-tycho-ruff
lint-tycho-ruff-fix: ## lint and fix tycho python sources with ruff
@echo 'lint:tycho-ruff-fix started…'
$(TYCHO_UV) ruff check --fix .
$(TYCHO_UV) ruff format .
.PHONY: lint-tycho-ruff-fix
lint-tycho-djlint: ## lint tycho template sources with djlint
@echo 'lint:tycho-djlint started…'
$(TYCHO_UV) djlint presentation/templates --check
.PHONY: lint-tycho-djlint
lint-tycho-djlint-fix: ## lint and fix tycho template sources with djlint
@echo 'lint:tycho-djlint-fix started…'
$(TYCHO_UV) djlint presentation/templates --reformat
.PHONY: lint-tycho-djlint-fix
lint-tycho-mypy: ## lint tycho python sources with mypy
@echo 'lint:tycho-mypy started…'
$(TYCHO_UV) mypy .
.PHONY: lint-tycho-mypy
lint-ocr: ## lint ocr python sources
lint-ocr: \
lint-ocr-ruff \
lint-ocr-mypy
.PHONY: lint-ocr
lint-ocr-fix: ## lint and fix ocr python sources
lint-ocr-fix: \
lint-ocr-ruff-fix \
lint-ocr-mypy
.PHONY: lint-ocr-fix
lint-ocr-ruff: ## lint ocr python sources with ruff (check only, like CI)
@echo 'lint:ocr-ruff started…'
$(OCR_UV) ruff check .
$(OCR_UV) ruff format --check .
.PHONY: lint-ocr-ruff
lint-ocr-ruff-fix: ## lint and fix ocr python sources with ruff
@echo 'lint:ocr-ruff-fix started…'
$(OCR_UV) ruff check --fix .
$(OCR_UV) ruff format .
.PHONY: lint-ocr-ruff-fix
lint-ocr-mypy: ## lint ocr python sources with mypy
@echo 'lint:ocr-mypy started…'
$(OCR_UV) mypy .
.PHONY: lint-ocr-mypy
## TEST
test: ## test all services
test: \
test-tycho \
test-ocr
.PHONY: test
test-tycho: ## test tycho python sources
@echo 'test:tycho started…'
$(TYCHO_UV) pytest --numprocesses=logical --create-db $(ARGS)
.PHONY: test-tycho
test-ocr: ## test ocr python sources
@echo 'test:ocr started…'
$(OCR_UV) pytest $(ARGS)
.PHONY: test-ocr
## MANAGE docker services
status: ## an alias for "docker compose ps"
@$(COMPOSE) ps
.PHONY: status
down: ## stop and remove containers but keep volumes (data persists)
@$(COMPOSE) down
.PHONY: down
down-all: ## stop and remove containers AND volumes (⚠️ data loss!)
@$(COMPOSE) down -v
.PHONY: down-all
volumes: ## show docker volumes info
@echo "=== DOCKER VOLUMES ==="
@docker volume ls | grep csplab || echo "No csplab volumes found"
@echo ""
@echo "=== POSTGRES DATA SIZE ==="
@docker volume inspect csplab_postgres_data --format '{{.Mountpoint}}' 2>/dev/null | xargs -I {} du -sh {} 2>/dev/null || echo "Volume not found or not accessible"
.PHONY: volumes
stop: ## stop all servers
@$(COMPOSE) stop
.PHONY: stop
# -- Misc
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help