-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (80 loc) · 3.16 KB
/
Copy pathMakefile
File metadata and controls
92 lines (80 loc) · 3.16 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
SHELL := /bin/zsh
.DEFAULT_GOAL := help
UVICORN ?= .venv/bin/uvicorn
BACKEND_CMD := $(UVICORN) backend.main:app --reload --port 8000
FRONTEND_CMD := cd frontend && npm run predev && npm run dev
.PHONY: help init install backend frontend dev stop clean test-fe test-be
help:
@echo "Available targets:"
@echo " init - Create .venv, ensure uv is installed, install backend deps via uv, and frontend deps"
@echo " install - Install backend (pip) and frontend (npm) dependencies"
@echo " backend - Start FastAPI backend (uvicorn) on http://localhost:8000"
@echo " frontend - Start Vite frontend on http://localhost:5173"
@echo " dev - Start backend and frontend together; Ctrl+C to stop both"
@echo " test-fe - Run frontend unit tests (Vitest)"
@echo " test-be - Run backend unit tests (pytest)"
@echo " stop - Stop backgrounded dev processes (if any)"
@echo " clean - Remove pid files"
# Initialize Python venv, install uv in venv via pip if needed, install backend with uv, and frontend deps
init:
@echo "Initializing dev environment..."
@if [ ! -d .venv ]; then \
echo "Creating Python virtual environment (.venv)"; \
python3 -m venv .venv; \
else \
echo "Virtual environment already exists (.venv)"; \
fi
@echo "Ensuring uv is installed in the venv"
@if [ ! -x .venv/bin/uv ]; then \
echo "Installing uv into .venv via pip"; \
.venv/bin/python -m pip install --upgrade pip; \
.venv/bin/python -m pip install uv; \
else \
echo "uv already present in .venv"; \
fi
@echo "uv version:" && .venv/bin/uv --version || true
@echo "Installing Python dependencies with uv (in venv)"
@.venv/bin/uv pip install -r backend/requirements.txt
@echo "Installing frontend dependencies (npm install)"
@cd frontend && npm install
@echo "Done. Activate venv with: source .venv/bin/activate"
install:
pip install -r backend/requirements.txt
cd frontend && npm install
backend:
$(BACKEND_CMD)
frontend:
$(FRONTEND_CMD)
test-fe:
cd frontend && npm run test
test-be:
@export PYTHONPATH=$(PWD); \
if [ -x .venv/bin/pytest ]; then \
PYTHONPATH=$(PWD) .venv/bin/pytest -q backend; \
else \
PYTHONPATH=$(PWD) pytest -q backend; \
fi
# Runs backend and frontend concurrently. Press Ctrl+C to stop both.
# Uses pid files (.backend.pid, .frontend.pid) to ensure both are terminated.
dev:
@echo "Starting backend and frontend..."
@set -e; \
trap 'echo; echo "Shutting down..."; \
test -f .backend.pid && kill $$(cat .backend.pid) 2>/dev/null || true; \
test -f .frontend.pid && kill $$(cat .frontend.pid) 2>/dev/null || true; \
rm -f .backend.pid .frontend.pid' INT TERM EXIT; \
( $(BACKEND_CMD) & echo $$! > .backend.pid ); \
( $(FRONTEND_CMD) & echo $$! > .frontend.pid ); \
echo "Backend: http://localhost:8000"; \
echo "Frontend: http://localhost:5173"; \
wait
# Try to stop any processes started by `make dev`.
stop:
@echo "Stopping dev processes (if running)..."
@test -f .backend.pid && kill $$(cat .backend.pid) 2>/dev/null || true
@test -f .frontend.pid && kill $$(cat .frontend.pid) 2>/dev/null || true
@rm -f .backend.pid .frontend.pid
@echo "Stopped."
clean:
@rm -f .backend.pid .frontend.pid
@echo "Cleaned pid files."