2121from grpc_tools import protoc
2222
2323
24- def build_package_protos (package_root ):
24+ def build_package_protos (package_root , strict_mode = False ):
2525 proto_files = []
2626 inclusion_root = os .path .abspath (package_root )
2727 for root , _ , files in os .walk (inclusion_root ):
@@ -42,17 +42,21 @@ def build_package_protos(package_root):
4242 '--grpc_python_out={}' .format (inclusion_root ),
4343 ] + [proto_file ]
4444 if protoc .main (command ) != 0 :
45- sys .stderr .write ('warning: {} failed' .format (command ))
45+ if strict_mode :
46+ raise Exception ('error: {} failed' .format (command ))
47+ else :
48+ sys .stderr .write ('warning: {} failed' .format (command ))
4649
4750
4851class BuildPackageProtos (setuptools .Command ):
4952 """Command to generate project *_pb2.py modules from proto files."""
5053
5154 description = 'build grpc protobuf modules'
52- user_options = []
55+ user_options = [('strict-mode' , 's' ,
56+ 'exit with non-zero value if the proto compiling fails.' )]
5357
5458 def initialize_options (self ):
55- pass
59+ self . strict_mode = False
5660
5761 def finalize_options (self ):
5862 pass
@@ -62,4 +66,5 @@ def run(self):
6266 # directory is provided as an 'include' directory. We assume it's the '' key
6367 # to `self.distribution.package_dir` (and get a key error if it's not
6468 # there).
65- build_package_protos (self .distribution .package_dir ['' ])
69+ build_package_protos (self .distribution .package_dir ['' ],
70+ self .strict_mode )
0 commit comments