From d481046de69f0da27b702fd881d46c39f61715ae Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Fri, 21 Aug 2020 16:57:31 -0700 Subject: [PATCH 1/3] Tolerate old versions of grpcio-tools --- src/python/grpcio/grpc/_runtime_protos.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/python/grpcio/grpc/_runtime_protos.py b/src/python/grpcio/grpc/_runtime_protos.py index 88863e0306d..8d57dea6449 100644 --- a/src/python/grpcio/grpc/_runtime_protos.py +++ b/src/python/grpcio/grpc/_runtime_protos.py @@ -14,20 +14,23 @@ import sys +_REQUIRED_SYMBOLS = ("_protos", "_services", "_protos_and_services") + def _uninstalled_protos(*args, **kwargs): raise NotImplementedError( - "Install the grpcio-tools package to use the protos function.") + "Install grpcio-tools package (1.32.0+) to use the protos function.") def _uninstalled_services(*args, **kwargs): raise NotImplementedError( - "Install the grpcio-tools package to use the services function.") + "Install the grpcio-tools (1.32.0+) package to use the services function." + ) def _uninstalled_protos_and_services(*args, **kwargs): raise NotImplementedError( - "Install the grpcio-tools package to use the protos_and_services function." + "Install the grpcio-tools package (1.32.0+) to use the protos_and_services function." ) @@ -156,6 +159,12 @@ else: services = _uninstalled_services protos_and_services = _uninstalled_protos_and_services else: - from grpc_tools.protoc import _protos as protos # pylint: disable=unused-import - from grpc_tools.protoc import _services as services # pylint: disable=unused-import - from grpc_tools.protoc import _protos_and_services as protos_and_services # pylint: disable=unused-import + import grpc_tools.protoc # pylint: disable=unused-import + if all(hasattr(grpc_tools.protoc, sym) for sym in _REQUIRED_SYMBOLS): + from grpc_tools.protoc import _protos as protos # pylint: disable=unused-import + from grpc_tools.protoc import _services as services # pylint: disable=unused-import + from grpc_tools.protoc import _protos_and_services as protos_and_services # pylint: disable=unused-import + else: + protos = _uninstalled_protos + services = _uninstalled_services + protos_and_services = _uninstalled_protos_and_services From 3ce329ffda09d55310b3478db7edd1640f0c388b Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Fri, 21 Aug 2020 17:04:15 -0700 Subject: [PATCH 2/3] Clean up error messages --- src/python/grpcio/grpc/_runtime_protos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/_runtime_protos.py b/src/python/grpcio/grpc/_runtime_protos.py index 8d57dea6449..9025c1bbeb8 100644 --- a/src/python/grpcio/grpc/_runtime_protos.py +++ b/src/python/grpcio/grpc/_runtime_protos.py @@ -19,12 +19,12 @@ _REQUIRED_SYMBOLS = ("_protos", "_services", "_protos_and_services") def _uninstalled_protos(*args, **kwargs): raise NotImplementedError( - "Install grpcio-tools package (1.32.0+) to use the protos function.") + "Install the grpcio-tools package (1.32.0+) to use the protos function.") def _uninstalled_services(*args, **kwargs): raise NotImplementedError( - "Install the grpcio-tools (1.32.0+) package to use the services function." + "Install the grpcio-tools package (1.32.0+) to use the services function." ) From 36be9bbf6ecb0213177cedbde0d17c0e1a9803a4 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Fri, 21 Aug 2020 17:25:25 -0700 Subject: [PATCH 3/3] Yapf --- src/python/grpcio/grpc/_runtime_protos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/grpcio/grpc/_runtime_protos.py b/src/python/grpcio/grpc/_runtime_protos.py index 9025c1bbeb8..7f555ccd9e4 100644 --- a/src/python/grpcio/grpc/_runtime_protos.py +++ b/src/python/grpcio/grpc/_runtime_protos.py @@ -19,7 +19,8 @@ _REQUIRED_SYMBOLS = ("_protos", "_services", "_protos_and_services") def _uninstalled_protos(*args, **kwargs): raise NotImplementedError( - "Install the grpcio-tools package (1.32.0+) to use the protos function.") + "Install the grpcio-tools package (1.32.0+) to use the protos function." + ) def _uninstalled_services(*args, **kwargs):