Refactored protoc plugin, moved Makefile into repository root
This commit is contained in:
parent
1f796f7b72
commit
01e2f28585
|
@ -0,0 +1,2 @@
|
|||
stubs:
|
||||
python -m grpc_tools.protoc -I./example --python_out=./example --grpc_python_out=./example --python_asyncgrpc_out=./example ./example/helloworld.proto
|
|
@ -7,7 +7,7 @@ from concurrent.futures import Future
|
|||
import grpc
|
||||
|
||||
|
||||
Method = namedtuple('Method', 'name, input, output')
|
||||
Method = namedtuple('Method', 'name input_type output_type')
|
||||
|
||||
|
||||
def reduce_arity(values, func):
|
||||
|
@ -70,14 +70,14 @@ def create_handler(service, dependencies, functions, *, loop):
|
|||
func.__implements__.name: grpc.unary_unary_rpc_method_handler(
|
||||
make_sync(reduce_arity(dependencies, func), loop=loop),
|
||||
request_deserializer=(
|
||||
func.__implements__.input.FromString
|
||||
func.__implements__.input_type.FromString
|
||||
),
|
||||
response_serializer=(
|
||||
func.__implements__.output.SerializeToString
|
||||
func.__implements__.output_type.SerializeToString
|
||||
),
|
||||
)
|
||||
for func in functions
|
||||
}
|
||||
}
|
||||
|
||||
return grpc.method_handlers_generic_handler(
|
||||
service.__service__,
|
||||
|
|
|
@ -8,6 +8,7 @@ from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest
|
|||
from google.protobuf.compiler.plugin_pb2 import CodeGeneratorResponse
|
||||
|
||||
from .. import handler
|
||||
from ..handler import Method
|
||||
|
||||
|
||||
SUFFIX = handler.__name__.split('.')[0]
|
||||
|
@ -41,7 +42,7 @@ def render(proto_file, package, imports, services):
|
|||
buf.add('# source: {}', proto_file)
|
||||
buf.add('# plugin: {}', __name__)
|
||||
buf.add('')
|
||||
buf.add('from {} import {}', handler.__name__, handler.Method.__name__)
|
||||
buf.add('from {} import {}', handler.__name__, Method.__name__)
|
||||
buf.add('')
|
||||
for mod in imports:
|
||||
buf.add('import {}', mod)
|
||||
|
@ -64,15 +65,9 @@ def render(proto_file, package, imports, services):
|
|||
return buf.content()
|
||||
|
||||
|
||||
Method = namedtuple('Method', 'name input_type output_type')
|
||||
|
||||
Service = namedtuple('Service', 'name methods')
|
||||
|
||||
|
||||
def pp(*args):
|
||||
print(*args, file=sys.stderr)
|
||||
|
||||
|
||||
def _get_proto(request, name):
|
||||
return next(f for f in request.proto_file if f.name == name)
|
||||
|
||||
|
@ -81,10 +76,6 @@ def _proto2py(proto_name):
|
|||
return proto_name.replace('/', '.')[:-len('.proto')] + '_pb2'
|
||||
|
||||
|
||||
def _type2py(type_name):
|
||||
return type_name.lstrip('.')
|
||||
|
||||
|
||||
def main():
|
||||
with os.fdopen(sys.stdin.fileno(), 'rb') as inp:
|
||||
request = CodeGeneratorRequest.FromString(inp.read())
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
stubs:
|
||||
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. --python_asyncgrpc_out=. helloworld.proto
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by the protocol buffer compiler. DO NOT EDIT
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: helloworld.proto
|
||||
# plugin: asyncgrpc.plugin.main
|
||||
|
||||
|
|
Loading…
Reference in New Issue