Skip to content

Commit 5f62265

Browse files
authored
Merge branch 'main' into add-protobuf-runtime
2 parents b59e0fa + 3aa67a5 commit 5f62265

File tree

111 files changed

+7075
-1708
lines changed

Some content is hidden

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

111 files changed

+7075
-1708
lines changed

.github/sync-repo-settings.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ branchProtectionRules:
1515
- 'mypy (3.13)'
1616
- 'showcase (3.7, showcase)'
1717
- 'showcase (3.13, showcase)'
18-
- 'showcase (3.7, showcase_alternative_templates)'
19-
- 'showcase (3.13, showcase_alternative_templates)'
2018
- 'showcase (3.7, showcase_w_rest_async)'
2119
- 'showcase (3.13, showcase_w_rest_async)'
2220
# TODO(dovs): reenable these when the mtls tests have been debugged and fixed
2321
# See #1218 for details
2422
# - 'showcase-mtls (showcase_mtls)'
25-
# - 'showcase-mtls (showcase_mtls_alternative_templates)'
2623
- 'showcase-mypy'
2724
- 'showcase-mypy (_alternative_templates)'
2825
- 'showcase-unit (3.7)'

.github/workflows/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
matrix:
5858
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
5959
python: ["3.7", "3.13"]
60-
target: [showcase, showcase_alternative_templates, showcase_w_rest_async]
60+
target: [showcase, showcase_w_rest_async]
6161
logging_scope: ["", "google"]
6262

6363
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
@@ -102,7 +102,7 @@ jobs:
102102
if: ${{ false }} # TODO(dovs): reenable when #1218 is fixed
103103
strategy:
104104
matrix:
105-
target: [showcase_mtls, showcase_mtls_alternative_templates]
105+
target: [showcase_mtls]
106106
max-parallel: 1
107107
runs-on: ubuntu-latest
108108
steps:

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Changelog
22

33

