Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4e3138c
feat: add support for reading google.api.api_version
parthea Apr 10, 2024
009fc71
add showcase tests; clean up code
parthea Apr 29, 2024
b574ed1
remove noise in diff
parthea Apr 29, 2024
dd96aa4
remove noise in diff
parthea Apr 29, 2024
de4ba22
remove noise in diff
parthea Apr 29, 2024
28e6991
use gapic-showcase 0.35.0
parthea Apr 29, 2024
fca5b55
update comment
parthea Apr 29, 2024
8cd648a
add constraints to ads templates
parthea Apr 30, 2024
35755b7
add new line
parthea Apr 30, 2024
ea5666f
update google-api-core and googleapis-common-protos setup.py to match…
parthea Apr 30, 2024
79f1767
update grpc in setup.py to match the one in googleads/google-ads-python
parthea Apr 30, 2024
7eb5c92
style
parthea Apr 30, 2024
c0b7810
coverage
parthea Apr 30, 2024
d52e78e
fix test
parthea Apr 30, 2024
5129f61
mypy
parthea Apr 30, 2024
ab18eea
coverage
parthea Apr 30, 2024
6946304
revert
parthea Apr 30, 2024
6dfa53c
remove test code
parthea May 1, 2024
2e666ea
update copyright year
parthea May 2, 2024
1e6e96e
address review feedback
parthea May 2, 2024
6416902
fix comment
parthea May 2, 2024
68b4010
revert constraints files for ads
parthea May 2, 2024
178c964
remove test code
parthea May 2, 2024
a5d6109
address review feedback
parthea May 4, 2024
109edd4
address review feedback
parthea May 4, 2024
12ff101
revert WORKSPACE
parthea May 4, 2024
ca95a6b
clean up
parthea May 4, 2024
0e669ab
Update gapic/templates/%namespace/%name_%version/%sub/services/%servi…
parthea May 7, 2024
7957ded
convert to symlink
parthea May 7, 2024
542e4e1
Revert "convert to symlink"
parthea May 7, 2024
0f68169
Update gapic/templates/%namespace/%name_%version/%sub/services/%servi…
parthea May 7, 2024
921f20b
address review feedback
parthea May 7, 2024
16402e1
Revert "Update gapic/templates/%namespace/%name_%version/%sub/service…
parthea May 7, 2024
555cff7
fix build
parthea May 7, 2024
f150e67
Address review feedback
parthea May 7, 2024
220f873
Address review feedback
parthea May 7, 2024
a62b313
address review feedback
parthea May 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ class {{ service.client_name }}Meta(type):


class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
"""{{ service.meta.doc|rst(width=72, indent=4) }}"""
"""{{ service.meta.doc|rst(width=72, indent=4) }}{% if service.version|length %}
This class implements API version {{ service.version }}."""
{% else %}"""
{% endif %}
Comment thread
vchudnov-g marked this conversation as resolved.
Outdated

@staticmethod
def _get_default_mtls_endpoint(api_endpoint):
Expand Down Expand Up @@ -476,6 +479,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
)
{% endif %}

{% if service.version %}
metadata = tuple(metadata) + (
gapic_v1.version_header.to_grpc_metadata("{{ service.version }}"),
)
{% endif %}
{#
Automatically populate UUID4 fields according to
https://google.aip.dev/client-libraries/4235 when the
Expand Down
3 changes: 2 additions & 1 deletion gapic/ads-templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ else:
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 2.10.0, < 3.0.0dev",
"google-api-core[grpc] @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 2.10.0, < 3.0.0dev",
"google-auth >= 2.14.1, <3.0.0dev",
"googleapis-common-protos >= 1.53.0",
"grpcio >= 1.10.0",
Expand Down
11 changes: 11 additions & 0 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,17 @@ def host(self) -> str:
return self.options.Extensions[client_pb2.default_host]
return ''

@property
def version(self) -> str:
"""Return the API version for this service, if specified.

