Add generaton cli entrypoint

This commit is contained in:
Luke Murphy 2020-08-09 02:52:58 +02:00
parent 82c398e13b
commit 249c4d4634
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
4 changed files with 41 additions and 0 deletions

4
example/client.py Normal file
View File

@ -0,0 +1,4 @@
"""Echo client."""
if __name__ == "__main__":
pass

9
example/schema.proto Normal file
View File

@ -0,0 +1,9 @@
syntax = "proto2";
message EchoMsg {
required string value = 1;
}
service Example {
rpc Echo (EchoMsg) returns (EchoMsg) {}
}

4
example/server.py Normal file
View File

@ -0,0 +1,4 @@
"""Echo server."""
if __name__ == "__main__":
pass

24
hrpc/hrpc.py Normal file
View File

@ -0,0 +1,24 @@
"""Simple RPC with Protobuf Services."""
from argparse import ArgumentParser, FileType
from shlex import split
from subprocess import run
def main():
"""Command-line entrypoint."""
parser = ArgumentParser(description="Generate hrpc service and stubs")
parser.add_argument("protobuf", type=FileType("r"), help="protobuf file")
args = parser.parse_args()
generate(args)
def generate(args):
"""Generate services and stubs."""
cmd = (
"python -m grpc_tools.protoc "
"--purerpc_out=. "
"--python_out=. "
"-I. "
f"{args.protobuf.name}"
)
run(split(cmd))