Skip to content

Commit

Permalink
Added "skip-empty" parameter for the protoc plugin, refs #42
Browse files Browse the repository at this point in the history
  • Loading branch information
vmagamedov committed Mar 27, 2019
1 parent 40ae265 commit 68b56b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ plugin provided, which can be used like this:
This command will generate ``helloworld_pb2.py`` and ``helloworld_grpc.py``
files.

Plugin parameters:

- ``skip-empty`` - don't generate empty ``*_grpc.py`` file if corresponding
``*.proto`` file doesn't contain service definitions:

.. code-block:: shell
--python_grpc_out=skip-empty:output/path
Plugin, which implements ``--python_grpc_out`` option is available for
``protoc`` compiler as ``protoc-gen-python_grpc`` executable, which will be
installed by ``setuptools`` into your ``PATH`` during installation of the
Expand Down
5 changes: 5 additions & 0 deletions grpclib/plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def main():
with os.fdopen(sys.stdin.fileno(), 'rb') as inp:
request = CodeGeneratorRequest.FromString(inp.read())

skip_empty = 'skip-empty' in request.parameter.split(',')

types_map = {
_type_name(pf, mt): '.'.join((_proto2py(pf.name), mt.name))
for pf in request.proto_file
Expand Down Expand Up @@ -175,6 +177,9 @@ def main():
services.append(Service(service.name,
methods=methods))

if not services and skip_empty:
continue

out = response.file.add()
out.name = file_to_generate.replace('.proto', SUFFIX)
out.content = render(proto_file=proto_file.name,
Expand Down

0 comments on commit 68b56b2

Please sign in to comment.