aboutsummaryrefslogtreecommitdiff
path: root/google
diff options
context:
space:
mode:
authorLuke Sneeringer <luke@sneeringer.com>2018-05-24 11:28:50 -0700
committerThea Flowers <theaflowers@google.com>2018-05-24 11:28:50 -0700
commitf05cd0cd2f29645cf029e5126d60b5a4816c6bb1 (patch)
tree419b2985e06f8d4b08fe6ab93e8022391f7fdfe3 /google
parent84aab8500ce1bb0c85f0e2edcf708d3c3084fc2d (diff)
downloadpython-api-core-f05cd0cd2f29645cf029e5126d60b5a4816c6bb1.tar.gz
Make client_info work without gRPC installed. (#5075)
Diffstat (limited to 'google')
-rw-r--r--google/api_core/gapic_v1/client_info.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/google/api_core/gapic_v1/client_info.py b/google/api_core/gapic_v1/client_info.py
index a76754d..7feeaf1 100644
--- a/google/api_core/gapic_v1/client_info.py
+++ b/google/api_core/gapic_v1/client_info.py
@@ -23,8 +23,13 @@ import platform
import pkg_resources
_PY_VERSION = platform.python_version()
-_GRPC_VERSION = pkg_resources.get_distribution('grpcio').version
_API_CORE_VERSION = pkg_resources.get_distribution('google-api-core').version
+
+try:
+ _GRPC_VERSION = pkg_resources.get_distribution('grpcio').version
+except pkg_resources.DistributionNotFound: # pragma: NO COVER
+ _GRPC_VERSION = None
+
METRICS_METADATA_KEY = 'x-goog-api-client'
@@ -38,7 +43,7 @@ class ClientInfo(object):
Args:
python_version (str): The Python interpreter version, for example,
``'2.7.13'``.
- grpc_version (str): The gRPC library version.
+ grpc_version (Optional[str]): The gRPC library version.
api_core_version (str): The google-api-core library version.
gapic_version (Optional[str]): The sversion of gapic-generated client
library, if the library was generated by gapic.
@@ -66,15 +71,18 @@ class ClientInfo(object):
# expects these items to be in specific locations.
ua = 'gl-python/{python_version} '
- if self.client_library_version is not None:
- ua += 'gccl/{client_library_version} '
+ if self.grpc_version is not None:
+ ua += 'grpc/{grpc_version} '
+
+ ua += 'gax/{api_core_version} '
if self.gapic_version is not None:
ua += 'gapic/{gapic_version} '
- ua += 'gax/{api_core_version} grpc/{grpc_version}'
+ if self.client_library_version is not None:
+ ua += 'gccl/{client_library_version} '
- return ua.format(**self.__dict__)
+ return ua.format(**self.__dict__).strip()
def to_grpc_metadata(self):
"""Returns the gRPC metadata for this client info."""