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

Commit

Permalink
feat: add context manager support in client (#93)
Browse files Browse the repository at this point in the history
- [ ] 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: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 7, 2021
1 parent ff106ef commit 5df0cf1
Show file tree
Hide file tree
Showing 32 changed files with 370 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,12 @@ async def import_catalog_items(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def create_catalog_item(
Expand Down Expand Up @@ -879,6 +876,19 @@ def import_catalog_items(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,8 @@ def import_catalog_items(
)
return self._stubs["import_catalog_items"]

def close(self):
self.grpc_channel.close()


__all__ = ("CatalogServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,8 @@ def import_catalog_items(
)
return self._stubs["import_catalog_items"]

def close(self):
return self.grpc_channel.close()


__all__ = ("CatalogServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ async def delete_prediction_api_key_registration(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def create_prediction_api_key_registration(
Expand Down Expand Up @@ -650,6 +647,19 @@ def delete_prediction_api_key_registration(
request, retry=retry, timeout=timeout, metadata=metadata,
)

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def create_prediction_api_key_registration(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,8 @@ def delete_prediction_api_key_registration(
)
return self._stubs["delete_prediction_api_key_registration"]

def close(self):
self.grpc_channel.close()


__all__ = ("PredictionApiKeyRegistryGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,8 @@ def delete_prediction_api_key_registration(
)
return self._stubs["delete_prediction_api_key_registration"]

def close(self):
return self.grpc_channel.close()


__all__ = ("PredictionApiKeyRegistryGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ async def predict(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def predict(
Expand Down Expand Up @@ -491,6 +488,19 @@ def predict(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def predict(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,8 @@ def predict(
)
return self._stubs["predict"]

def close(self):
self.grpc_channel.close()


__all__ = ("PredictionServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,8 @@ def predict(
)
return self._stubs["predict"]

def close(self):
return self.grpc_channel.close()


__all__ = ("PredictionServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@ async def import_user_events(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def write_user_event(
Expand Down Expand Up @@ -981,6 +978,19 @@ def import_user_events(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,8 @@ def import_user_events(
)
return self._stubs["import_user_events"]

def close(self):
self.grpc_channel.close()


__all__ = ("UserEventServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -408,5 +408,8 @@ def import_user_events(
)
return self._stubs["import_user_events"]

def close(self):
return self.grpc_channel.close()


__all__ = ("UserEventServiceGrpcAsyncIOTransport",)
3 changes: 3 additions & 0 deletions google/cloud/recommendationengine_v1beta1/types/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CatalogItem(proto.Message):

class CategoryHierarchy(proto.Message):
r"""Category represents catalog item category hierarchy.
Attributes:
categories (Sequence[str]):
Required. Catalog item categories. Each
Expand Down Expand Up @@ -172,6 +173,7 @@ class StockState(proto.Enum):

class ExactPrice(proto.Message):
r"""Exact product price.
Attributes:
display_price (float):
Optional. Display price of the product.
Expand Down Expand Up @@ -214,6 +216,7 @@ class PriceRange(proto.Message):

class Image(proto.Message):
r"""Catalog item thumbnail/detail image.
Attributes:
uri (str):
Required. URL of the image with a length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

class CreateCatalogItemRequest(proto.Message):
r"""Request message for CreateCatalogItem method.
Attributes:
parent (str):
Required. The parent catalog resource name, such as
Expand All @@ -48,6 +49,7 @@ class CreateCatalogItemRequest(proto.Message):

class GetCatalogItemRequest(proto.Message):
r"""Request message for GetCatalogItem method.
Attributes:
name (str):
Required. Full resource name of catalog item, such as
Expand All @@ -59,6 +61,7 @@ class GetCatalogItemRequest(proto.Message):

class ListCatalogItemsRequest(proto.Message):
r"""Request message for ListCatalogItems method.
Attributes:
parent (str):
Required. The parent catalog resource name, such as
Expand All @@ -83,6 +86,7 @@ class ListCatalogItemsRequest(proto.Message):

class ListCatalogItemsResponse(proto.Message):
r"""Response message for ListCatalogItems method.
Attributes:
catalog_items (Sequence[google.cloud.recommendationengine_v1beta1.types.CatalogItem]):
The catalog items.
Expand All @@ -104,6 +108,7 @@ def raw_page(self):

class UpdateCatalogItemRequest(proto.Message):
r"""Request message for UpdateCatalogItem method.
Attributes:
name (str):
Required. Full resource name of catalog item, such as
Expand All @@ -126,6 +131,7 @@ class UpdateCatalogItemRequest(proto.Message):

class DeleteCatalogItemRequest(proto.Message):
r"""Request message for DeleteCatalogItem method.
Attributes:
name (str):
Required. Full resource name of catalog item, such as
Expand Down
Loading

0 comments on commit 5df0cf1

Please sign in to comment.