Skip to content
Snippets Groups Projects
Commit e2195c06 authored by kpayson64's avatar kpayson64 Committed by GitHub
Browse files

Merge pull request #7397 from soltanmm/hua-tulyada-hua-wa-hua-HEY-Hey-hey-hey

Document the custom grpcio-tools command class
parents 4fa58f08 34c9a73a
No related branches found
No related tags found
No related merge requests found
......@@ -137,3 +137,42 @@ Given protobuf include directories :code:`$INCLUDE`, an output directory
::
$ python -m grpc.tools.protoc -I$INCLUDE --python_out=$OUTPUT --grpc_python_out=$OUTPUT $PROTO_FILES
To use as a build step in distutils-based projects, you may use the provided
command class in your :code:`setup.py`:
::
setuptools.setup(
# ...
cmdclass={
'build_proto_modules': grpc.tools.command.BuildPackageProtos,
}
# ...
)
Invocation of the command will walk the project tree and transpile every
:code:`.proto` file into a :code:`_pb2.py` file in the same directory.
Note that this particular approach requires :code:`grpcio-tools` to be
installed on the machine before the setup script is invoked (i.e. no
combination of :code:`setup_requires` or :code:`install_requires` will provide
access to :code:`grpc.tools.command.BuildPackageProtos` if it isn't already
installed). One way to work around this can be found in our
:code:`grpcio-health-checking`
`package <https://pypi.python.org/pypi/grpcio-health-checking>`_:
::
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[''])
Now including :code:`grpcio-tools` in :code:`setup_requires` will provide the
command on-setup as desired.
For more information on command classes, consult :code:`distutils` and
:code:`setuptools` documentation.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment