Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit c403d1d

Browse files
feat: add context manager support in client (#240)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent ed2bc71 commit c403d1d

Some content is hidden

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

48 files changed

+537
-24
lines changed

google/cloud/datacatalog_v1/services/data_catalog/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,12 @@ async def test_iam_permissions(
29112911
# Done; return the response.
29122912
return response
29132913

2914+
async def __aenter__(self):
2915+
return self
2916+
2917+
async def __aexit__(self, exc_type, exc, tb):
2918+
await self.transport.close()
2919+
29142920

29152921
try:
29162922
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/datacatalog_v1/services/data_catalog/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,7 @@ def __init__(
454454
client_cert_source_for_mtls=client_cert_source_func,
455455
quota_project_id=client_options.quota_project_id,
456456
client_info=client_info,
457-
always_use_jwt_access=(
458-
Transport == type(self).get_transport_class("grpc")
459-
or Transport == type(self).get_transport_class("grpc_asyncio")
460-
),
457+
always_use_jwt_access=True,
461458
)
462459

463460
def search_catalog(
@@ -3120,6 +3117,19 @@ def test_iam_permissions(
31203117
# Done; return the response.
31213118
return response
31223119

3120+
def __enter__(self):
3121+
return self
3122+
3123+
def __exit__(self, type, value, traceback):
3124+
"""Releases underlying transport's resources.
3125+
3126+
.. warning::
3127+
ONLY use as a context manager if the transport is NOT shared
3128+
with other clients! Exiting the with block will CLOSE the transport
3129+
and may cause errors in other clients!
3130+
"""
3131+
self.transport.close()
3132+
31233133

31243134
try:
31253135
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/datacatalog_v1/services/data_catalog/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ def _prep_wrapped_messages(self, client_info):
344344
),
345345
}
346346

347+
def close(self):
348+
"""Closes resources associated with the transport.
349+
350+
.. warning::
351+
Only call this method if the transport is NOT shared
352+
with other clients - this may cause errors in other clients!
353+
"""
354+
raise NotImplementedError()
355+
347356
@property
348357
def search_catalog(
349358
self,

google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,5 +1157,8 @@ def test_iam_permissions(
11571157
)
11581158
return self._stubs["test_iam_permissions"]
11591159

1160+
def close(self):
1161+
self.grpc_channel.close()
1162+
11601163

11611164
__all__ = ("DataCatalogGrpcTransport",)

google/cloud/datacatalog_v1/services/data_catalog/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,5 +1188,8 @@ def test_iam_permissions(
11881188
)
11891189
return self._stubs["test_iam_permissions"]
11901190

1191+
def close(self):
1192+
return self.grpc_channel.close()
1193+
11911194

11921195
__all__ = ("DataCatalogGrpcAsyncIOTransport",)

google/cloud/datacatalog_v1/services/policy_tag_manager/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,12 @@ async def test_iam_permissions(
12381238
# Done; return the response.
12391239
return response
12401240

1241+
async def __aenter__(self):
1242+
return self
1243+
1244+
async def __aexit__(self, exc_type, exc, tb):
1245+
await self.transport.close()
1246+
12411247

12421248
try:
12431249
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/datacatalog_v1/services/policy_tag_manager/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,7 @@ def __init__(
374374
client_cert_source_for_mtls=client_cert_source_func,
375375
quota_project_id=client_options.quota_project_id,
376376
client_info=client_info,
377-
always_use_jwt_access=(
378-
Transport == type(self).get_transport_class("grpc")
379-
or Transport == type(self).get_transport_class("grpc_asyncio")
380-
),
377+
always_use_jwt_access=True,
381378
)
382379

383380
def create_taxonomy(
@@ -1443,6 +1440,19 @@ def test_iam_permissions(
14431440
# Done; return the response.
14441441
return response
14451442

1443+
def __enter__(self):
1444+
return self
1445+
1446+
def __exit__(self, type, value, traceback):
1447+
"""Releases underlying transport's resources.
1448+
1449+
.. warning::
1450+
ONLY use as a context manager if the transport is NOT shared
1451+
with other clients! Exiting the with block will CLOSE the transport
1452+
and may cause errors in other clients!
1453+
"""
1454+
self.transport.close()
1455+
14461456

14471457
try:
14481458
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/datacatalog_v1/services/policy_tag_manager/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ def _prep_wrapped_messages(self, client_info):
200200
),
201201
}
202202

203+
def close(self):
204+
"""Closes resources associated with the transport.
205+
206+
.. warning::
207+
Only call this method if the transport is NOT shared
208+
with other clients - this may cause errors in other clients!
209+
"""
210+
raise NotImplementedError()
211+
203212
@property
204213
def create_taxonomy(
205214
self,

google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,5 +597,8 @@ def test_iam_permissions(
597597
)
598598
return self._stubs["test_iam_permissions"]
599599

600+
def close(self):
601+
self.grpc_channel.close()
602+
600603

601604
__all__ = ("PolicyTagManagerGrpcTransport",)

google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,5 +610,8 @@ def test_iam_permissions(
610610
)
611611
return self._stubs["test_iam_permissions"]
612612

613+
def close(self):
614+
return self.grpc_channel.close()
615+
613616

614617
__all__ = ("PolicyTagManagerGrpcAsyncIOTransport",)

0 commit comments

Comments
 (0)