Returns:
str: The API version for this service.
"""
if self.options.Extensions[client_pb2.api_version]:
return self.options.Extensions[client_pb2.api_version]
return ''

@property
def shortname(self) -> str:
"""Return the API short name. DRIFT uses this to identify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
)
{% endif %} {# method.explicit_routing #}

{% if service.version %}
metadata = tuple(metadata) + (
gapic_v1.version_header.to_grpc_metadata("{{ service.version }}"),
)
{% endif %}

{{ auto_populate_uuid4_fields(api, method) }}

# Validate the universe domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ from .client import {{ service.client_name }}

{# TODO(yon-mg): handle rest transport async client interaction #}
class {{ service.async_client_name }}:
"""{{ service.meta.doc|rst(width=72, indent=4) }}"""
"""{{ service.meta.doc|rst(width=72, indent=4) }}{% if service.version|length %}
This class implements API version {{ service.version }}."""
{% else %}"""
Comment thread
vchudnov-g marked this conversation as resolved.
Outdated
{% endif %}

_client: {{ service.client_name }}

Expand Down Expand Up @@ -388,6 +391,12 @@ class {{ service.async_client_name }}:
)
{% endif %}

{% if service.version %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good if we could call this code in the _client_macros.j2 file, so we reduce duplication. Maybe a separate macro call set_version_header(service.version), and the macro could take care of the conditional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 009fc71

metadata = tuple(metadata) + (
gapic_v1.version_header.to_grpc_metadata("{{ service.version }}")
)
{% endif %}

{{ macros.auto_populate_uuid4_fields(api, method) }}

# Validate the universe domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class {{ service.client_name }}Meta(type):


class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
"""{{ service.meta.doc|rst(width=72, indent=4) }}"""
"""{{ service.meta.doc|rst(width=72, indent=4) }}{% if service.version|length %}
This class implements API version {{ service.version }}."""
{% else %}"""
Comment thread
vchudnov-g marked this conversation as resolved.
Outdated
{% endif %}

@staticmethod
def _get_default_mtls_endpoint(api_endpoint):
Expand Down
3 changes: 2 additions & 1 deletion gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ else:
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
"google-api-core[grpc] @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
# Exclude incompatible versions of `google-auth`
# See https://github.com/googleapis/google-cloud-python/issues/12364
"google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0",
Expand Down
1 change: 0 additions & 1 deletion gapic/templates/testing/_default_constraints.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% from '_pypi_packages.j2' import pypi_packages %}
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
Comment thread
parthea marked this conversation as resolved.
proto-plus
protobuf
{% for package_tuple, package_info in pypi_packages.items() %}
Expand Down
1 change: 0 additions & 1 deletion gapic/templates/testing/constraints-3.7.txt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
google-api-core==1.34.1
Comment thread
parthea marked this conversation as resolved.
google-auth==2.14.1
proto-plus==1.22.3
protobuf==3.19.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'):
{% endif %}
{% endwith %}{# auto_populated_field_sample_value #}

{% if service.version %}
{% for mode in ["", "async"] %}
{% if mode == "async" %}
async def test_{{ method_name }}_api_version_header_async():
client = {{ service.async_client_name }}(credentials=ga_credentials.AnonymousCredentials())
{% else %}
def test_{{ method_name }}_api_version_header():
client = {{ service.client_name }}(credentials=ga_credentials.AnonymousCredentials())
{% endif %}
# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.{{ method.transport_safe_name|snake_case }}),
'__call__'
) as call:
{% if mode == "async" %}
await client.{{ method_name }}()
{% else %}
client.{{ method_name }}()
{% endif %}

# Establish that the api version header was sent.
_, _, kw = call.mock_calls[0]
assert kw['metadata'][0] == (gapic_v1.version_header.API_VERSION_METADATA_KEY, "{{ service.version }}")
{% endfor %}{# mode #}
{% endif %}{# service.version #}

{% if not method.client_streaming %}
def test_{{ method_name }}_empty_call():
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
# Ensure that the lower bounds of these dependencies match what we have in the
# templated setup.py.j2: https://github.com/googleapis/gapic-generator-python/blob/main/gapic/templates/setup.py.j2
"click >= 6.7",
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
"google-api-core @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
Comment thread
parthea marked this conversation as resolved.
Outdated
"googleapis-common-protos >= 1.55.0",
"grpcio >= 1.24.3",
# 2.11.0 is required which adds the `default` argument to `jinja-filters.map()`
Expand Down
3 changes: 3 additions & 0 deletions test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def make_service(
visible_resources: typing.Optional[
typing.Mapping[str, wrappers.CommonResource]
] = None,
version: str = "",
) -> wrappers.Service:
visible_resources = visible_resources or {}
# Define a service descriptor, and set a host and oauth scopes if
Expand All @@ -40,6 +41,8 @@ def make_service(
if host:
service_pb.options.Extensions[client_pb2.default_host] = host
service_pb.options.Extensions[client_pb2.oauth_scopes] = ','.join(scopes)
if version:
service_pb.options.Extensions[client_pb2.api_version] = version

# Return a service object to test.
return wrappers.Service(
Expand Down
16 changes: 16 additions & 0 deletions tests/fragments/google/api/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ extend google.protobuf.ServiceOptions {
// ...
// }
string oauth_scopes = 1050;

// The API version of this service, which should be sent by version-aware
// clients to the service. This allows services to abide by the schema and
// behavior of the service at the time this API version was deployed.
// The format of the API version must be treated as opaque by clients.
// Services may use a format with an apparent structure, but clients must
// not rely on this to determine components within an API version, or attempt
// to construct other valid API versions. Note that this is for upcoming
// functionality and may not be implemented for all services.
//
// Example:
//
// service Foo {
// option (google.api.api_version) = "v1_20230821_preview";
// }
string api_version = 525000001;
}
37 changes: 37 additions & 0 deletions tests/fragments/test_api_version.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2023 Google LLC
Comment thread
parthea marked this conversation as resolved.
Outdated
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.fragment;

import "google/protobuf/struct.proto";
import "google/api/client.proto";

service MyServiceWithVersion {
option (google.api.api_version) = "v1_20230601";
option (google.api.default_host) = "my.example.com";

rpc MyMethod(MethodRequest) returns (MethodResponse) {
option (google.api.method_signature) = "parameter";
}
}

message MethodRequest {
google.protobuf.Value parameter = 1;
}

message MethodResponse {
google.protobuf.Value result = 1;
}
3 changes: 2 additions & 1 deletion tests/integration/goldens/asset/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
"google-api-core[grpc] @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
# Exclude incompatible versions of `google-auth`
# See https://github.com/googleapis/google-cloud-python/issues/12364
"google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
google-api-core==1.34.1
google-auth==2.14.1
proto-plus==1.22.3
protobuf==3.19.5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
google-cloud-access-context-manager
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/goldens/credentials/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
"google-api-core[grpc] @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
# Exclude incompatible versions of `google-auth`
# See https://github.com/googleapis/google-cloud-python/issues/12364
"google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
google-api-core==1.34.1
google-auth==2.14.1
proto-plus==1.22.3
protobuf==3.19.5
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
3 changes: 2 additions & 1 deletion tests/integration/goldens/eventarc/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
release_status = "Development Status :: 5 - Production/Stable"

dependencies = [
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
"google-api-core[grpc] @ git+https://github.com/googleapis/python-api-core.git@add-api-version-header",
#"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
# Exclude incompatible versions of `google-auth`
# See https://github.com/googleapis/google-cloud-python/issues/12364
"google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# This constraints file is required for unit tests.
# List all library dependencies and extras in this file.
google-api-core
proto-plus
protobuf
grpc-google-iam-v1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Pin the version to the lower bound.
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev",
# Then this file should have google-cloud-foo==1.14.0
google-api-core==1.34.1
google-auth==2.14.1
proto-plus==1.22.3
protobuf==3.19.5
Expand Down
Loading