-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (105 loc) · 4.09 KB
/
Copy pathMakefile
File metadata and controls
139 lines (105 loc) · 4.09 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
# Every gate CI runs is reachable from here with the same command, so "it passed locally"
# and "it passed in CI" mean the same thing.
.DEFAULT_GOAL := help
SHELL := /bin/bash
VENV := .venv
PY := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
WEB := apps/web
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
# ------------------------------------------------------------------------------ setup
$(VENV):
python3.12 -m venv $(VENV)
$(PIP) install --upgrade pip setuptools wheel
.PHONY: install
install: $(VENV) ## Install the backend with every extra, and the frontend
$(PIP) install -e ".[dev,pdf,office,evals]"
cd $(WEB) && npm ci
.PHONY: dev
dev: install migrate ## Install and bring the schema up to date
@echo "ready: run 'make api' and 'make worker' and 'make web'"
.PHONY: env
env: ## Create .env from the example if it does not exist
@test -f .env || (cp .env.example .env && echo "wrote .env")
# ------------------------------------------------------------------------------ run
.PHONY: api
api: ## Run the API with reload
$(VENV)/bin/uvicorn contextforge.api.main:app --reload --port 8000
.PHONY: worker
worker: ## Run a Celery worker on both queues
$(VENV)/bin/celery --app=contextforge.worker.celery_app:celery_app worker \
--queues=ingest,maintenance --concurrency=2 --loglevel=INFO
.PHONY: web
web: ## Run the Next.js dev server
cd $(WEB) && npm run dev
.PHONY: up
up: ## The whole system in containers
docker compose up --build
.PHONY: down
down: ## Stop the containers and delete their volumes
docker compose down --volumes
# ------------------------------------------------------------------------- database
.PHONY: migrate
migrate: ## Apply migrations
$(VENV)/bin/alembic upgrade head
.PHONY: revision
revision: ## Autogenerate a migration: make revision m="what changed"
$(VENV)/bin/alembic revision --autogenerate -m "$(m)"
.PHONY: index
index: ## Rebuild the vector index to match VECTOR_INDEX
$(PY) -m contextforge.cli db index --apply
# ---------------------------------------------------------------------------- gates
.PHONY: lint
lint: ## ruff check and format check
$(VENV)/bin/ruff check .
$(VENV)/bin/ruff format --check .
.PHONY: format
format: ## Apply formatting
$(VENV)/bin/ruff format .
$(VENV)/bin/ruff check --fix .
.PHONY: typecheck
typecheck: ## mypy
$(VENV)/bin/mypy
.PHONY: test
test: ## The whole Python suite (warnings are errors)
$(VENV)/bin/pytest -q
.PHONY: test-unit
test-unit: ## Unit tests only, no database needed
$(VENV)/bin/pytest -q tests/unit
.PHONY: coverage
coverage: ## Tests with a coverage report
$(VENV)/bin/pytest -q --cov=services/contextforge --cov-report=term-missing:skip-covered
.PHONY: web-check
web-check: ## Frontend lint, types, tests and build
cd $(WEB) && npm run lint && npm run typecheck && npm run test && npm run build
.PHONY: openapi
openapi: ## Regenerate openapi.json and the frontend's types from it
$(PY) scripts/export_openapi.py --output openapi.json
cd $(WEB) && npm run generate:api -- --input ../../openapi.json
.PHONY: report
report: ## Regenerate every published figure from evals/results
$(PY) -m evals.report
.PHONY: check-generated
check-generated: ## Fail when a document disagrees with evals/results
$(PY) -m evals.report --check
.PHONY: check
check: lint typecheck test check-generated web-check ## Everything CI runs
# ----------------------------------------------------------------------- evaluation
.PHONY: corpus
corpus: ## Download and verify the evaluation corpus
$(PY) -m evals.fetch
.PHONY: evals
evals: corpus ## Retrieval and generation harnesses on the held-out split, then the documents
$(PY) -m evals.retrieval.run --split test --rebuild
$(PY) -m evals.generation.run --split test
$(PY) -m evals.report
.PHONY: smoke
smoke: ## End-to-end smoke test against a running stack
$(PY) scripts/smoke.py --api http://127.0.0.1:8000
.PHONY: clean
clean: ## Remove caches and build output
find . -name __pycache__ -type d -prune -exec rm -rf {} +
rm -rf .pytest_cache .mypy_cache .ruff_cache $(WEB)/.next