-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathMakefile
More file actions
298 lines (249 loc) · 11.2 KB
/
Makefile
File metadata and controls
298 lines (249 loc) · 11.2 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
.PHONY: help install install-dev venv
.PHONY: format lint lint-go lint-frontend lint-frontend-fix lint-all typecheck typecheck-frontend check check-all ruff-fix ruff-all
.PHONY: test test-go test-all
.PHONY: clean clean-venv clean-all
.PHONY: build-dmg build-linux verify-linux
.PHONY: electron-build electron-run electron electron-dev electron-install
.PHONY: list show shell jupyter info quickstart
.PHONY: pr
# Default target
.DEFAULT_GOAL := help
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[1;33m
NC := \033[0m # No Color
# Go build flags
CGO_LDFLAGS := -L./build/tokenizers
# Version from package.json
VERSION := $(shell cd src/frontend && node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
##@ General
help: ## Display this help message
@echo "$(BLUE)Kiji PII Detection - Development Commands$(NC)"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make $(GREEN)<target>$(NC)\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2 } /^##@/ { printf "\n$(BLUE)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
info: ## Show project info
@echo "$(BLUE)Project Information$(NC)"
@echo "Name: $(GREEN)kiji-pii-detection$(NC)"
@echo -n "Version: $(GREEN)"
@cd src/frontend && node -p "require('./package.json').version" 2>/dev/null || echo "unknown"
@echo "$(NC)"
@echo "Python: $(GREEN)$(shell .venv/bin/python --version 2>&1 || echo "Not installed (run 'make venv')")$(NC)"
@echo "UV: $(GREEN)$(shell uv --version 2>&1)$(NC)"
@echo ""
@echo "$(BLUE)Virtual Environment$(NC)"
@if [ -d ".venv" ]; then \
echo "Status: $(GREEN)Created$(NC)"; \
echo "Path: $(GREEN).venv$(NC)"; \
else \
echo "Status: $(YELLOW)Not created (run 'make venv')$(NC)"; \
fi
@echo ""
@echo "$(BLUE)Version Information$(NC)"
@echo " Version is managed in src/frontend/package.json"
@echo " Backend receives version via ldflags during build"
@echo " Check version: ./build/kiji-proxy --version"
@echo " API endpoint: http://localhost:8080/version"
@echo ""
@echo "$(BLUE)Quick Commands$(NC)"
@echo " make install - Install dependencies"
@echo " make test - Run tests"
@echo " make help - Show all commands"
##@ Git & PR
pr: ## Generate semantic PR title + summary with Claude Code and create the PR
@./src/scripts/create_pr.sh
##@ Setup & Installation
venv: ## Create virtual environment with uv
@echo "$(BLUE)Creating virtual environment with Python 3.13...$(NC)"
uv venv --python 3.13
@echo "$(GREEN)✅ Virtual environment created at .venv$(NC)"
@echo "$(YELLOW)Activate with: source .venv/bin/activate$(NC)"
install: venv ## Install project with all dependencies
@echo "$(BLUE)Installing project dependencies...$(NC)"
uv pip install -e .
@echo "$(GREEN)✅ Installation complete$(NC)"
install-dev: venv ## Install with development dependencies
@echo "$(BLUE)Installing with dev dependencies...$(NC)"
uv pip install -e ".[dev]"
@echo "$(GREEN)✅ Dev installation complete$(NC)"
##@ Code Quality
format: ## Format code with ruff
@echo "$(BLUE)Formatting code...$(NC)"
uv run ruff format .
@echo "$(GREEN)✅ Code formatted$(NC)"
lint: ## Run linters with ruff
@echo "$(BLUE)Running linters...$(NC)"
uv run ruff check model/
@echo "$(GREEN)✅ Linting complete$(NC)"
lint-go: ## Lint Go code with golangci-lint
@echo "$(BLUE)Linting Go code...$(NC)"
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "$(YELLOW)⚠️ golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest$(NC)"; \
exit 1; \
fi
@echo "$(GREEN)✅ Go linting complete$(NC)"
lint-frontend: ## Lint frontend code with ESLint
@echo "$(BLUE)Linting frontend code...$(NC)"
@if [ ! -d "src/frontend/node_modules" ]; then \
echo "$(YELLOW)⚠️ Frontend dependencies not installed. Run 'make electron-install' first.$(NC)"; \
exit 1; \
fi
@cd src/frontend && npm run lint
@echo "$(GREEN)✅ Frontend linting complete$(NC)"
lint-frontend-fix: ## Lint and auto-fix frontend code with ESLint, then run type check
@echo "$(BLUE)Auto-fixing frontend code...$(NC)"
@if [ ! -d "src/frontend/node_modules" ]; then \
echo "$(YELLOW)⚠️ Frontend dependencies not installed. Run 'make electron-install' first.$(NC)"; \
exit 1; \
fi
@cd src/frontend && npm run lint:fix
@echo "$(GREEN)✅ Frontend auto-fix complete$(NC)"
@echo "$(BLUE)Running TypeScript type check...$(NC)"
@cd src/frontend && npm run type-check
@echo "$(GREEN)✅ TypeScript type check complete$(NC)"
lint-all: lint lint-go lint-frontend ## Run all linters (Python, Go, Frontend)
@echo "$(GREEN)✅ All linting complete$(NC)"
typecheck: ## Run type checker with ruff
@echo "$(BLUE)Running type checker...$(NC)"
uv run ruff check model/ --select TYP
@echo "$(GREEN)✅ Type checking complete$(NC)"
typecheck-frontend: ## Run TypeScript type checking
@echo "$(BLUE)Running TypeScript type checker...$(NC)"
@if [ ! -d "src/frontend/node_modules" ]; then \
echo "$(YELLOW)⚠️ Frontend dependencies not installed. Run 'make electron-install' first.$(NC)"; \
exit 1; \
fi
@cd src/frontend && npm run type-check
@echo "$(GREEN)✅ TypeScript type checking complete$(NC)"
check: format lint typecheck ## Run Python code quality checks
check-all: format lint-all typecheck typecheck-frontend ## Run all code quality checks (Python, Go, Frontend)
ruff-fix: ## Auto-fix ruff issues
@echo "$(BLUE)Auto-fixing ruff issues...$(NC)"
uv run ruff check model/ --fix
@echo "$(GREEN)✅ Auto-fix complete$(NC)"
ruff-all: ## Run all ruff checks (lint + format + typecheck)
@echo "$(BLUE)Running all ruff checks...$(NC)"
uv run ruff check model/ --fix
uv run ruff format .
@echo "$(GREEN)✅ All ruff checks complete$(NC)"
##@ Testing
test-python: ## Run Python tests
@echo "$(BLUE)Running Python tests...$(NC)"
uv run pytest tests/ -v
@echo "$(GREEN)✅ Tests complete$(NC)"
test-go: ## Run Go tests
@echo "$(BLUE)Running Go tests...$(NC)"
CGO_LDFLAGS="$(CGO_LDFLAGS)" go test ./... -v
@echo "$(GREEN)✅ Go tests complete$(NC)"
test-all: test test-go ## Run all tests (Python, Go)
@echo "$(GREEN)✅ All tests complete$(NC)"
##@ Cleanup
clean: ## Remove build artifacts and cache
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
find . -type d \( -name "__pycache__" -o -name "*.egg-info" -o -name ".pytest_cache" -o -name ".mypy_cache" \) -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
rm -rf build/ *.egg-info
@echo "$(GREEN)✅ Cleanup complete$(NC)"
clean-venv: ## Remove virtual environment
@echo "$(BLUE)Removing virtual environment...$(NC)"
rm -rf .venv
@echo "$(GREEN)✅ Virtual environment removed$(NC)"
clean-all: clean clean-venv ## Remove everything (artifacts, cache, and venv)
@echo "$(GREEN)✅ Full cleanup complete$(NC)"
##@ Electron
electron-install: ## Install Electron UI dependencies
@echo "$(BLUE)Installing Electron UI dependencies...$(NC)"
@cd src/frontend && npm install
@echo "$(GREEN)✅ Electron dependencies installed$(NC)"
setup-onnx: ## Set up ONNX Runtime library for development
@echo "$(BLUE)Setting up ONNX Runtime library...$(NC)"
@mkdir -p build
@if [ -f "build/libonnxruntime.1.24.2.dylib" ]; then \
echo "$(GREEN)✅ ONNX library already exists$(NC)"; \
elif [ -f "src/frontend/resources/libonnxruntime.1.24.2.dylib" ]; then \
ln -sf ../src/frontend/resources/libonnxruntime.1.24.2.dylib build/libonnxruntime.1.24.2.dylib; \
echo "$(GREEN)✅ Linked existing ONNX library from resources$(NC)"; \
else \
if [ ! -d ".venv" ]; then \
echo "$(YELLOW)Creating virtual environment with Python 3.13...$(NC)"; \
uv venv --python 3.13; \
fi; \
uv pip install --quiet onnxruntime==1.24.2; \
ONNX_LIB=$$(find .venv -name "libonnxruntime*.dylib" | head -1); \
if [ -n "$$ONNX_LIB" ]; then \
cp "$$ONNX_LIB" build/libonnxruntime.1.24.2.dylib; \
echo "$(GREEN)✅ ONNX library installed$(NC)"; \
else \
echo "$(YELLOW)⚠️ Could not find ONNX library, continuing anyway$(NC)"; \
fi; \
fi
build-go: ## Build Go binary for development
@echo "$(BLUE)Building Go binary for development...$(NC)"
@mkdir -p build
@CGO_ENABLED=1 \
CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go build \
-ldflags="-X main.version=$(VERSION) -extldflags '$(CGO_LDFLAGS)'" \
-o build/kiji-proxy \
./src/backend
@echo "$(GREEN)✅ Go binary built at build/kiji-proxy (version $(VERSION))$(NC)"
electron-build: ## Build Electron app for production
@echo "$(BLUE)Building Electron app...$(NC)"
@cd src/frontend && npm run build:electron
@echo "$(GREEN)✅ Electron app built$(NC)"
electron-run: setup-onnx build-go electron-build ## Run Electron app (builds Go binary and frontend first)
@echo "$(BLUE)Preparing resources for Electron...$(NC)"
@mkdir -p src/frontend/resources
@cp build/kiji-proxy src/frontend/resources/kiji-proxy
@chmod +x src/frontend/resources/kiji-proxy
@if [ -f "build/libonnxruntime.1.24.2.dylib" ]; then \
cp build/libonnxruntime.1.24.2.dylib src/frontend/resources/libonnxruntime.1.24.2.dylib; \
echo "$(GREEN)✅ ONNX library copied to resources$(NC)"; \
else \
echo "$(YELLOW)⚠️ ONNX library not found at build/libonnxruntime.1.24.2.dylib$(NC)"; \
fi
@echo "$(GREEN)✅ Resources prepared$(NC)"
@echo "$(BLUE)Starting Electron app...$(NC)"
@cd src/frontend && NODE_ENV=development npm run electron
electron: electron-run ## Alias for electron-run
electron-dev: ## Run Electron app in development mode (assumes backend is running in debugger)
@echo "$(BLUE)Building frontend for Electron...$(NC)"
@cd src/frontend && npm run build:electron
@echo "$(GREEN)✅ Frontend built$(NC)"
@echo "$(BLUE)Starting Electron in development mode...$(NC)"
@echo "$(YELLOW)Note: Assumes Go backend is running separately (e.g., in VSCode debugger)$(NC)"
@echo "$(YELLOW)Note: Run 'npm run dev' in another terminal for hot reload$(NC)"
@cd src/frontend && EXTERNAL_BACKEND=true npm run electron:dev
electron-dev-external: electron-dev ## Alias for electron-dev (for backwards compatibility)
go-backend-dev: ## Run Go backend in development mode
@echo "$(BLUE)Running Go backend in development mode...$(NC)"
CGO_LDFLAGS="$(CGO_LDFLAGS)" go run ./src/backend -config ./src/backend/config/config.development.json
##@ Build
build-dmg: ## Build DMG package with Go binary and Electron app
@echo "$(BLUE)Building DMG package...$(NC)"
@if [ ! -f "src/scripts/build_dmg.sh" ]; then \
echo "$(YELLOW)⚠️ build_dmg.sh script not found$(NC)"; \
exit 1; \
fi
@chmod +x src/scripts/build_dmg.sh
@./src/scripts/build_dmg.sh
@echo "$(GREEN)✅ DMG build complete$(NC)"
build-linux: ## Build Linux standalone binary (without Electron)
@echo "$(BLUE)Building Linux standalone binary...$(NC)"
@if [ ! -f "src/scripts/build_linux.sh" ]; then \
echo "$(YELLOW)⚠️ build_linux.sh script not found$(NC)"; \
exit 1; \
fi
@chmod +x src/scripts/build_linux.sh
@./src/scripts/build_linux.sh
@echo "$(GREEN)✅ Linux build complete$(NC)"
verify-linux: ## Verify Linux build includes all required files (tokenizer, model, etc.)
@echo "$(BLUE)Verifying Linux build...$(NC)"
@if [ ! -f "src/scripts/verify_linux_build.sh" ]; then \
echo "$(YELLOW)⚠️ verify_linux_build.sh script not found$(NC)"; \
exit 1; \
fi
@chmod +x src/scripts/verify_linux_build.sh
@./src/scripts/verify_linux_build.sh