Skip to content

Commit

Permalink
[gRPC] Update the code generator for Python to produce typed handlers (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
anton-bobukh committed Jun 18, 2024
1 parent dafd2f1 commit fb9afba
Show file tree
Hide file tree
Showing 22 changed files with 1,165 additions and 653 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ set(FlatBuffers_Compiler_SRCS
src/bfbs_gen_lua.h
src/bfbs_gen_nim.h
src/bfbs_namer.h
include/codegen/idl_namer.h
include/codegen/namer.h
include/codegen/python.h
include/codegen/python.cc
include/flatbuffers/code_generators.h
Expand Down
43 changes: 41 additions & 2 deletions docs/source/Compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ Additional options:

- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
generated C++. This also implies `--no-prefix`.

- `--no-emit-min-max-enum-values` : Disable generation of MIN and MAX
enumerated values for scoped enums and prefixed enums.

- `--gen-includes` : (deprecated), this is the default behavior.
If the original behavior is required (no include
statements) use `--no-includes.`
Expand Down Expand Up @@ -238,5 +238,44 @@ Additional options:

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

Additional gRPC options:

- `--grpc-filename-suffix`: `[C++]` An optional suffix for the generated
files' names. For example, compiling gRPC for C++ with
`--grpc-filename-suffix=.fbs` will generate `{name}.fbs.h` and
`{name}.fbs.cc` files.

- `--grpc-additional-header`: `[C++]` Additional headers to include in the
generated files.

- `--grpc-search-path`: `[C++]` An optional prefix for the gRPC runtime path.
For example, compiling gRPC for C++ with `--grpc-search-path=some/path` will
generate the following includes:

```cpp
#include "some/path/grpcpp/impl/codegen/async_stream.h"
#include "some/path/grpcpp/impl/codegen/async_unary_call.h"
#include "some/path/grpcpp/impl/codegen/method_handler.h"
...
```

- `--grpc-use-system-headers`: `[C++]` Whether to generate `#include <header>`
instead of `#include "header.h"` for all headers when compiling gRPC for
C++. For example, compiling gRPC for C++ with `--grpc-use-system-headers`
will generate the following includes:

```cpp
#include <some/path/grpcpp/impl/codegen/async_stream.h>
#include <some/path/grpcpp/impl/codegen/async_unary_call.h>
#include <some/path/grpcpp/impl/codegen/method_handler.h>
...
```

NOTE: This option can be negated with `--no-grpc-use-system-headers`.

- `--grpc-python-typed-handlers`: `[Python]` Whether to generate the typed
handlers that use the generated Python classes instead of raw bytes for
requests/responses.

NOTE: short-form options for generators are deprecated, use the long form
whenever possible.
2 changes: 2 additions & 0 deletions grpc/src/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ cc_library(
visibility = ["//visibility:private"],
deps = [
"//:flatbuffers",
"//include/codegen:namer",
"//include/codegen:python",
],
)

Expand Down
Loading

0 comments on commit fb9afba

Please sign in to comment.