-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (70 loc) · 2.73 KB
/
Copy pathMakefile
File metadata and controls
91 lines (70 loc) · 2.73 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
-include .env
export
SHELL := /bin/bash
VENV := .venv
PYTHON := $(VENV)/bin/python
PYTEST := $(VENV)/bin/pytest
PIP := $(VENV)/bin/pip
PORT ?= 8000
.DEFAULT_GOAL := help
# ===================== INTERNAL HELPER =====================
$(VENV):
@echo "ERROR: Virtual environment not found. Run 'make setup' first" && exit 1
# ===================== MANDATORY TARGETS =====================
help:
@echo "Mandatory targets:"
@echo " make setup — Create venv and install dependencies"
@echo " make test — Run pytest tests"
@echo " make docker-build — Build Docker image"
@echo " make docker-up — Start the service"
@echo " make docker-down — Stop the service"
@echo " make health — Check service health"
@echo " make predict — Make a sample prediction"
@echo ""
@echo "Optional targets:"
@echo " make dev — Run API locally (uvicorn with hot-reload)"
@echo " make docker-test — Run tests inside Docker image"
@echo " make pipeline — Run data pipeline"
@echo " make train — Train model"
@echo " make clean — Clean generated files"
setup:
python3 -m venv $(VENV)
$(PIP) install --upgrade pip
$(PIP) install -r requirements.txt
@echo "Setup complete. Activate with: source $(VENV)/bin/activate"
test: $(VENV)
@test -d tests || (echo "ERROR: tests/ directory not found. Tests are added in Session 11." && exit 1)
$(PYTEST) tests/ -v
docker-test:
docker build -t student-placement-api .
docker run --rm --env-file .env -v $(PWD)/tests:/app/tests student-placement-api pytest tests/ -v
docker-build:
docker compose build
docker-up:
mkdir -p data logs
docker compose up -d
@echo "Service started at http://localhost:$(PORT)"
docker-down:
docker compose down
health:
@set -o pipefail; curl -sf http://localhost:$(PORT)/health | python3 -m json.tool || \
(echo "ERROR: Service not responding at /health" && exit 1)
predict:
@set -o pipefail; curl -sf -X POST http://localhost:$(PORT)/predict \
-H "Content-Type: application/json" \
-d '{"age":21,"gender":1,"degree":0,"branch":3,"cgpa":7.5,"internships":1,"projects":3,"coding_skills":7,"communication_skills":6,"aptitude_test_score":72,"soft_skills_rating":7,"certifications":2,"backlogs":0}' \
| python3 -m json.tool || \
(echo "ERROR: Prediction failed" && exit 1)
# ===================== OPTIONAL TARGETS =====================
dev: $(VENV)
$(VENV)/bin/uvicorn app.api:app --reload --port 8000
pipeline: $(VENV)
$(PYTHON) -m app.pipeline
train: $(VENV)
$(PYTHON) -m app.train
clean:
rm -rf $(VENV) .pytest_cache .mypy_cache
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
rm -f data/*.parquet data/predictions.jsonl
rm -f logs/*.log
@echo "Cleaned"