Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use 'grpcio-tools' in a virtualenv to generate from latest datastore …
…V1beta3 protos.

This is a better hack for #1482, but we still really want #1384.
  • Loading branch information
tseaver committed Jun 28, 2016
commit 568a463060ec34ba7fa6372a6f465d055cbc4b12
10 changes: 7 additions & 3 deletions Makefile.datastore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GRPCIO_VIRTUALENV=$(shell pwd)/grpc_python_venv
GENERATED_DIR=$(shell pwd)/generated_python
DATASTORE_DIR=$(shell pwd)/gcloud/datastore/_generated
GRPC_PLUGIN=grpc_python_plugin
PROTOC_CMD=protoc
PROTOC_CMD=$(GRPCIO_VIRTUALENV)/bin/python -m grpc.tools.protoc
GOOGLEAPIS_PROTOS_DIR=$(shell pwd)/googleapis-pb

help:
Expand All @@ -12,6 +12,9 @@ help:
@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/google/googleapis googleapis-pb --depth=1
cd googleapis-pb && git pull origin master
Expand Down Expand Up @@ -39,7 +42,8 @@ generate:
done
# Separate the gRPC parts of the datastore service from the
# non-gRPC parts so that the protos can be used without gRPC.
PROTOC_CMD=$(PROTOC_CMD) GRPC_PLUGIN=$(GRPC_PLUGIN) \
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
Expand Down
15 changes: 8 additions & 7 deletions scripts/make_datastore_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
'v1beta3', 'datastore.proto')
GRPC_ONLY_FILE = os.path.join(ROOT_DIR, 'gcloud', 'datastore',
'_generated', 'datastore_grpc_pb2.py')
PROTOC_CMD = os.environ.get('PROTOC_CMD', 'protoc')
GRPC_PLUGIN = os.environ.get('GRPC_PLUGIN', 'grpc_python_plugin')
GRPCIO_VIRTUALENV = os.environ.get('GRPCIO_VIRTUALENV', 'protoc')


def get_pb2_contents_with_grpc():
Expand All @@ -43,14 +42,14 @@ def get_pb2_contents_with_grpc():
'v1beta3', 'datastore_pb2.py')
try:
return_code = subprocess.call([
PROTOC_CMD,
'%s/bin/python' % GRPCIO_VIRTUALENV,
'-m',
'grpc.tools.protoc',
'--proto_path',
PROTOS_DIR,
'--python_out',
temp_dir,
'--plugin',
'protoc-gen-grpc=' + GRPC_PLUGIN,
'--grpc_out',
'--grpc_python_out',
temp_dir,
PROTO_PATH,
])
Expand All @@ -73,7 +72,9 @@ def get_pb2_contents_without_grpc():
'v1beta3', 'datastore_pb2.py')
try:
return_code = subprocess.call([
PROTOC_CMD,
'%s/bin/python' % GRPCIO_VIRTUALENV,
'-m',
'grpc.tools.protoc',
'--proto_path',
PROTOS_DIR,
'--python_out',
Expand Down