Skip to content

Commit 9c05dbe

Browse files
authored
feat: Add protobuf runtime version to x-goog-api-client header (#2368)
1 parent 3aa67a5 commit 9c05dbe

File tree

46 files changed

+176
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+176
-3
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ from google.api_core import gapic_v1
2424
from google.api_core import retry_async as retries
2525
from google.auth import credentials as ga_credentials # type: ignore
2626
from google.oauth2 import service_account # type: ignore
27+
import google.protobuf
2728

2829
{{ shared_macros.add_google_api_core_version_header_import(service.version) }}
2930
try:
@@ -726,6 +727,9 @@ class {{ service.async_client_name }}:
726727

727728
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
728729

730+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
731+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
732+
729733

730734
__all__ = (
731735
"{{ service.async_client_name }}",

gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from google.auth.transport import mtls # type: ignore
3636
from google.auth.transport.grpc import SslCredentials # type: ignore
3737
from google.auth.exceptions import MutualTLSChannelError # type: ignore
3838
from google.oauth2 import service_account # type: ignore
39+
import google.protobuf
3940
{{ shared_macros.add_google_api_core_version_header_import(service.version) }}
4041
try:
4142
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
@@ -991,6 +992,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
991992

992993
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
993994

995+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
996+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
994997

995998
__all__ = (
996999
"{{ service.client_name }}",

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from google.api_core import operations_v1
1818
{% endif %}
1919
from google.auth import credentials as ga_credentials # type: ignore
2020
from google.oauth2 import service_account # type: ignore
21+
import google.protobuf
2122

2223
{% filter sort_lines %}
2324
{% set import_ns = namespace(has_operations_mixin=false) %}
@@ -51,6 +52,9 @@ from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + ser
5152

5253
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
5354

55+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
56+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
57+
5458

5559
class {{ service.name }}Transport(abc.ABC):
5660
"""Abstract transport class for {{ service.name }}."""

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from google.api_core import retry as retries
1313
from google.api_core import rest_helpers
1414
from google.api_core import rest_streaming
1515
from google.api_core import gapic_v1
16+
import google.protobuf
1617

1718
from google.protobuf import json_format
1819
{% if service.has_lro %}
@@ -55,6 +56,9 @@ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
5556
rest_version=f"requests@{requests_version}",
5657
)
5758

59+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
60+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
61+
5862

5963
{{ shared_macros.create_interceptor_class(api, service, method, is_async=False) }}
6064

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ from google.cloud.location import locations_pb2 # type: ignore
3434
from google.api_core import retry_async as retries
3535
from google.api_core import rest_helpers
3636
from google.api_core import rest_streaming_async # type: ignore
37-
37+
import google.protobuf
3838

3939
from google.protobuf import json_format
4040
{% if service.has_lro %}
@@ -80,6 +80,9 @@ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
8080
rest_version=f"google-auth@{google.auth.__version__}",
8181
)
8282

83+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
84+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
85+
8386
{{ shared_macros.create_interceptor_class(api, service, method, is_async=True) }}
8487

8588
@dataclasses.dataclass

noxfile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ def showcase_library(
365365
"-r",
366366
constraints_path,
367367
)
368+
# Exclude `google-auth==2.40.0` which contains a regression
369+
# https://github.com/googleapis/gapic-generator-python/issues/2385
370+
session.install(
371+
"--no-cache-dir",
372+
"--force-reinstall",
373+
"--upgrade",
374+
"google-auth[aiohttp]!=2.40.0",
375+
)
368376
else:
369377
# The ads templates do not have constraints files.
370378
# See https://github.com/googleapis/gapic-generator-python/issues/1788

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from google.api_core import retry_async as retries
2727
from google.auth import credentials as ga_credentials # type: ignore
2828
from google.oauth2 import service_account # type: ignore
29+
import google.protobuf
2930

3031

3132
try:
@@ -3213,6 +3214,9 @@ async def __aexit__(self, exc_type, exc, tb):
32133214

32143215
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
32153216

3217+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
3218+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
3219+
32163220

32173221
__all__ = (
32183222
"AssetServiceAsyncClient",

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from google.auth.transport.grpc import SslCredentials # type: ignore
3434
from google.auth.exceptions import MutualTLSChannelError # type: ignore
3535
from google.oauth2 import service_account # type: ignore
36+
import google.protobuf
3637

3738
try:
3839
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
@@ -3619,6 +3620,8 @@ def get_operation(
36193620

36203621
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
36213622

3623+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
3624+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
36223625

36233626
__all__ = (
36243627
"AssetServiceClient",

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
from google.api_core import operations_v1
2727
from google.auth import credentials as ga_credentials # type: ignore
2828
from google.oauth2 import service_account # type: ignore
29+
import google.protobuf
2930

3031
from google.cloud.asset_v1.types import asset_service
3132
from google.longrunning import operations_pb2 # type: ignore
3233
from google.protobuf import empty_pb2 # type: ignore
3334

3435
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)
3536

37+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
38+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
39+
3640

3741
class AssetServiceTransport(abc.ABC):
3842
"""Abstract transport class for AssetService."""

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from google.api_core import rest_helpers
2424
from google.api_core import rest_streaming
2525
from google.api_core import gapic_v1
26+
import google.protobuf
2627

2728
from google.protobuf import json_format
2829
from google.api_core import operations_v1
@@ -60,6 +61,9 @@
6061
rest_version=f"requests@{requests_version}",
6162
)
6263

64+
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
65+
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
66+
6367

6468
class AssetServiceRestInterceptor:
6569
"""Interceptor for AssetService.

0 commit comments

Comments
 (0)