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

feat: add context manager support in client #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -529,6 +529,12 @@ async def get_default_branch(
# 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
18 changes: 14 additions & 4 deletions google/cloud/retail_v2/services/catalog_service/client.py
Expand Up @@ -364,10 +364,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 list_catalogs(
Expand Down Expand Up @@ -732,6 +729,19 @@ def get_default_branch(
# 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
Expand Up @@ -168,6 +168,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 list_catalogs(
self,
Expand Down
Expand Up @@ -383,5 +383,8 @@ def get_default_branch(
)
return self._stubs["get_default_branch"]

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


__all__ = ("CatalogServiceGrpcTransport",)
Expand Up @@ -391,5 +391,8 @@ def get_default_branch(
)
return self._stubs["get_default_branch"]

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


__all__ = ("CatalogServiceGrpcAsyncIOTransport",)
Expand Up @@ -291,6 +291,12 @@ async def import_completion_data(
# 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
18 changes: 14 additions & 4 deletions google/cloud/retail_v2/services/completion_service/client.py
Expand Up @@ -354,10 +354,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 complete_query(
Expand Down Expand Up @@ -484,6 +481,19 @@ def import_completion_data(
# 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
Expand Up @@ -165,6 +165,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
Expand Up @@ -318,5 +318,8 @@ def import_completion_data(
)
return self._stubs["import_completion_data"]

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


__all__ = ("CompletionServiceGrpcTransport",)
Expand Up @@ -323,5 +323,8 @@ def import_completion_data(
)
return self._stubs["import_completion_data"]

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


__all__ = ("CompletionServiceGrpcAsyncIOTransport",)
Expand Up @@ -208,6 +208,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
18 changes: 14 additions & 4 deletions google/cloud/retail_v2/services/prediction_service/client.py
Expand Up @@ -351,10 +351,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 @@ -406,6 +403,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
Expand Up @@ -157,6 +157,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
Expand Up @@ -253,5 +253,8 @@ def predict(
)
return self._stubs["predict"]

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


__all__ = ("PredictionServiceGrpcTransport",)
Expand Up @@ -257,5 +257,8 @@ def predict(
)
return self._stubs["predict"]

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


__all__ = ("PredictionServiceGrpcAsyncIOTransport",)
Expand Up @@ -1115,6 +1115,12 @@ async def remove_fulfillment_places(
# 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
18 changes: 14 additions & 4 deletions google/cloud/retail_v2/services/product_service/client.py
Expand Up @@ -378,10 +378,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_product(
Expand Down Expand Up @@ -1317,6 +1314,19 @@ def remove_fulfillment_places(
# 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
Expand Up @@ -203,6 +203,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
Expand Up @@ -575,5 +575,8 @@ def remove_fulfillment_places(
)
return self._stubs["remove_fulfillment_places"]

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


__all__ = ("ProductServiceGrpcTransport",)
Expand Up @@ -591,5 +591,8 @@ def remove_fulfillment_places(
)
return self._stubs["remove_fulfillment_places"]

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


__all__ = ("ProductServiceGrpcAsyncIOTransport",)
Expand Up @@ -236,6 +236,12 @@ async def search(
# 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
18 changes: 14 additions & 4 deletions google/cloud/retail_v2/services/search_service/client.py
Expand Up @@ -370,10 +370,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 search(
Expand Down Expand Up @@ -444,6 +441,19 @@ def search(
# 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
Expand Up @@ -157,6 +157,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 search(
self,
Expand Down
Expand Up @@ -261,5 +261,8 @@ def search(
)
return self._stubs["search"]

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


__all__ = ("SearchServiceGrpcTransport",)
Expand Up @@ -266,5 +266,8 @@ def search(
)
return self._stubs["search"]

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


__all__ = ("SearchServiceGrpcAsyncIOTransport",)