diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd2d3fa --- /dev/null +++ b/Makefile @@ -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 diff --git a/asyncgrpc/handler.py b/asyncgrpc/handler.py index fc3a7fe..ba3254a 100644 --- a/asyncgrpc/handler.py +++ b/asyncgrpc/handler.py @@ -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__, diff --git a/asyncgrpc/plugin/main.py b/asyncgrpc/plugin/main.py index 63eec80..5bde19b 100644 --- a/asyncgrpc/plugin/main.py +++ b/asyncgrpc/plugin/main.py @@ -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()) diff --git a/example/Makefile b/example/Makefile deleted file mode 100644 index 9075efe..0000000 --- a/example/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -stubs: - python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. --python_asyncgrpc_out=. helloworld.proto diff --git a/example/helloworld_pb2_asyncgrpc.py b/example/helloworld_pb2_asyncgrpc.py index f8b4520..63fe690 100644 --- a/example/helloworld_pb2_asyncgrpc.py +++ b/example/helloworld_pb2_asyncgrpc.py @@ -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