用法
给定protobuf包含目录$INCLUDE,输出目录
$OUTPUT,和proto文件$PROTO_FILES,调用为:$ python -m grpc.tools.protoc -I$INCLUDE --python_out=$OUTPUT --grpc_python_out=$OUTPUT $PROTO_FILES
要在基于distutils的项目中用作构建步骤,可以使用
命令类在您的setup.py:setuptools.setup(
# ...
cmdclass={
'build_proto_modules': grpc.tools.command.BuildPackageProtos,
}
# ...
)
调用该命令将遍历项目树并将
.proto文件放入同一目录中的_pb2.py文件中。
注意,这种特殊的方法要求grpcio-tools
在调用安装脚本之前安装在计算机上(即没有
组合setup_requires或install_requires将提供
如果还没有访问grpc.tools.command.BuildPackageProtos
已安装)。解决这个问题的一种方法是
grpcio-health-checkingpackage:class BuildPackageProtos(setuptools.Command):
"""Command to generate project *_pb2.py modules from proto files."""
# ...
def run(self):
from grpc.tools import command
command.build_package_protos(self.distribution.package_dir[''])
现在在setup_requires中包含grpcio-tools将提供
根据需要设置命令。
有关命令类的更多信息,请参阅distutils和
setuptools文档。