Skip to content

Commit fb9afba

Browse files
authored
[gRPC] Update the code generator for Python to produce typed handlers (#8326)
* Move `namer.h` and `idl_namer.h` to `include/codegen` so they can be reused from `grpc` dirqectory. * [gRPC] Update the Python generator to produce typed handlers and Python stubs if requested. * [gRPC] Document the newly added compiler flags.
1 parent dafd2f1 commit fb9afba

22 files changed

+1165
-653
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ set(FlatBuffers_Compiler_SRCS
183183
src/bfbs_gen_lua.h
184184
src/bfbs_gen_nim.h
185185
src/bfbs_namer.h
186+
include/codegen/idl_namer.h
187+
include/codegen/namer.h
186188
include/codegen/python.h
187189
include/codegen/python.cc
188190
include/flatbuffers/code_generators.h

docs/source/Compiler.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ Additional options:
9696

9797
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
9898
generated C++. This also implies `--no-prefix`.
99-
99+
100100
- `--no-emit-min-max-enum-values` : Disable generation of MIN and MAX
101101
enumerated values for scoped enums and prefixed enums.
102-
102+
103103
- `--gen-includes` : (deprecated), this is the default behavior.
104104
If the original behavior is required (no include
105105
statements) use `--no-includes.`
@@ -238,5 +238,44 @@ Additional options:
238238

239239
- `--python-typing` : Generate Python type annotations
240240

241+
Additional gRPC options:
242+
243+
- `--grpc-filename-suffix`: `[C++]` An optional suffix for the generated
244+
files' names. For example, compiling gRPC for C++ with
245+
`--grpc-filename-suffix=.fbs` will generate `{name}.fbs.h` and
246+
`{name}.fbs.cc` files.
247+
248+
- `--grpc-additional-header`: `[C++]` Additional headers to include in the
249+
generated files.
250+
251+
- `--grpc-search-path`: `[C++]` An optional prefix for the gRPC runtime path.
252+
For example, compiling gRPC for C++ with `--grpc-search-path=some/path` will
253+
generate the following includes:
254+
255+
```cpp
256+
#include "some/path/grpcpp/impl/codegen/async_stream.h"
257+
#include "some/path/grpcpp/impl/codegen/async_unary_call.h"
258+
#include "some/path/grpcpp/impl/codegen/method_handler.h"
259+
...
260+
```
261+
262+
- `--grpc-use-system-headers`: `[C++]` Whether to generate `#include <header>`
263+
instead of `#include "header.h"` for all headers when compiling gRPC for
264+
C++. For example, compiling gRPC for C++ with `--grpc-use-system-headers`
265+
will generate the following includes:
266+
267+
```cpp
268+
#include <some/path/grpcpp/impl/codegen/async_stream.h>
269+
#include <some/path/grpcpp/impl/codegen/async_unary_call.h>
270+
#include <some/path/grpcpp/impl/codegen/method_handler.h>
271+
...
272+
```
273+
274+
NOTE: This option can be negated with `--no-grpc-use-system-headers`.
275+
276+
- `--grpc-python-typed-handlers`: `[Python]` Whether to generate the typed
277+
handlers that use the generated Python classes instead of raw bytes for
278+
requests/responses.
279+
241280
NOTE: short-form options for generators are deprecated, use the long form
242281
whenever possible.

grpc/src/compiler/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ cc_library(
9595
visibility = ["//visibility:private"],
9696
deps = [
9797
"//:flatbuffers",
98+
"//include/codegen:namer",
99+
"//include/codegen:python",
98100
],
99101
)
100102

0 commit comments

Comments
 (0)