42
42
if TYPE_CHECKING :
43
43
from google .protobuf .descriptor import Descriptor
44
44
45
+
45
46
def traverse (
46
47
proto_file : FieldDescriptorProto ,
47
48
) -> "itertools.chain[Tuple[Union[str, EnumDescriptorProto], List[int]]]" :
@@ -68,30 +69,30 @@ def _traverse(
68
69
_traverse ([5 ], proto_file .enum_type ), _traverse ([4 ], proto_file .message_type )
69
70
)
70
71
72
+
71
73
def parse_options (plugin_options : List [str ]) -> Options :
72
74
options = Options ()
73
75
for option in plugin_options :
74
76
if option .startswith ("grpc=" ):
75
77
options .grpc_kind = option .split ("=" , 1 )[1 ]
78
+ if option == "INCLUDE_GOOGLE" :
79
+ options .include_google = True
76
80
return options
77
81
82
+
78
83
def generate_code (
79
84
request : plugin .CodeGeneratorRequest , response : plugin .CodeGeneratorResponse
80
85
) -> None :
81
- plugin_options = request . parameter . split ( "," ) if request . parameter else []
82
-
83
- options = parse_options ( plugin_options )
86
+ plugin_options = parse_options (
87
+ request . parameter . split ( "," ) if request . parameter else []
88
+ )
84
89
85
90
request_data = PluginRequestCompiler (
86
- plugin_request_obj = request ,
87
- options = options
91
+ plugin_request_obj = request , options = plugin_options
88
92
)
89
93
# Gather output packages
90
94
for proto_file in request .proto_file :
91
- if (
92
- proto_file .package == "google.protobuf"
93
- and "INCLUDE_GOOGLE" not in plugin_options
94
- ):
95
+ if proto_file .package == "google.protobuf" and plugin_options .include_google :
95
96
# If not INCLUDE_GOOGLE,
96
97
# skip re-compiling Google's well-known types
97
98
continue
0 commit comments