From 344f28d4a24524e107a6ce3a2077283b08e603b9 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Thu, 1 Oct 2020 17:17:55 -0700 Subject: [PATCH] Allow `generate_py_protobufs` to find a custom protoc (#7936) Currently, the logic in `generate_py_protobufs` cannot find a custom `protoc` (even though it's supposed to be possible). Fixes: 1. Mark the `--protoc` flag as accepting an argument. 2. If the `--protoc` flag was not passed, try finding `PROTOC` in the environment. 3. (Existing behavior) Otherwise, fall back to `spawn.find_executable`. Hat tip to @bobhancock for uncovering the problem(s). --- .../protobuf_distutils/generate_py_protobufs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/protobuf_distutils/protobuf_distutils/generate_py_protobufs.py b/python/protobuf_distutils/protobuf_distutils/generate_py_protobufs.py index 452b5d7e1e..515ded2334 100644 --- a/python/protobuf_distutils/protobuf_distutils/generate_py_protobufs.py +++ b/python/protobuf_distutils/protobuf_distutils/generate_py_protobufs.py @@ -47,7 +47,7 @@ class generate_py_protobufs(Command): ('extra-proto-paths=', None, 'Additional paths to resolve imports in .proto files.'), - ('protoc', None, + ('protoc=', None, 'Path to a specific `protoc` command to use.'), ] boolean_options = ['recurse'] @@ -127,6 +127,8 @@ class generate_py_protobufs(Command): self.ensure_string_list('proto_files') + if self.protoc is None: + self.protoc = os.getenv('PROTOC') if self.protoc is None: self.protoc = spawn.find_executable('protoc')