Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (121 loc) · 4.33 KB
/
Copy pathMakefile
File metadata and controls
154 lines (121 loc) · 4.33 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
# =============================================================================
# OpenMRS AI Query Agent — development tasks
#
# `make check` runs exactly what CI runs, so a green local check means a green
# pipeline. Every target works on Linux, macOS and Windows (Git Bash).
# =============================================================================
.DEFAULT_GOAL := help
SHELL := /bin/bash
# Windows virtualenvs put executables in Scripts/, POSIX in bin/.
ifeq ($(OS),Windows_NT)
VENV_BIN := .venv/Scripts
PYTHON := python
else
VENV_BIN := .venv/bin
PYTHON := python3
endif
PY := $(VENV_BIN)/python
PIP := $(PY) -m pip
PYTEST := $(PY) -m pytest
RUFF := $(PY) -m ruff
MYPY := $(PY) -m mypy
COMPOSE := docker compose
IMAGE := openmrs-query-agent
TAG ?= dev
.PHONY: help
help: ## Show this help
@echo "OpenMRS AI Query Agent"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
# --- Setup -------------------------------------------------------------------
.PHONY: install
install: ## Create the virtualenv and install with dev extras
$(PYTHON) -m venv .venv
$(PIP) install --upgrade pip
$(PIP) install -e ".[dev]"
@echo ""
@echo "Done. Activate with: source $(VENV_BIN)/activate"
.PHONY: install-all
install-all: ## Install every optional extra (ai, rag, mcp, auth, reporting)
$(PIP) install -e ".[dev,ai,rag,mcp,auth,reporting]"
.PHONY: env
env: ## Create .env from the template if it does not exist
@if [ -f .env ]; then \
echo ".env already exists; leaving it alone."; \
else \
cp .env.example .env && echo "Created .env — set OQA_DB__PASSWORD before starting."; \
fi
# --- Quality gates -----------------------------------------------------------
.PHONY: lint
lint: ## Lint and check formatting
$(RUFF) check src tests
$(RUFF) format --check src tests
.PHONY: format
format: ## Apply formatting and safe autofixes
$(RUFF) check --fix src tests
$(RUFF) format src tests
.PHONY: typecheck
typecheck: ## Run mypy in strict mode
$(MYPY)
.PHONY: test
test: ## Run unit tests
$(PYTEST) tests/unit -m "not integration and not e2e"
.PHONY: test-all
test-all: ## Run every test, including those needing Docker services
$(PYTEST) tests
.PHONY: coverage
coverage: ## Run unit tests with a coverage report
$(PYTEST) tests/unit --cov --cov-report=term-missing --cov-report=html
@echo "HTML report: htmlcov/index.html"
.PHONY: check
check: lint typecheck test ## Everything CI runs
@echo ""
@echo "All quality gates passed."
# --- Application -------------------------------------------------------------
.PHONY: run
run: ## Run the API with autoreload
$(VENV_BIN)/oqa serve --reload
.PHONY: config-check
config-check: ## Validate the current .env
$(VENV_BIN)/oqa config check
# --- Docker ------------------------------------------------------------------
.PHONY: build
build: ## Build the production image
docker build -t $(IMAGE):$(TAG) .
.PHONY: up
up: ## Start Qdrant, Redis and the API
$(COMPOSE) up -d --build
.PHONY: up-ai
up-ai: ## Also start a local Ollama runtime
$(COMPOSE) --profile ai up -d
.PHONY: up-demo
up-demo: ## Also start a reference OpenMRS to query (first boot takes minutes)
$(COMPOSE) --profile demo up -d
@echo "OpenMRS is initialising. Follow it with: make logs-openmrs"
.PHONY: up-obs
up-obs: ## Also start Prometheus, Grafana and Loki
$(COMPOSE) --profile obs up -d
.PHONY: down
down: ## Stop all services
$(COMPOSE) --profile ai --profile demo --profile obs down
.PHONY: clean-volumes
clean-volumes: ## Stop services and DELETE all data volumes
@echo "This deletes the vector index, cache and demo database."
@read -p "Type 'yes' to continue: " confirm && [ "$$confirm" = "yes" ]
$(COMPOSE) --profile ai --profile demo --profile obs down -v
.PHONY: logs
logs: ## Tail API logs
$(COMPOSE) logs -f api
.PHONY: logs-openmrs
logs-openmrs: ## Tail the reference OpenMRS logs
$(COMPOSE) logs -f openmrs
.PHONY: ps
ps: ## Show service status
$(COMPOSE) ps
# --- Housekeeping ------------------------------------------------------------
.PHONY: clean
clean: ## Remove caches and build artefacts
rm -rf build dist *.egg-info src/*.egg-info
rm -rf .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage coverage.xml
find . -type d -name __pycache__ -not -path "./.venv/*" -exec rm -rf {} + 2>/dev/null || true