Skip to content

Commit

Permalink
feat: add context manager support in client (#41)
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] authored Oct 8, 2021
1 parent 8e92ebf commit 9bbc14a
Show file tree
Hide file tree
Showing 43 changed files with 573 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ async def launch_flex_template(
# 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 @@ -332,10 +332,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 launch_flex_template(
Expand Down Expand Up @@ -382,6 +379,19 @@ def launch_flex_template(
# 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 @@ -166,6 +166,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 launch_flex_template(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,8 @@ def launch_flex_template(
)
return self._stubs["launch_flex_template"]

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


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

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


__all__ = ("FlexTemplatesServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ async def snapshot_job(
# 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 @@ -333,10 +333,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_job(
Expand Down Expand Up @@ -701,6 +698,19 @@ def snapshot_job(
# 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 @@ -185,6 +185,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_job(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,5 +428,8 @@ def snapshot_job(self) -> Callable[[jobs.SnapshotJobRequest], snapshots.Snapshot
)
return self._stubs["snapshot_job"]

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


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

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


__all__ = ("JobsV1Beta3GrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ async def list_job_messages(
# 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 @@ -330,10 +330,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_job_messages(
Expand Down Expand Up @@ -400,6 +397,19 @@ def list_job_messages(
# 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 @@ -164,6 +164,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_job_messages(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,8 @@ def list_job_messages(
)
return self._stubs["list_job_messages"]

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


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

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


__all__ = ("MessagesV1Beta3GrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ async def get_stage_execution_details(
# 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 @@ -331,10 +331,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 get_job_metrics(
Expand Down Expand Up @@ -515,6 +512,19 @@ def get_stage_execution_details(
# 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 @@ -174,6 +174,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 get_job_metrics(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,8 @@ def get_stage_execution_details(
)
return self._stubs["get_stage_execution_details"]

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


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

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


__all__ = ("MetricsV1Beta3GrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ async def list_snapshots(
# 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 @@ -331,10 +331,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 get_snapshot(
Expand Down Expand Up @@ -461,6 +458,19 @@ def list_snapshots(
# 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 @@ -170,6 +170,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 get_snapshot(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,8 @@ def list_snapshots(
)
return self._stubs["list_snapshots"]

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


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

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


__all__ = ("SnapshotsV1Beta3GrpcAsyncIOTransport",)
Loading

0 comments on commit 9bbc14a

Please sign in to comment.