-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (136 loc) · 6.1 KB
/
Makefile
File metadata and controls
165 lines (136 loc) · 6.1 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
NUM_WORKERS ?= $$(( $(shell nproc --all) / 2))
ARTIFACT_DIR := $(if $(ARTIFACT_DIR),$(ARTIFACT_DIR),tests/test_results)
# Define arguments for pgvector support
POSTGRES_USER ?= postgres
POSTGRES_PASSWORD ?= somesecret
POSTGRES_HOST ?= localhost
POSTGRES_PORT ?= 15432
POSTGRES_DATABASE ?= postgres
# Container image build / output arguments
TOOL_IMAGE ?= localhost/rag-content:latest
DOCS_DIR ?= docs
OUTPUT_DIR ?= output
INDEX_NAME ?= my-index
OUTPUT_IMAGE_NAME ?= rag-content-output
OUTPUT_IMAGE_TAG ?= latest
OUTPUT_IMAGE_FILE ?= $(OUTPUT_DIR)/$(OUTPUT_IMAGE_NAME)-$(OUTPUT_IMAGE_TAG).tar
.PHONY: unit-test
test-unit: ## Run the unit tests
@echo "Running unit tests..."
@echo "Reports will be written to ${ARTIFACT_DIR}"
COVERAGE_FILE="${ARTIFACT_DIR}/.coverage.unit" uv run pytest tests --cov=src/lightspeed_rag_content --cov-report term-missing --cov-report "json:${ARTIFACT_DIR}/coverage_unit.json" --junit-xml="${ARTIFACT_DIR}/junit_unit.xml" --cov-fail-under=60
.PHONY: install-tools
install-tools: ## Install required utilities/tools
@command -v uv > /dev/null || { echo >&2 "uv is not installed. Installing..."; pip3.12 install --upgrade pip uv; }
.PHONY: uv-lock-check
uv-lock-check: ## Check that the uv.lock file is in a good shape
uv lock --check
.PHONY: install-global
install-global: install-tools ## Install ligthspeed-rag-content into file system.
uv pip install --python 3.12 --system .
.PHONY: install-hooks
install-hooks: install-deps-test ## Install commit hooks
uv pip install pre-commit
.PHONY: install-deps
install-deps: install-tools uv-lock-check ## Install all required dependencies, according to uv.lock
uv sync
.PHONY: install-deps-test
install-deps-test: install-tools uv-lock-check ## Install all required dev dependencies, according to uv.lock
uv sync --dev
.PHONY: update-deps
update-deps: ## Check pyproject.toml for changes, update the lock file if needed, then sync.
uv lock --upgrade
uv sync
uv sync --dev
.PHONY: check-types
check-types: ## Check types in the code.
@echo "Running $@ target ..."
uv run mypy --namespace-packages --explicit-package-bases --strict --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs src scripts
.PHONY: check-format
check-format: ## Check that the code is properly formatted using Black and Ruff formatter.
@echo "Running $@ target ..."
uv run black --check scripts src tests
uv run ruff check scripts src
.PHONY: check-coverage
check-coverage: ## Check the coverage of unit tests.
@echo "Running $@ target ..."
uv run coverage run --source=src/lightspeed_rag_content -m pytest tests --verbose && uv run coverage report -m --fail-under 90
.PHONY: check-code-metrics
check-code-metrics: ## Check the code using Radon.
@echo "Running $@ target ..."
@RADON_OUT=$$(uv run radon cc -a src/) && \
echo "$$RADON_OUT" && \
OUTPUT=$$(echo "$$RADON_OUT" | tail -1) && \
GRADE=$$(echo "$$OUTPUT" | awk '/Average complexity:/ { print $$3; exit }') && \
if [ "$$GRADE" = "A" ]; then exit 0; else exit 1; fi
.PHONY: format
format: ## Format the code into unified format
uv run black scripts src tests
uv run ruff check scripts src --fix
uv run pre-commit run --all-files
black:
uv tool run black --check .
.PHONY: pylint
pylint: ## Run pylint on application source.
@echo "Running $@ target ..."
uv run pylint src
ruff:
uv run ruff check src
.PHONY: verify
verify: check-types check-format pylint check-code-metrics check-coverage ## Verify the code using various linters
.PHONY: start-postgres
start-postgres: ## Start postgresql from the pgvector container image
mkdir -pv ./postgresql/data ./output
podman run -d --name pgvector --rm -e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \
-p $(POSTGRES_PORT):5432 \
-v $(PWD)/postgresql/data:/var/lib/postgresql/data:Z pgvector/pgvector:pg16
.PHONY: start-postgres-debug
start-postgres-debug: ## Start postgresql from the pgvector container image with debugging enabled
mkdir -pv ./postgresql/data ./output
podman run --name pgvector --rm -e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \
-p $(POSTGRES_PORT):5432 \
-v ./postgresql/data:/var/lib/postgresql/data:Z pgvector/pgvector:pg16 \
postgres -c log_statement=all -c log_destination=stderr
.PHONY: build-tool-image
build-tool-image: ## Build the rag-content tool image (uses the existing Containerfile)
podman build -t $(TOOL_IMAGE) .
.PHONY: generate-output-image
# skopeo (needed to fetch the base image) is bundled in the tool container but
# not required on the host, so the script is run inside the container.
generate-output-image: build-tool-image ## Run the tool container and produce a vector-DB image archive
mkdir -p "$(OUTPUT_DIR)"
outfile="$$(basename "$(OUTPUT_IMAGE_FILE)")"; \
podman run --rm \
-v "$(abspath $(DOCS_DIR)):/input:ro,Z" \
-v "$(abspath $(OUTPUT_DIR)):/output:Z" \
"$(TOOL_IMAGE)" \
python /rag-content/scripts/generate_embeddings.py \
-f /input \
-o /output/vector_db \
-i "$(INDEX_NAME)" \
--output-image "/output/$$outfile" \
--image-name "$(OUTPUT_IMAGE_NAME)" \
--image-tag "$(OUTPUT_IMAGE_TAG)"
@echo ""
@echo "Image archive written to $(OUTPUT_IMAGE_FILE)"
@echo "Load with: podman load < $(OUTPUT_IMAGE_FILE)"
@echo "Then push: podman push $(OUTPUT_IMAGE_NAME):$(OUTPUT_IMAGE_TAG)"
konflux-requirements: ## generate hermetic requirements.*.txt file and gemfile.lock for konflux build
./scripts/konflux_requirements.sh
bundle _2.2.33_ lock --add-platform aarch64-linux
konflux-requirements-cuda: ## generate hermetic requirements.*.cuda.txt for CUDA konflux build
./scripts/konflux_requirements_cuda.sh
BASE_IMAGE := $(shell grep '^BASE_IMAGE=' build-args-konflux.conf | cut -d= -f2-)
konflux-rpm-lock: ## generate rpm.lock.yaml file for konflux build
./scripts/generate-rpm-lock.sh -i $(BASE_IMAGE)
ruby-bundler: # Install bundler 2.2.33, this is the version used by the container image.
gem install bundler -v 2.2.33
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
@echo ''