@@ -75,19 +75,70 @@ verify-boilerplate: $(TOOLS_DIR)/verify_boilerplate.py
75
75
$(TOOLS_DIR ) /verify_boilerplate.py --boilerplate-dir=hack/boilerplate --skip docs
76
76
77
77
.PHONY : unit-test
78
- unit-test : download-tokenizer download-zmq
78
+ unit-test : download-tokenizer detect-python install-python-deps download-zmq
79
79
@printf " \033[33;1m==== Running unit tests ====\033[0m\n"
80
80
go test -ldflags=" $( LDFLAGS) " ./pkg/...
81
+ @printf " \033[33;1m==== Running chat template tests ====\033[0m\n"
82
+ go test -tags=exclude -v -ldflags=" $( LDFLAGS) " ./pkg/preprocessing/chat_completions_template/
83
+ @printf " \033[33;1m==== Running chat template benchmarks ====\033[0m\n"
84
+ go test -tags=exclude -bench=. -benchmem -ldflags=" $( LDFLAGS) " ./pkg/preprocessing/chat_completions_template/
81
85
82
86
.PHONY : e2e-test
83
- e2e-test : download-tokenizer download-zmq
84
- @printf " \033[33;1m==== Running unit tests ====\033[0m\n"
87
+ e2e-test : download-tokenizer detect-python install-python-deps download-zmq
88
+ @printf " \033[33;1m==== Running e2e tests ====\033[0m\n"
85
89
go test -v -ldflags=" $( LDFLAGS) " ./tests/...
86
90
87
91
# #@ Build
88
92
93
+ # Python detection and build configuration
94
+ PYTHON_VERSION := 3.11.7
95
+ PYTHON_DIR = build/python-$(PYTHON_VERSION )
96
+
97
+ .PHONY : detect-python
98
+ detect-python :
99
+ @printf " \033[33;1m==== Detecting Python installation ====\033[0m\n"
100
+ @if python3 -c " import sys; print(sys.version)" > /dev/null 2>&1 ; then \
101
+ echo " Using system Python" ; \
102
+ PYTHON_PATH=$$(python3 -c "import sys; print(sys.prefix ) " ); \
103
+ PYTHON_VERSION=$$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}' ) " ); \
104
+ sed -i.bak " s|{{PYTHON_PATH}}|$$ PYTHON_PATH|g; s|{{PYTHON_VERSION}}|$$ PYTHON_VERSION|g" \
105
+ pkg/preprocessing/chat_completions_template/cgo_functions.go; \
106
+ rm -f pkg/preprocessing/chat_completions_template/cgo_functions.go.bak; \
107
+ else \
108
+ echo " System Python not found, downloading..." ; \
109
+ $(MAKE ) download-python; \
110
+ fi
111
+
112
+ .PHONY : download-python
113
+ download-python :
114
+ @printf " \033[33;1m==== Downloading Python $( PYTHON_VERSION) ====\033[0m\n"
115
+ @mkdir -p build
116
+ @if [ ! -d " $( PYTHON_DIR) " ]; then \
117
+ if [ " $( TARGETOS) " = " darwin" ]; then \
118
+ curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION ) /python-$(PYTHON_VERSION ) -macos11.pkg -o build/python.pkg; \
119
+ sudo installer -pkg build/python.pkg -target /; \
120
+ elif [ " $( TARGETOS) " = " linux" ]; then \
121
+ curl -L https://www.python.org/ftp/python/$(PYTHON_VERSION ) /Python-$(PYTHON_VERSION ) .tgz -o build/python.tgz; \
122
+ tar -xzf build/python.tgz -C build/; \
123
+ cd build/Python-$(PYTHON_VERSION ) && ./configure --prefix=$(PWD ) /$(PYTHON_DIR ) && make && make install; \
124
+ fi ; \
125
+ fi
126
+ @# Update CGo flags with downloaded Python path
127
+ @sed -i.bak " s|{{PYTHON_PATH}}|$( PWD) /$( PYTHON_DIR) |g; s|{{PYTHON_VERSION}}|$( PYTHON_VERSION) |g" \
128
+ pkg/preprocessing/chat_completions_template/cgo_functions.go
129
+ @rm -f pkg/preprocessing/chat_completions_template/cgo_functions.go.bak
130
+
131
+ .PHONY : install-python-deps
132
+ install-python-deps : detect-python
133
+ @printf " \033[33;1m==== Installing Python dependencies ====\033[0m\n"
134
+ @if [ -d " $( PYTHON_DIR) " ]; then \
135
+ $(PYTHON_DIR ) /bin/pip install -r pkg/preprocessing/chat_completions_template/requirements.txt; \
136
+ else \
137
+ python3 -m pip install -r pkg/preprocessing/chat_completions_template/requirements.txt; \
138
+ fi
139
+
89
140
.PHONY : build
90
- build : check-go download-tokenizer download-zmq
141
+ build : check-go download-tokenizer detect-python install-python-deps download-zmq
91
142
@printf " \033[33;1m==== Building ====\033[0m\n"
92
143
go build -ldflags=" $( LDFLAGS) " -o bin/$(PROJECT_NAME ) examples/kv_cache_index/main.go
93
144
@@ -351,6 +402,14 @@ print-namespace: ## Print the current namespace
351
402
print-project-name : # # Print the current project name
352
403
@echo " $( PROJECT_NAME) "
353
404
405
+ .PHONY : clean
406
+ clean : # # Clean build artifacts and restore placeholders
407
+ @printf " \033[33;1m==== Cleaning build artifacts ====\033[0m\n"
408
+ @rm -rf build/
409
+ @# Restore original placeholders
410
+ @git checkout pkg/preprocessing/chat_completions_template/cgo_functions.go
411
+ @echo " ✅ Build artifacts cleaned and placeholders restored"
412
+
354
413
.PHONY : install-hooks
355
414
install-hooks : # # Install git hooks
356
415
git config core.hooksPath hooks
0 commit comments