21
21
from grpc_tools import protoc
22
22
23
23
24
- def build_package_protos (package_root ):
24
+ def build_package_protos (package_root , strict_mode = False ):
25
25
proto_files = []
26
26
inclusion_root = os .path .abspath (package_root )
27
27
for root , _ , files in os .walk (inclusion_root ):
@@ -42,17 +42,21 @@ def build_package_protos(package_root):
42
42
'--grpc_python_out={}' .format (inclusion_root ),
43
43
] + [proto_file ]
44
44
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 ))
46
49
47
50
48
51
class BuildPackageProtos (setuptools .Command ):
49
52
"""Command to generate project *_pb2.py modules from proto files."""
50
53
51
54
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.' )]
53
57
54
58
def initialize_options (self ):
55
- pass
59
+ self . strict_mode = False
56
60
57
61
def finalize_options (self ):
58
62
pass
@@ -62,4 +66,5 @@ def run(self):
62
66
# directory is provided as an 'include' directory. We assume it's the '' key
63
67
# to `self.distribution.package_dir` (and get a key error if it's not
64
68
# there).
65
- build_package_protos (self .distribution .package_dir ['' ])
69
+ build_package_protos (self .distribution .package_dir ['' ],
70
+ self .strict_mode )
0 commit comments