Skip to content

Commit f7769a1

Browse files
Pass betterproto option using custom_opt instead of environment variable
1 parent d31f90b commit f7769a1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,17 @@ $ pipenv run test
360360
Betterproto includes compiled versions for Google's well-known types at [betterproto/lib/google](betterproto/lib/google).
361361
Be sure to regenerate these files when modifying the plugin output format, and validate by running the tests.
362362

363-
Normally, the plugin does not compile any references to `google.protobuf`, since they are pre-compiled. To force compilation of `google.protobuf`, set this environment variable: `BETTERPROTO_OPTS=INCLUDE_GOOGLE`.
363+
Normally, the plugin does not compile any references to `google.protobuf`, since they are pre-compiled. To force compilation of `google.protobuf`, use the option `--custom_opt=INCLUDE_GOOGLE`.
364364

365365
Assuming your `google.protobuf` source files (included with all releases of `protoc`) are located in `/usr/local/include`, you can regenerate them as follows:
366366

367367
```sh
368-
export BETTERPROTO_OPTS=INCLUDE_GOOGLE
369-
protoc --plugin=protoc-gen-custom=betterproto/plugin.py --custom_out=betterproto/lib -I/usr/local/include/ /usr/local/include/google/protobuf/*.proto
368+
protoc \
369+
--plugin=protoc-gen-custom=betterproto/plugin.py \
370+
--custom_opt=INCLUDE_GOOGLE \
371+
--custom_out=betterproto/lib \
372+
-I /usr/local/include/ \
373+
/usr/local/include/google/protobuf/*.proto
370374
```
371375

372376

betterproto/plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def get_comment(proto_file, path: List[int], indent: int = 4) -> str:
120120

121121

122122
def generate_code(request, response):
123-
plugin_options = os.environ.get("BETTERPROTO_OPTS")
124-
plugin_options = plugin_options.split(" ") if plugin_options else []
123+
plugin_options = request.parameter.split(",") if request.parameter else []
125124

126125
env = jinja2.Environment(
127126
trim_blocks=True,

0 commit comments

Comments
 (0)