From 22ac40097ab50bb2d3a7f1a2d35d659c391e0927 Mon Sep 17 00:00:00 2001 From: James Lynn Wu Date: Fri, 10 Sep 2021 19:31:38 -0400 Subject: [PATCH] fix: add a separate DEFAULT_CLIENT_INFO for rest clients (#988) --- .../%sub/services/%service/transports/base.py.j2 | 9 --------- .../%sub/services/%service/transports/rest.py.j2 | 9 ++++++++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 index b38a3535b0..b5b7bb2ac4 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 @@ -6,9 +6,6 @@ import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union import packaging.version import pkg_resources -{% if 'rest' in opts.transport %} -from requests import __version__ as requests_version -{% endif %} import google.auth # type: ignore import google.api_core # type: ignore @@ -37,12 +34,6 @@ try: gapic_version=pkg_resources.get_distribution( '{{ api.naming.warehouse_package_name }}', ).version, - {% if 'grpc' not in opts.transport %} - grpc_version=None, - {% endif %} - {% if 'rest' in opts.transport %} - rest_version=requests_version, - {% endif %} ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index 8c677847da..2308ea8c26 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -4,6 +4,7 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple +from requests import __version__ as requests_version {% if service.has_lro %} from google.api_core import operations_v1 @@ -30,9 +31,15 @@ from google.iam.v1 import policy_pb2 # type: ignore {% endif %} {% endfilter %} -from .base import {{ service.name }}Transport, DEFAULT_CLIENT_INFO +from .base import {{ service.name }}Transport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=requests_version, +) + class {{ service.name }}RestTransport({{ service.name }}Transport): """REST backend transport for {{ service.name }}.