Skip to content

Commit dbee5b2

Browse files
committed
Using more descriptive shell var names in Makefile.
Also using subprocess.call instead of check_output in the scripts that split up gRPC from non-gRPC parts of generated modules. This is because check_output swallows standard error and throws a less useful exception.
1 parent e586d2d commit dbee5b2

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

Makefile

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
GENERATED_DIR=$(shell pwd)/generated_python
2-
BT_DIR=$(shell pwd)/gcloud/bigtable/_generated
3-
DS_DIR=$(shell pwd)/gcloud/datastore/_generated
2+
BIGTABLE_DIR=$(shell pwd)/gcloud/bigtable/_generated
3+
DATASTORE_DIR=$(shell pwd)/gcloud/datastore/_generated
44
GRPC_PLUGIN=grpc_python_plugin
55
PROTOC_CMD=protoc
6-
BT_PROTOS_DIR=$(shell pwd)/cloud-bigtable-client/bigtable-protos/src/main/proto
7-
DS_PROTOS_DIR=$(shell pwd)/googleapis-pb
6+
BIGTABLE_PROTOS_DIR=$(shell pwd)/cloud-bigtable-client/bigtable-protos/src/main/proto
7+
GOOGLEAPIS_PROTOS_DIR=$(shell pwd)/googleapis-pb
88

