diff options
Diffstat (limited to 'protoc-gen-custom_grpc')
-rwxr-xr-x | protoc-gen-custom_grpc | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/protoc-gen-custom_grpc b/protoc-gen-custom_grpc index eb5ec11..00e47a5 100755 --- a/protoc-gen-custom_grpc +++ b/protoc-gen-custom_grpc @@ -1,7 +1,25 @@ #!/usr/bin/env python3 + +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Custom mmi2grpc gRPC compiler.""" + import sys -from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest, CodeGeneratorResponse +from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest, \ + CodeGeneratorResponse def eprint(*args, **kwargs): @@ -10,14 +28,17 @@ def eprint(*args, **kwargs): request = CodeGeneratorRequest.FromString(sys.stdin.buffer.read()) + def has_type(proto_file, type_name): return any(filter(lambda x: x.name == type_name, proto_file.message_type)) + def import_type(imports, type): - # eprint(f'type: {type} request: {request.proto_file}') package = type[1:type.rindex('.')] type_name = type[type.rindex('.')+1:] - file = next(filter(lambda x: x.package == package and has_type(x, type_name), request.proto_file)) + file = next(filter( + lambda x: x.package == package and has_type(x, type_name), + request.proto_file)) python_path = file.name.replace('.proto', '').replace('/', '.') as_name = python_path.replace('.', '_dot_') + '__pb2' module_path = python_path[:python_path.rindex('.')] |