4242if TYPE_CHECKING :
4343 from google .protobuf .descriptor import Descriptor
4444
45+
4546def traverse (
4647 proto_file : FieldDescriptorProto ,
4748) -> "itertools.chain[Tuple[Union[str, EnumDescriptorProto], List[int]]]" :
@@ -68,30 +69,30 @@ def _traverse(
6869 _traverse ([5 ], proto_file .enum_type ), _traverse ([4 ], proto_file .message_type )
6970 )
7071
72+
7173def parse_options (plugin_options : List [str ]) -> Options :
7274 options = Options ()
7375 for option in plugin_options :
7476 if option .startswith ("grpc=" ):
7577 options .grpc_kind = option .split ("=" , 1 )[1 ]
78+ if option == "INCLUDE_GOOGLE" :
79+ options .include_google = True
7680 return options
7781
82+
7883def generate_code (
7984 request : plugin .CodeGeneratorRequest , response : plugin .CodeGeneratorResponse
8085) -> 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+ )
8489
8590 request_data = PluginRequestCompiler (
86- plugin_request_obj = request ,
87- options = options
91+ plugin_request_obj = request , options = plugin_options
8892 )
8993 # Gather output packages
9094 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 :
9596 # If not INCLUDE_GOOGLE,
9697 # skip re-compiling Google's well-known types
9798 continue
0 commit comments