setuptools plugin to compile .proto files using python-betterproto.
- Protobuf compiler
protoc - Python 3.6+
In either of the following scenarios, setuptools-proto will take effects.
- Option 1, install
setuptools-protousingpipor other tools:
$ pip install setuptools-proto- Option 2, require
setuptools-protoinsetup_requireskeyword ofsetuptools.
So, add it either in setup.py in a imperative fashion,
setuptools.setup(
setup_requires=['setuptools-proto'],
)or in seutp.cfg in a declarative manner.
[options]
setup_requires =
setuptools-protoTo let setuptools-proto know what to compile,
define proto_modules as a ProtoModule list.
from setuptools import setup
from setuptools_proto import ProtoModule
module1 = ProtoModule(
['proto/sample/**/*.proto'],
cwd='proto/sample',
)
module2 = ProtoModule(
['demo/grpc/echo.proto', 'demo/grpc/hello.proto'],
cwd='demo/grpc',
out_dir='proto',
include_dirs=['demo/schema'],
)
setup(
proto_modules=[module1, module2],
)By default, setuptools-proto will use the system protoc compiler.
If there's a custom install of protoc, which is not in the PATH,
You can point environment variable PROTOC to it,
or command line argument --protoc to it.
For example,
$ python setup.py --protoc /path/to/protoc build_protoAn extra setuptools command build_proto is added, to compile .proto to python code.
This command will be automatically run before setuptools command build_py.