Improve protoc autodetection.
protoc --version caused extra output (the version number).
It could be redirected to /dev/null, but it seems unnecessary
to invoke protoc twice every time. Instead just call it and
let it fail if it is missing.
diff --git a/generator/proto/_utils.py b/generator/proto/_utils.py
index 5cbc650..26e1ccf 100644
--- a/generator/proto/_utils.py
+++ b/generator/proto/_utils.py
@@ -1,17 +1,5 @@
import subprocess
-
-def has_system_protoc():
- # type: () -> bool
- """ checks if a system-installed `protoc` executable exists """
-
- try:
- subprocess.check_call("protoc --version".split())
- except FileNotFoundError:
- return False
- return True
-
-
def has_grpcio_protoc():
# type: () -> bool
""" checks if grpcio-tools protoc is installed"""
@@ -32,12 +20,10 @@
using system-installed protoc as a fallback.
Args:
- argv: protoc CLI invocation
+ argv: protoc CLI invocation, first item must be 'protoc'
"""
if has_grpcio_protoc():
import grpc_tools.protoc as protoc
return protoc.main(argv)
- if has_system_protoc():
+ else:
return subprocess.check_call(argv)
-
- raise FileNotFoundError("Neither grpc-tools nor system provided protoc could be found.")