forked from vdaas/vald-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·213 lines (175 loc) · 5.67 KB
/
Makefile
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
#
# Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
REPO ?= vdaas
NAME = vald
VALDREPO = github.com/$(REPO)/$(NAME)
LANGUAGE = python
PKGNAME = $(NAME)-client-$(LANGUAGE)
PKGREPO = github.com/$(REPO)/$(PKGNAME)
PYTHON = python3
PIP = pip3
VALD_DIR = vald-origin
VALD_SHA = VALD_SHA
VALD_CLIENT_PYTHON_VERSION = VALD_CLIENT_PYTHON_VERSION
VALD_CHECKOUT_REF ?= main
K3D_MAKEFILE_URL=https://raw.githubusercontent.com/vdaas/vald/main/Makefile.d/k3d.mk
K3D_MAKEFILE=Makefile.d/k3d.mk
BINDIR ?= /usr/local/bin
PROTO_ROOT = $(VALD_DIR)/apis/proto
PB2DIR_ROOT = src
BUF_VERSION_URL := https://raw.githubusercontent.com/vdaas/vald/main/versions/BUF_VERSION
SHADOW_ROOT = vald
SHADOW_PROTO_ROOT = $(SHADOW_ROOT)/$(SHADOW_ROOT)
PROTOS = \
v1/agent/core/agent.proto \
v1/filter/egress/egress_filter.proto \
v1/filter/ingress/ingress_filter.proto \
v1/vald/filter.proto \
v1/vald/insert.proto \
v1/vald/object.proto \
v1/vald/index.proto \
v1/vald/remove.proto \
v1/vald/search.proto \
v1/vald/update.proto \
v1/vald/upsert.proto \
v1/payload/payload.proto
PROTOS := $(PROTOS:%=$(PROTO_ROOT)/%)
SHADOWS = $(PROTOS:$(PROTO_ROOT)/%.proto=$(SHADOW_PROTO_ROOT)/%.proto)
PB2PYS = $(PROTOS:$(PROTO_ROOT)/%.proto=$(PB2DIR_ROOT)/$(SHADOW_ROOT)/%_pb2.py)
MAKELISTS = Makefile
PYTHON_VERSION := $(eval PYTHON_VERSION := $(shell cat PYTHON_VERSION))$(PYTHON_VERSION)
TEST_DATASET_PATH = wordvecs1000.json
red = /bin/echo -e "\x1b[31m\#\# $1\x1b[0m"
green = /bin/echo -e "\x1b[32m\#\# $1\x1b[0m"
yellow = /bin/echo -e "\x1b[33m\#\# $1\x1b[0m"
blue = /bin/echo -e "\x1b[34m\#\# $1\x1b[0m"
pink = /bin/echo -e "\x1b[35m\#\# $1\x1b[0m"
cyan = /bin/echo -e "\x1b[36m\#\# $1\x1b[0m"
.PHONY: all
## execute clean and proto
all: clean proto
.PHONY: help
## print all available commands
help:
@awk '/^[a-zA-Z_0-9%:\\\/-]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKELISTS) | sort -u
@printf "\n"
.PHONY: clean
## clean
clean:
rm -rf $(PB2DIR_ROOT)/google $(PB2DIR_ROOT)/vald $(PB2DIR_ROOT)/buf
rm -rf $(SHADOW_ROOT)
rm -rf $(VALD_DIR)
.PHONY: proto
## build proto
proto: $(PB2PYS)
@$(call green, "generating pb2.py files...")
buf generate --include-imports
$(PROTOS): $(VALD_DIR)
$(SHADOWS): $(PROTOS)
$(SHADOW_PROTO_ROOT)/%.proto: $(PROTO_ROOT)/%.proto
mkdir -p $(dir $@)
cp $< $@
sed -i -e 's:^import "v1:import "$(SHADOW_ROOT)/v1:' $@
$(PB2DIR_ROOT):
mkdir -p $@
$(PB2PYS): proto/deps/install $(PB2DIR_ROOT) $(SHADOWS)
$(VALD_DIR):
git clone https://$(VALDREPO) $(VALD_DIR)
## checkout vald repository
vald/checkout: $(VALD_DIR)
cd $(VALD_DIR) && git checkout $(VALD_CHECKOUT_REF)
.PHONY: vald/origin/sha/print
## print origin VALD_SHA value
vald/origin/sha/print: $(VALD_DIR)
@cd $(VALD_DIR) && git rev-parse HEAD | tr -d '\n'
.PHONY: vald/sha/print
## print VALD_SHA value
vald/sha/print:
@cat $(VALD_SHA)
.PHONY: vald/sha/update
## update VALD_SHA value
vald/sha/update: $(VALD_DIR)
(cd $(VALD_DIR); git rev-parse HEAD | tr -d '\n' > ../$(VALD_SHA))
.PHONY: vald/client/version/print
## print VALD_CLIENT_PYTHON_VERSION value
vald/client/version/print:
@cat $(VALD_CLIENT_PYTHON_VERSION)
.PHONY: vald/client/version/update
## update VALD_CLIENT_PYTHON_VERSION value
vald/client/version/update: $(VALD_DIR)
(vald_version=`cat $(VALD_DIR)/versions/VALD_VERSION | sed -e 's/^v//'`; \
echo "VALD_VERSION: $${vald_version}"; \
echo "$${vald_version}" > VALD_CLIENT_PYTHON_VERSION)
sed -i -e "s/^version = .*\$$/version = `cat VALD_CLIENT_PYTHON_VERSION`/" setup.cfg
.PHONY: test
## Execute test
test: $(TEST_DATASET_PATH)
$(PYTHON) src/test.py
$(TEST_DATASET_PATH):
curl -L https://raw.githubusercontent.com/rinx/word2vecjson/master/data/wordvecs1000.json -o $(TEST_DATASET_PATH)
.PHONY: ci/deps/install
## install deps for CI environment
ci/deps/install: proto/deps/install
apt-get update -y && apt-get install -y \
python3-setuptools \
libprotobuf-dev \
libprotoc-dev \
protobuf-compiler
$(PYTHON) -m pip install \
grpcio \
protobuf \
wheel
.PHONY: ci/deps/update
## update deps for CI environment
ci/deps/update: sync/k3d/mk
.PHONY: ci/package/prepare
## prepare package to publish
ci/package/prepare:
$(PYTHON) setup.py sdist
$(PYTHON) setup.py bdist_wheel
.PHONY: ci/package/publish
## publich packages
ci/package/publish:
@echo "Nothing to do"
.PHONY: proto/deps/install
## install proto deps
proto/deps/install: $(BINDIR)/buf
$(BINDIR)/buf:
@version=$$(curl -sSL $(BUF_VERSION_URL)); \
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/$$version/buf-$(shell uname -s)-$(shell uname -m)" \
-o "${BINDIR}/buf" && \
chmod +x "${BINDIR}/buf"
.PHONY: version/python
## Print Python version
version/python:
@echo $(PYTHON_VERSION)
Makefile.d:
mkdir -p Makefile.d
sync/k3d/mk: Makefile.d
rm -rf $(K3D_MAKEFILE)
curl -fsSLo $(K3D_MAKEFILE) $(K3D_MAKEFILE_URL)
include $(K3D_MAKEFILE)