我有一些.proto
gRPC文件,我想编译为设置.py脚本。这需要运行from grpc_tools import protoc
并在setup(args)
之前调用protoc
。目标是编译并安装来自pip install pkgname
的pb文件。在
例如
# setup.py
# generate our pb2 files in the temp directory structure
compile_protobufs(pkgname)
# this will package the generated files and put them in site-packages or .whl
setup(
name=pkgname,
install_requires=['grpcio-tools', ...],
...
)
这正如预期的那样工作,我可以在我的站点包或轮子中获得pb文件,而不必将它们存在于源文件夹中。但是,这个模式意味着我不能天真地从头开始pip install pkgname
,因为步骤compile_protobufs
依赖于grpcio-tools
,直到setup()
才安装。在
我可以使用setup\u requires,但是that is on the chopping block。我可以先安装依赖项(现在我使用RUN pip install -r build-require.txt && pip install pkgname/
),但似乎仍然应该有一种更干净的方法。在
我是否正确地使用了这种模式,或者我遗漏了一些包装习惯用法?在
我的标准:
pip install
时重新生成_pb2.py
文件.whl
或tar。在
看起来这里已经有记载了:
https://github.com/grpc/grpc/tree/master/tools/distrib/python/grpcio_tools#usage
所以你的
setup.py
可以是这样的:相关问题 更多 >
编程相关推荐