forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.datastore
53 lines (49 loc) · 2.32 KB
/
Makefile.datastore
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
GRPCIO_VIRTUALENV=$(shell pwd)/grpc_python_venv
GENERATED_DIR=$(shell pwd)/generated_python
DATASTORE_DIR=$(shell pwd)/datastore/google/cloud/datastore/_generated
PROTOC_CMD=$(GRPCIO_VIRTUALENV)/bin/python -m grpc.tools.protoc
GOOGLEAPIS_PROTOS_DIR=$(shell pwd)/googleapis-pb
help:
@echo 'Makefile for google-cloud-python Datastore protos '
@echo ' '
@echo ' make generate Generates the protobuf modules'
@echo ' make clean Clean generated files '
generate:
# Ensure we have a virtualenv w/ up-to-date grpcio/grpcio-tools
[ -d $(GRPCIO_VIRTUALENV) ] || python2.7 -m virtualenv $(GRPCIO_VIRTUALENV)
$(GRPCIO_VIRTUALENV)/bin/pip install --upgrade grpcio grpcio-tools
# Retrieve git repos that have our *.proto files.
[ -d googleapis-pb ] || git clone https://github.com/googleapis/googleapis googleapis-pb --depth=1
cd googleapis-pb && git pull origin master
# Make the directory where our *_pb2.py files will go.
mkdir -p $(GENERATED_DIR)
# Generate all *_pb2.py files that do not require gRPC.
$(PROTOC_CMD) \
--proto_path=$(GOOGLEAPIS_PROTOS_DIR) \
--python_out=$(GENERATED_DIR) \
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1/datastore.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1/entity.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1/query.proto
# Move the newly generated *_pb2.py files into our library.
cp $(GENERATED_DIR)/google/datastore/v1/* $(DATASTORE_DIR)
# Remove all existing *.proto files before we replace
rm -f $(DATASTORE_DIR)/*.proto
# Copy over the *.proto files into our library.
cp $(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1/*.proto $(DATASTORE_DIR)
# Rename all *.proto files in our library with an
# underscore and remove executable bit.
cd $(DATASTORE_DIR) && \
for filename in *.proto; do \
chmod -x $$filename ; \
mv $$filename _$$filename ; \
done
# Separate the gRPC parts of the datastore service from the
# non-gRPC parts so that the protos can be used without gRPC.
GRPCIO_VIRTUALENV="$(GRPCIO_VIRTUALENV)" \
GENERATED_SUBDIR=$(GENERATED_SUBDIR) \
python scripts/make_datastore_grpc.py
# Rewrite the imports in the generated *_pb2.py files.
python scripts/rewrite_imports.py $(DATASTORE_DIR)/*pb2.py
clean:
rm -fr $(GENERATED_DIR)
.PHONY: generate clean