如何从多个 proto 文件生成单个 python 文件
我有一个项目,其中包含一个原始文件:
$ tree proto/
proto/
├── common
│ └── request.proto
├── file
│ ├── file.proto
│ └── file_service.proto
├── job
│ ├── job.proto
│ └── job_service.proto
├── pool
│ ├── pool.proto
│ └── pool_service.proto
└── worker
├── worker.proto
└── worker_service.proto
5 directories, 9 files
我想从 worker_service.proto
生成一个文件,但这些文件具有来自 common 的导入。
grpc_tools.protoc 中是否有一个选项可以生成单个 python 文件?
或者有没有一种工具可以生成一个proto文件?
I have a project with a proto files in a:
$ tree proto/
proto/
├── common
│ └── request.proto
├── file
│ ├── file.proto
│ └── file_service.proto
├── job
│ ├── job.proto
│ └── job_service.proto
├── pool
│ ├── pool.proto
│ └── pool_service.proto
└── worker
├── worker.proto
└── worker_service.proto
5 directories, 9 files
I want to generate a one single file from worker_service.proto
but these file has imports from common.
Is there a option in grpc_tools.protoc
to generate one single python file?
Or is there a tool to generate one proto file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据这些信息,我猜生成一个Python文件意味着:而不是生成一个用于消息的Python文件(
*_pb2.py
)和一个用于服务的Python文件(*_pb2_grpc.py< /code>),您希望将它们连接到一个 Python 文件中。要查看生成的文件内容,这里是 Helloworld 示例< /a>.
gRPC Python ProtoBuf 插件当前不支持合并两个输出文件(与 Java/Go 不同)。您可以发布功能请求并添加有关您的用例的更多详细信息:https://github.com/grpc /grpc/问题
Based on the information, I guess by generate one Python file means: instead of generate one Python file for messages (
*_pb2.py
) and one Python file for services (*_pb2_grpc.py
), you hope to concatenate both of them into one Python file. To take a look at the generated file content, here is the Helloworld example.Combining the two output file is currently not supported by the gRPC Python ProtoBuf plugin (unlike Java/Go). You can post a feature request and add more detail about your use case: https://github.com/grpc/grpc/issues