4+
## [1.24.1](https://github.com/googleapis/gapic-generator-python/compare/v1.24.0...v1.24.1) (2025-04-17)
5+
6+
7+
### Bug Fixes
8+
9+
* Update generated docs to match synthtool templates ([3f62f31](https://github.com/googleapis/gapic-generator-python/commit/3f62f31d5146147c4bc6393fbeef18ce1d9a1a42))
10+
11+
## [1.24.0](https://github.com/googleapis/gapic-generator-python/compare/v1.23.6...v1.24.0) (2025-04-11)
12+
13+
14+
### Features
15+
16+
* Adds augmented pagination to account for BQ family of APIs ([#2372](https://github.com/googleapis/gapic-generator-python/issues/2372)) ([30cd1a4](https://github.com/googleapis/gapic-generator-python/commit/30cd1a49353048fc190114cfb7a73e14ec2eff31))
17+
18+
19+
### Bug Fixes
20+
21+
* Fixed internal method generation naming issues ([#2365](https://github.com/googleapis/gapic-generator-python/issues/2365)) ([868f201](https://github.com/googleapis/gapic-generator-python/commit/868f201957b271c9390bf41374897a2ce728a5e2))
22+
* Missing DEFAULT_HOST should still result in compiling code ([#2051](https://github.com/googleapis/gapic-generator-python/issues/2051)) ([dc6d4f7](https://github.com/googleapis/gapic-generator-python/commit/dc6d4f7ec0853557bb7c25a8276fbe262c5bda5d))
23+
424
## [1.23.6](https://github.com/googleapis/gapic-generator-python/compare/v1.23.5...v1.23.6) (2025-03-17)
525

626

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
# If your documentation needs a minimal Sphinx version, state it here.
4242
#
43-
# needs_sphinx = '1.0'
43+
needs_sphinx = "4.5.0"
4444

4545
# Add any Sphinx extension module names here, as strings. They can be
4646
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom

gapic/ads-templates/docs/conf.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ __version__ = "0.1.0"
2828
# -- General configuration ------------------------------------------------
2929

3030
# If your documentation needs a minimal Sphinx version, state it here.
31-
needs_sphinx = "4.0.1"
31+
needs_sphinx = "4.5.0"
3232

3333
# Add any Sphinx extension module names here, as strings. They can be
3434
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom

gapic/schema/wrappers.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,13 +1830,34 @@ def ident(self) -> metadata.Address:
18301830
"""Return the identifier data to be used in templates."""
18311831
return self.meta.address
18321832

1833+
def _validate_paged_field_size_type(self, page_field_size) -> bool:
1834+
"""Validates allowed paged_field_size type(s).
1835+
1836+
Confirms whether the paged_field_size.type is an allowed wrapper type:
1837+
The norm is for type to be int, but an additional check is included to
1838+
account for BigQuery legacy APIs which allowed UInt32Value and
1839+
Int32Value.
1840+
"""
1841+
1842+
pb_type = page_field_size.type
1843+
1844+
return pb_type == int or (
1845+
isinstance(pb_type, MessageType)
1846+
and pb_type.message_pb.name in {"UInt32Value", "Int32Value"}
1847+
)
1848+
18331849
@utils.cached_property
18341850
def paged_result_field(self) -> Optional[Field]:
1835-
"""Return the response pagination field if the method is paginated."""
1836-
# If the request field lacks any of the expected pagination fields,
1837-
# then the method is not paginated.
1851+
"""Return the response pagination field if the method is paginated.
1852+
1853+
The request field must have a page_token field and a page_size field (or
1854+
for legacy APIs, a max_results field) and the response field
1855+
must have a next_token_field and a repeated field.
1856+
1857+
For the purposes of supporting legacy APIs, additional wrapper types are
1858+
allowed.
1859+
"""
18381860

1839-
# The request must have page_token and next_page_token as they keep track of pages
18401861
for source, source_type, name in (
18411862
(self.input, str, "page_token"),
18421863
(self.output, str, "next_page_token"),
@@ -1845,13 +1866,18 @@ def paged_result_field(self) -> Optional[Field]:
18451866
if not field or field.type != source_type:
18461867
return None
18471868

1848-
# The request must have max_results or page_size
1869+
# The request must have page_size (or max_results if legacy API)
18491870
page_fields = (
18501871
self.input.fields.get("max_results", None),
18511872
self.input.fields.get("page_size", None),
18521873
)
18531874
page_field_size = next((field for field in page_fields if field), None)
1854-
if not page_field_size or page_field_size.type != int:
1875+
1876+
if not page_field_size:
1877+
return None
1878+
1879+
# Confirm whether the paged_field_size is an allowed type.
1880+
if not self._validate_paged_field_size_type(page_field_size=page_field_size):
18551881
return None
18561882

18571883
# Return the first repeated field.

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,42 @@ def _get_http_options():
264264
{% endmacro %}
265265

266266

267+
{% macro unary_request_interceptor_common(service) %}
268+
logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG)
269+
if logging_enabled: # pragma: NO COVER
270+
request_metadata = client_call_details.metadata
271+
if isinstance(request, proto.Message):
272+
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2293): Investigate if we can improve this logic
273+
or wait for next gen protobuf.
274+
#}
275+
request_payload = type(request).to_json(request)
276+
elif isinstance(request, google.protobuf.message.Message):
277+
request_payload = MessageToJson(request)
278+
else:
279+
request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
280+
281+
request_metadata = {
282+
key: value.decode("utf-8") if isinstance(value, bytes) else value
283+
for key, value in request_metadata
284+
}
285+
grpc_request = {
286+
"payload": request_payload,
287+
"requestMethod": "grpc",
288+
"metadata": dict(request_metadata),
289+
}
290+
_LOGGER.debug(
291+
f"Sending request for {client_call_details.method}",
292+
extra = {
293+
"serviceName": "{{ service.meta.address.proto }}",
294+
"rpcName": str(client_call_details.method),
295+
"request": grpc_request,
296+
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2275): logging `metadata` seems repetitive and may need to be cleaned up. We're including it within "request" for consistency with REST transport. #}
297+
"metadata": grpc_request["metadata"],
298+
},
299+
)
300+
{%- endmacro %}
301+
302+
267303
{% macro prep_wrapped_messages_async_method(api, service) %}
268304
def _prep_wrapped_messages(self, client_info):
269305
""" Precompute the wrapped methods, overriding the base class method to use async wrappers."""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class {{ service.name }}Transport(abc.ABC):
6565
{% endfor %}
6666
)
6767

68-
DEFAULT_HOST: str = {% if service.host %}'{{ service.host }}'{% else %}{{ '' }}{% endif %}
68+
DEFAULT_HOST: str = '{% if service.host %}{{ service.host }}{% endif %}'
6969

7070
def __init__(
7171
self, *,

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% extends '_base.py.j2' %}
22

3+
{% import "%namespace/%name_%version/%sub/services/%service/_shared_macros.j2" as shared_macros %}
4+
35
{% block content %}
46

57
import json
@@ -59,39 +61,7 @@ _LOGGER = std_logging.getLogger(__name__)
5961

6062
class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
6163
def intercept_unary_unary(self, continuation, client_call_details, request):
62-
logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG)
63-
if logging_enabled: # pragma: NO COVER
64-
request_metadata = client_call_details.metadata
65-
if isinstance(request, proto.Message):
66-
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2293): Investigate if we can improve this logic
67-
or wait for next gen protobuf.
68-
#}
69-
request_payload = type(request).to_json(request)
70-
elif isinstance(request, google.protobuf.message.Message):
71-
request_payload = MessageToJson(request)
72-
else:
73-
request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
74-
75-
request_metadata = {
76-
key: value.decode("utf-8") if isinstance(value, bytes) else value
77-
for key, value in request_metadata
78-
}
79-
grpc_request = {
80-
"payload": request_payload,
81-
"requestMethod": "grpc",
82-
"metadata": dict(request_metadata),
83-
}
84-
_LOGGER.debug(
85-
f"Sending request for {client_call_details.method}",
86-
extra = {
87-
"serviceName": "{{ service.meta.address.proto }}",
88-
"rpcName": client_call_details.method,
89-
"request": grpc_request,
90-
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2275): logging `metadata` seems repetitive and may need to be cleaned up. We're including it within "request" for consistency with REST transport. #}
91-
"metadata": grpc_request["metadata"],
92-
},
93-
)
94-
64+
{{ shared_macros.unary_request_interceptor_common(service) }}
9565
response = continuation(client_call_details, request)
9666
if logging_enabled: # pragma: NO COVER
9767
response_metadata = response.trailing_metadata()

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% extends '_base.py.j2' %}
22

3+
{% import "%namespace/%name_%version/%sub/services/%service/_shared_macros.j2" as shared_macros %}
4+
35
{% block content %}
46
{% import "%namespace/%name_%version/%sub/services/%service/_shared_macros.j2" as shared_macros %}
57

@@ -64,38 +66,7 @@ _LOGGER = std_logging.getLogger(__name__)
6466

6567
class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER
6668
async def intercept_unary_unary(self, continuation, client_call_details, request):
67-
logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG)
68-
if logging_enabled: # pragma: NO COVER
69-
request_metadata = client_call_details.metadata
70-
if isinstance(request, proto.Message):
71-
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2293): Investigate if we can improve this logic
72-
or wait for next gen protobuf.
73-
#}
74-
request_payload = type(request).to_json(request)
75-
elif isinstance(request, google.protobuf.message.Message):
76-
request_payload = MessageToJson(request)
77-
else:
78-
request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
79-
80-
request_metadata = {
81-
key: value.decode("utf-8") if isinstance(value, bytes) else value
82-
for key, value in request_metadata
83-
}
84-
grpc_request = {
85-
"payload": request_payload,
86-
"requestMethod": "grpc",
87-
"metadata": dict(request_metadata),
88-
}
89-
_LOGGER.debug(
90-
f"Sending request for {client_call_details.method}",
91-
extra = {
92-
"serviceName": "{{ service.meta.address.proto }}",
93-
"rpcName": str(client_call_details.method),
94-
"request": grpc_request,
95-
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2275): logging `metadata` seems repetitive and may need to be cleaned up. We're including it within "request" for consistency with REST transport.' #}
96-
"metadata": grpc_request["metadata"],
97-
},
98-
)
69+
{{ shared_macros.unary_request_interceptor_common(service) }}
9970
response = await continuation(client_call_details, request)
10071
if logging_enabled: # pragma: NO COVER
10172
response_metadata = await response.trailing_metadata()

0 commit comments

Comments
 (0)