I'd like to use protoc.main(...)
in order to generate python gRPC files during runtime as below.
from grpc_tools import protoc
args = "--proto_path=. --python_out=grpc --grpc_python_out=grpc alpha.proto"
result = protoc.main(c)
The above code gives 'missing output directives' error with result code 1
.
However, below workaround to put alpha.proto
as a commandline args works. It means alpha.proto
file is fine.
import subprocess
result = subprocess.call("python -m grpc_tools.protoc " + args, shell=True)
The possible causes are (1) protoc.main
does encode to each character as below code, or (2) protoc.main
wrongly resolves argument paths internally.
def main(command_arguments):
"""Run the protocol buffer compiler with the given command-line arguments.
Args:
command_arguments: a list of strings representing command line arguments to
`protoc`.
"""
command_arguments = [argument.encode() for argument in command_arguments]
return _protoc_compiler.run_main(command_arguments)
How can I use protoc.main
correctly?