Merge pull request #17734 from lidizheng/i17703

Escalate the failure of protoc execution
reviewable/pr17549/r7
Lidi Zheng 6 years ago committed by GitHub
commit e7435bb9af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      tools/distrib/python/grpcio_tools/grpc_tools/command.py

@ -21,7 +21,7 @@ import setuptools
from grpc_tools import protoc
def build_package_protos(package_root):
def build_package_protos(package_root, strict_mode=False):
proto_files = []
inclusion_root = os.path.abspath(package_root)
for root, _, files in os.walk(inclusion_root):
@ -42,17 +42,21 @@ def build_package_protos(package_root):
'--grpc_python_out={}'.format(inclusion_root),
] + [proto_file]
if protoc.main(command) != 0:
sys.stderr.write('warning: {} failed'.format(command))
if strict_mode:
raise Exception('error: {} failed'.format(command))
else:
sys.stderr.write('warning: {} failed'.format(command))
class BuildPackageProtos(setuptools.Command):
"""Command to generate project *_pb2.py modules from proto files."""
description = 'build grpc protobuf modules'
user_options = []
user_options = [('strict-mode', 's',
'exit with non-zero value if the proto compiling fails.')]
def initialize_options(self):
pass
self.strict_mode = False
def finalize_options(self):
pass
@ -62,4 +66,5 @@ class BuildPackageProtos(setuptools.Command):
# directory is provided as an 'include' directory. We assume it's the '' key
# to `self.distribution.package_dir` (and get a key error if it's not
# there).
build_package_protos(self.distribution.package_dir[''])
build_package_protos(self.distribution.package_dir[''],
self.strict_mode)

Loading…
Cancel
Save