Add type stub generation support to grpcio-tools (#30498)

* Add type stub generation support to grpcio-tools

* Clang format
pull/30493/head^2
Richard Belleville 3 years ago committed by GitHub
parent 326a1fd8fd
commit d84a6de3a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      tools/distrib/python/grpcio_tools/grpc_tools/command.py
  2. 6
      tools/distrib/python/grpcio_tools/grpc_tools/main.cc

@ -38,6 +38,7 @@ def build_package_protos(package_root, strict_mode=False):
'--proto_path={}'.format(inclusion_root),
'--proto_path={}'.format(well_known_protos_include),
'--python_out={}'.format(inclusion_root),
'--pyi_out={}'.format(inclusion_root),
'--grpc_python_out={}'.format(inclusion_root),
] + [proto_file]
if protoc.main(command) != 0:

@ -24,6 +24,7 @@
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/python/pyi_generator.h>
#include <google/protobuf/compiler/python/python_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
@ -49,6 +50,11 @@ int protoc_main(int argc, char* argv[]) {
cli.RegisterGenerator("--python_out", &py_generator,
"Generate Python source file.");
// pyi files for type checking
google::protobuf::compiler::python::PyiGenerator pyi_generator;
cli.RegisterGenerator("--pyi_out", &pyi_generator,
"Generate Python pyi stub.");
// gRPC Python
grpc_python_generator::GeneratorConfiguration grpc_py_config;
grpc_python_generator::PythonGrpcGenerator grpc_py_generator(grpc_py_config);

Loading…
Cancel
Save