-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
237 lines (195 loc) · 7.7 KB
/
Makefile
File metadata and controls
237 lines (195 loc) · 7.7 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
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2025-2026 Rohan R @rotsl
.PHONY: help venv install install-dev \
test test-cov test-integration \
lint lint-fix format type-check \
clean build \
docs docs-serve \
demo examples \
benchmark benchmark-weights benchmark-rag benchmark-api \
benchmark-latency benchmark-tokens benchmark-agent-loops \
benchmark-all \
precompute inspect-cache \
serve-mcp ui cli-help \
docker-build docker-run docker-ui docker-mcp docker-stop \
bootstrap env-example requirements all-checks
# ---------------------------------------------------------------------------
# Python — prefer the project venv when present
# ---------------------------------------------------------------------------
VENV := CFAdvenv
PYTHON := $(shell if [ -x "$(VENV)/bin/python" ]; then echo "$(VENV)/bin/python"; else echo "python3"; fi)
PIP := $(PYTHON) -m pip
PACKAGE_NAME := context_portfolio_optimizer
# Server / UI defaults (override with HOST=… UI_PORT=… MCP_PORT=…)
HOST ?= localhost
UI_PORT ?= 8080
MCP_PORT ?= 8765
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
help:
@echo "CFAdv — Context Portfolio Optimizer"
@echo ""
@echo "Setup"
@echo " venv Create CFAdvenv virtualenv (Python 3.11+)"
@echo " bootstrap Full first-time setup via scripts/bootstrap.sh"
@echo " install Install package with all optional extras"
@echo " install-dev Install package + dev tools + pre-commit hooks"
@echo " env-example Create .env from .env.example (if not present)"
@echo " requirements Sync requirements.txt / requirements-dev.txt"
@echo ""
@echo "Quality"
@echo " test Run full test suite"
@echo " test-cov Run tests with coverage report"
@echo " test-integration Run integration tests only"
@echo " lint Check code with ruff"
@echo " lint-fix Auto-fix ruff warnings"
@echo " format Format code with ruff"
@echo " type-check Static type-check with mypy"
@echo " all-checks format + lint + type-check + test"
@echo ""
@echo "Benchmarks"
@echo " benchmark Tiny eval (baseline vs CF uniform vs CF attention)"
@echo " benchmark-weights Tiny eval with attention weight detail"
@echo " benchmark-rag RAG pipeline benchmark"
@echo " benchmark-api Live Anthropic API benchmark (requires .env)"
@echo " benchmark-latency Pipeline assembly latency"
@echo " benchmark-tokens Token efficiency comparison"
@echo " benchmark-agent-loops Delta fusion agent-loop benchmark"
@echo " benchmark-all Run all local benchmarks"
@echo ""
@echo "Examples / UI"
@echo " demo Run multiformat ingestion demo"
@echo " examples Run all example scripts"
@echo " ui Launch local Web UI (HOST=$(HOST) UI_PORT=$(UI_PORT))"
@echo " serve-mcp Start MCP-style server (HOST=$(HOST) MCP_PORT=$(MCP_PORT))"
@echo " precompute Precompute artifacts for ./data"
@echo " inspect-cache Show cache and precompute store stats"
@echo ""
@echo "Build / Docs"
@echo " build Build sdist + wheel"
@echo " docs Build MkDocs site"
@echo " docs-serve Serve docs locally"
@echo " clean Remove build/test/cache artifacts"
@echo ""
@echo "Docker"
@echo " docker-build Build Docker image (cfadv:latest)"
@echo " docker-run Run image interactively"
@echo " docker-ui Start Web UI via Docker Compose"
@echo " docker-mcp Start MCP server via Docker Compose"
@echo " docker-stop Stop Docker Compose services"
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
venv:
python3 -m venv $(VENV)
@echo "Virtualenv created at $(VENV)/. Run: source $(VENV)/bin/activate"
install:
$(PIP) install -e ".[all]"
install-dev:
$(PIP) install -e ".[all,dev]"
$(VENV)/bin/pre-commit install
env-example:
@if [ ! -f .env ]; then \
cp .env.example .env && echo "Created .env from .env.example"; \
else \
echo ".env already exists — skipping"; \
fi
requirements:
@echo "requirements.txt and requirements-dev.txt are maintained manually."
@echo "To pin current venv state: $(PIP) freeze > requirements-pinned.txt"
bootstrap:
bash scripts/bootstrap.sh
# ---------------------------------------------------------------------------
# Quality
# ---------------------------------------------------------------------------
test:
$(PYTHON) -m pytest tests/ -v
test-cov:
$(PYTHON) -m pytest tests/ -v \
--cov=$(PACKAGE_NAME) \
--cov-report=term-missing \
--cov-report=html:htmlcov
test-integration:
$(PYTHON) -m pytest tests/integration/ -v -m integration
lint:
$(PYTHON) -m ruff check src/ tests/
lint-fix:
$(PYTHON) -m ruff check --fix src/ tests/
format:
$(PYTHON) -m ruff format src/ tests/
type-check:
$(PYTHON) -m mypy src/$(PACKAGE_NAME)
all-checks: format lint type-check test
@echo "All checks passed!"
# ---------------------------------------------------------------------------
# Benchmarks
# ---------------------------------------------------------------------------
benchmark:
$(PYTHON) benchmarks/runners/run_tiny_eval.py
benchmark-weights:
$(PYTHON) benchmarks/runners/run_tiny_eval.py --show-weights
benchmark-rag:
$(PYTHON) benchmarks/runners/run_rag_eval.py
benchmark-api:
$(PYTHON) benchmarks/runners/run_api_eval.py
benchmark-latency:
$(PYTHON) benchmarks/benchmark_latency.py
benchmark-tokens:
$(PYTHON) benchmarks/benchmark_tokens.py
benchmark-agent-loops:
$(PYTHON) benchmarks/benchmark_agent_loops.py
benchmark-all: benchmark benchmark-latency benchmark-tokens benchmark-agent-loops
@echo "All local benchmarks complete."
# ---------------------------------------------------------------------------
# Examples / demos
# ---------------------------------------------------------------------------
demo:
$(PYTHON) examples/multiformat_ingestion_demo.py
examples:
$(PYTHON) examples/multiformat_ingestion_demo.py
$(PYTHON) examples/ablation_demo.py
$(PYTHON) examples/memory_compaction_demo.py
$(PYTHON) examples/rag_context_optimizer.py
# ---------------------------------------------------------------------------
# Pipeline / server
# ---------------------------------------------------------------------------
precompute:
$(PYTHON) -m $(PACKAGE_NAME) precompute ./data
serve-mcp:
$(PYTHON) -m $(PACKAGE_NAME) serve-mcp --host $(HOST) --port $(MCP_PORT)
inspect-cache:
$(PYTHON) -m $(PACKAGE_NAME) inspect-cache
ui:
$(PYTHON) -m $(PACKAGE_NAME) ui --host $(HOST) --port $(UI_PORT)
cli-help:
$(PYTHON) -m $(PACKAGE_NAME) --help
# ---------------------------------------------------------------------------
# Build / docs / clean
# ---------------------------------------------------------------------------
clean:
rm -rf build/ dist/ *.egg-info/
rm -rf .pytest_cache/ .mypy_cache/ .ruff_cache/
rm -rf htmlcov/ .coverage .coverage.*
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
build: clean
$(PYTHON) -m build
docs:
$(VENV)/bin/mkdocs build
docs-serve:
$(VENV)/bin/mkdocs serve
# ---------------------------------------------------------------------------
# Docker
# ---------------------------------------------------------------------------
docker-build:
docker build -t cfadv:latest .
docker-run:
docker run --rm -it cfadv:latest
docker-ui:
docker compose up cpo-ui
docker-mcp:
docker compose up cpo-mcp
docker-stop:
docker compose down