99
help:
1010
@echo 'Makefile for gcloud-python Bigtable protos '
@@ -23,49 +23,49 @@ generate:
2323
mkdir -p $(GENERATED_DIR)
2424
# Generate all *_pb2.py files that require gRPC.
2525
$(PROTOC_CMD) \
26-
--proto_path=$(BT_PROTOS_DIR) \
26+
--proto_path=$(BIGTABLE_PROTOS_DIR) \
2727
--python_out=$(GENERATED_DIR) \
2828
--plugin=protoc-gen-grpc=$(GRPC_PLUGIN) \
2929
--grpc_out=$(GENERATED_DIR) \
30-
$(BT_PROTOS_DIR)/google/bigtable/v1/bigtable_service.proto \
31-
$(BT_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_service.proto \
32-
$(BT_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_service.proto
30+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/v1/bigtable_service.proto \
31+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_service.proto \
32+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_service.proto
3333
# Generate all *_pb2.py files that do not require gRPC.
3434
$(PROTOC_CMD) \
35-
--proto_path=$(BT_PROTOS_DIR) \
36-
--proto_path=$(DS_PROTOS_DIR) \
35+
--proto_path=$(BIGTABLE_PROTOS_DIR) \
36+
--proto_path=$(GOOGLEAPIS_PROTOS_DIR) \
3737
--python_out=$(GENERATED_DIR) \
38-
$(BT_PROTOS_DIR)/google/bigtable/v1/bigtable_data.proto \
39-
$(BT_PROTOS_DIR)/google/bigtable/v1/bigtable_service_messages.proto \
40-
$(BT_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_data.proto \
41-
$(BT_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_service_messages.proto \
42-
$(BT_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_data.proto \
43-
$(BT_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_service_messages.proto \
44-
$(DS_PROTOS_DIR)/google/datastore/v1beta3/datastore.proto \
45-
$(DS_PROTOS_DIR)/google/datastore/v1beta3/entity.proto \
46-
$(DS_PROTOS_DIR)/google/datastore/v1beta3/query.proto
38+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/v1/bigtable_data.proto \
39+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/v1/bigtable_service_messages.proto \
40+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_data.proto \
41+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/cluster/v1/bigtable_cluster_service_messages.proto \
42+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_data.proto \
43+
$(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/table/v1/bigtable_table_service_messages.proto \
44+
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1beta3/datastore.proto \
45+
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1beta3/entity.proto \
46+
$(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1beta3/query.proto
4747
# Move the newly generated *_pb2.py files into our library.
48-
mv $(GENERATED_DIR)/google/bigtable/v1/* $(BT_DIR)
49-
mv $(GENERATED_DIR)/google/bigtable/admin/cluster/v1/* $(BT_DIR)
50-
mv $(GENERATED_DIR)/google/bigtable/admin/table/v1/* $(BT_DIR)
51-
mv $(GENERATED_DIR)/google/datastore/v1beta3/* $(DS_DIR)
48+
mv $(GENERATED_DIR)/google/bigtable/v1/* $(BIGTABLE_DIR)
49+
mv $(GENERATED_DIR)/google/bigtable/admin/cluster/v1/* $(BIGTABLE_DIR)
50+
mv $(GENERATED_DIR)/google/bigtable/admin/table/v1/* $(BIGTABLE_DIR)
51+
mv $(GENERATED_DIR)/google/datastore/v1beta3/* $(DATASTORE_DIR)
5252
# Remove all existing *.proto files before we replace
53-
rm -f $(BT_DIR)/*.proto
54-
rm -f $(DS_DIR)/*.proto
53+
rm -f $(BIGTABLE_DIR)/*.proto
54+
rm -f $(DATASTORE_DIR)/*.proto
5555
# Copy over the *.proto files into our library.
56-
cp $(BT_PROTOS_DIR)/google/bigtable/v1/*.proto $(BT_DIR)
57-
cp $(BT_PROTOS_DIR)/google/bigtable/admin/cluster/v1/*.proto $(BT_DIR)
58-
cp $(BT_PROTOS_DIR)/google/bigtable/admin/table/v1/*.proto $(BT_DIR)
59-
cp $(BT_PROTOS_DIR)/google/longrunning/operations.proto $(BT_DIR)
60-
cp $(DS_PROTOS_DIR)/google/datastore/v1beta3/*.proto $(DS_DIR)
56+
cp $(BIGTABLE_PROTOS_DIR)/google/bigtable/v1/*.proto $(BIGTABLE_DIR)
57+
cp $(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/cluster/v1/*.proto $(BIGTABLE_DIR)
58+
cp $(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/table/v1/*.proto $(BIGTABLE_DIR)
59+
cp $(BIGTABLE_PROTOS_DIR)/google/longrunning/operations.proto $(BIGTABLE_DIR)
60+
cp $(GOOGLEAPIS_PROTOS_DIR)/google/datastore/v1beta3/*.proto $(DATASTORE_DIR)
6161
# Rename all *.proto files in our library with an
6262
# underscore and remove executable bit.
63-
cd $(BT_DIR) && \
63+
cd $(BIGTABLE_DIR) && \
6464
for filename in *.proto; do \
6565
chmod -x $$filename ; \
6666
mv $$filename _$$filename ; \
6767
done
68-
cd $(DS_DIR) && \
68+
cd $(DATASTORE_DIR) && \
6969
for filename in *.proto; do \
7070
chmod -x $$filename ; \
7171
mv $$filename _$$filename ; \

scripts/make_datastore_grpc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import shutil
1919
import subprocess
20+
import sys
2021
import tempfile
2122

2223

@@ -41,7 +42,7 @@ def get_pb2_contents_with_grpc():
4142
generated_path = os.path.join(temp_dir, 'google', 'datastore',
4243
'v1beta3', 'datastore_pb2.py')
4344
try:
44-
subprocess.check_output([
45+
return_code = subprocess.call([
4546
PROTOC_CMD,
4647
'--proto_path',
4748
PROTOS_DIR,
@@ -53,6 +54,8 @@ def get_pb2_contents_with_grpc():
5354
temp_dir,
5455
PROTO_PATH,
5556
])
57+
if return_code != 0:
58+
sys.exit(return_code)
5659
with open(generated_path, 'rb') as file_obj:
5760
return file_obj.readlines()
5861
finally:
@@ -69,14 +72,16 @@ def get_pb2_contents_without_grpc():
6972
generated_path = os.path.join(temp_dir, 'google', 'datastore',
7073
'v1beta3', 'datastore_pb2.py')
7174
try:
72-
subprocess.check_output([
75+
return_code = subprocess.call([
7376
PROTOC_CMD,
7477
'--proto_path',
7578
PROTOS_DIR,
7679
'--python_out',
7780
temp_dir,
7881
PROTO_PATH,
7982
])
83+
if return_code != 0:
84+
sys.exit(return_code)
8085
with open(generated_path, 'rb') as file_obj:
8186
return file_obj.readlines()
8287
finally:

scripts/make_operations_grpc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import shutil
1919
import subprocess
20+
import sys
2021
import tempfile
2122

2223

@@ -42,7 +43,7 @@ def get_pb2_contents_with_grpc():
4243
generated_path = os.path.join(temp_dir, 'google', 'longrunning',
4344
'operations_pb2.py')
4445
try:
45-
subprocess.check_output([
46+
return_code = subprocess.call([
4647
PROTOC_CMD,
4748
'--proto_path',
4849
PROTOS_DIR,
@@ -54,6 +55,8 @@ def get_pb2_contents_with_grpc():
5455
temp_dir,
5556
PROTO_PATH,
5657
])
58+
if return_code != 0:
59+
sys.exit(return_code)
5760
with open(generated_path, 'rb') as file_obj:
5861
return file_obj.readlines()
5962
finally:
@@ -70,14 +73,16 @@ def get_pb2_contents_without_grpc():
7073
generated_path = os.path.join(temp_dir, 'google', 'longrunning',
7174
'operations_pb2.py')
7275
try:
73-
subprocess.check_output([
76+
return_code = subprocess.call([
7477
PROTOC_CMD,
7578
'--proto_path',
7679
PROTOS_DIR,
7780
'--python_out',
7881
temp_dir,
7982
PROTO_PATH,
8083
])
84+
if return_code != 0:
85+
sys.exit(return_code)
8186
with open(generated_path, 'rb') as file_obj:
8287
return file_obj.readlines()
8388
finally:

0 commit comments

Comments
 (0)