23
23
import pkg_resources
24
24
25
25
_PY_VERSION = platform .python_version ()
26
- _GRPC_VERSION = pkg_resources .get_distribution ('grpcio' ).version
27
26
_API_CORE_VERSION = pkg_resources .get_distribution ('google-api-core' ).version
27
+
28
+ try :
29
+ _GRPC_VERSION = pkg_resources .get_distribution ('grpcio' ).version
30
+ except pkg_resources .DistributionNotFound : # pragma: NO COVER
31
+ _GRPC_VERSION = None
32
+
28
33
METRICS_METADATA_KEY = 'x-goog-api-client'
29
34
30
35
@@ -38,7 +43,7 @@ class ClientInfo(object):
38
43
Args:
39
44
python_version (str): The Python interpreter version, for example,
40
45
``'2.7.13'``.
41
- grpc_version (str): The gRPC library version.
46
+ grpc_version (Optional[ str] ): The gRPC library version.
42
47
api_core_version (str): The google-api-core library version.
43
48
gapic_version (Optional[str]): The sversion of gapic-generated client
44
49
library, if the library was generated by gapic.
@@ -66,15 +71,18 @@ def to_user_agent(self):
66
71
# expects these items to be in specific locations.
67
72
ua = 'gl-python/{python_version} '
68
73
69
- if self .client_library_version is not None :
70
- ua += 'gccl/{client_library_version} '
74
+ if self .grpc_version is not None :
75
+ ua += 'grpc/{grpc_version} '
76
+
77
+ ua += 'gax/{api_core_version} '
71
78
72
79
if self .gapic_version is not None :
73
80
ua += 'gapic/{gapic_version} '
74
81
75
- ua += 'gax/{api_core_version} grpc/{grpc_version}'
82
+ if self .client_library_version is not None :
83
+ ua += 'gccl/{client_library_version} '
76
84
77
- return ua .format (** self .__dict__ )
85
+ return ua .format (** self .__dict__ ). strip ()
78
86
79
87
def to_grpc_metadata (self ):
80
88
"""Returns the gRPC metadata for this client info."""
0 commit comments