From f7769a19d1d083c22435448aaf973f38905de712 Mon Sep 17 00:00:00 2001 From: boukeversteegh Date: Sat, 6 Jun 2020 12:51:37 +0200 Subject: [PATCH] Pass betterproto option using custom_opt instead of environment variable --- README.md | 10 +++++++--- betterproto/plugin.py | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cb8c0a0..385d1ea 100644 --- a/README.md +++ b/README.md @@ -360,13 +360,17 @@ $ pipenv run test Betterproto includes compiled versions for Google's well-known types at [betterproto/lib/google](betterproto/lib/google). Be sure to regenerate these files when modifying the plugin output format, and validate by running the tests. -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`. +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`. Assuming your `google.protobuf` source files (included with all releases of `protoc`) are located in `/usr/local/include`, you can regenerate them as follows: ```sh -export BETTERPROTO_OPTS=INCLUDE_GOOGLE -protoc --plugin=protoc-gen-custom=betterproto/plugin.py --custom_out=betterproto/lib -I/usr/local/include/ /usr/local/include/google/protobuf/*.proto +protoc \ + --plugin=protoc-gen-custom=betterproto/plugin.py \ + --custom_opt=INCLUDE_GOOGLE \ + --custom_out=betterproto/lib \ + -I /usr/local/include/ \ + /usr/local/include/google/protobuf/*.proto ``` diff --git a/betterproto/plugin.py b/betterproto/plugin.py index 85557bc..e300318 100755 --- a/betterproto/plugin.py +++ b/betterproto/plugin.py @@ -120,8 +120,7 @@ def get_comment(proto_file, path: List[int], indent: int = 4) -> str: def generate_code(request, response): - plugin_options = os.environ.get("BETTERPROTO_OPTS") - plugin_options = plugin_options.split(" ") if plugin_options else [] + plugin_options = request.parameter.split(",") if request.parameter else [] env = jinja2.Environment( trim_blocks=True,