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

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add context manager support in client (#156)
- [ ] 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 8, 2021
1 parent 95025fa commit 4332378
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 4 deletions.
Expand Up @@ -3264,6 +3264,12 @@ async def list_evaluation_jobs(
# 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
Expand Up @@ -479,10 +479,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_dataset(
Expand Down Expand Up @@ -3355,6 +3352,19 @@ def list_evaluation_jobs(
# 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 @@ -537,6 +537,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 @@ -1224,5 +1224,8 @@ def list_evaluation_jobs(
)
return self._stubs["list_evaluation_jobs"]

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


__all__ = ("DataLabelingServiceGrpcTransport",)
Expand Up @@ -1266,5 +1266,8 @@ def list_evaluation_jobs(
)
return self._stubs["list_evaluation_jobs"]

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


__all__ = ("DataLabelingServiceGrpcAsyncIOTransport",)
15 changes: 15 additions & 0 deletions google/cloud/datalabeling_v1beta1/types/annotation.py
Expand Up @@ -121,6 +121,7 @@ class Annotation(proto.Message):

class AnnotationValue(proto.Message):
r"""Annotation value for an example.
Attributes:
image_classification_annotation (google.cloud.datalabeling_v1beta1.types.ImageClassificationAnnotation):
Annotation value for image classification
Expand Down Expand Up @@ -204,6 +205,7 @@ class AnnotationValue(proto.Message):

class ImageClassificationAnnotation(proto.Message):
r"""Image classification annotation definition.
Attributes:
annotation_spec (google.cloud.datalabeling_v1beta1.types.AnnotationSpec):
Label of image.
Expand Down Expand Up @@ -248,6 +250,7 @@ class NormalizedVertex(proto.Message):

class BoundingPoly(proto.Message):
r"""A bounding polygon in the image.
Attributes:
vertices (Sequence[google.cloud.datalabeling_v1beta1.types.Vertex]):
The bounding polygon vertices.
Expand All @@ -258,6 +261,7 @@ class BoundingPoly(proto.Message):

class NormalizedBoundingPoly(proto.Message):
r"""Normalized bounding polygon.
Attributes:
normalized_vertices (Sequence[google.cloud.datalabeling_v1beta1.types.NormalizedVertex]):
The bounding polygon normalized vertices.
Expand Down Expand Up @@ -294,6 +298,7 @@ class ImageBoundingPolyAnnotation(proto.Message):

class Polyline(proto.Message):
r"""A line with multiple line segments.
Attributes:
vertices (Sequence[google.cloud.datalabeling_v1beta1.types.Vertex]):
The polyline vertices.
Expand All @@ -304,6 +309,7 @@ class Polyline(proto.Message):

class NormalizedPolyline(proto.Message):
r"""Normalized polyline.
Attributes:
normalized_vertices (Sequence[google.cloud.datalabeling_v1beta1.types.NormalizedVertex]):
The normalized polyline vertices.
Expand All @@ -316,6 +322,7 @@ class NormalizedPolyline(proto.Message):

class ImagePolylineAnnotation(proto.Message):
r"""A polyline for the image annotation.
Attributes:
polyline (google.cloud.datalabeling_v1beta1.types.Polyline):
Expand All @@ -336,6 +343,7 @@ class ImagePolylineAnnotation(proto.Message):

class ImageSegmentationAnnotation(proto.Message):
r"""Image segmentation annotation.
Attributes:
annotation_colors (Sequence[google.cloud.datalabeling_v1beta1.types.ImageSegmentationAnnotation.AnnotationColorsEntry]):
The mapping between rgb color and annotation
Expand All @@ -360,6 +368,7 @@ class ImageSegmentationAnnotation(proto.Message):

class TextClassificationAnnotation(proto.Message):
r"""Text classification annotation.
Attributes:
annotation_spec (google.cloud.datalabeling_v1beta1.types.AnnotationSpec):
Label of the text.
Expand All @@ -372,6 +381,7 @@ class TextClassificationAnnotation(proto.Message):

class TextEntityExtractionAnnotation(proto.Message):
r"""Text entity extraction annotation.
Attributes:
annotation_spec (google.cloud.datalabeling_v1beta1.types.AnnotationSpec):
Label of the text entities.
Expand All @@ -389,6 +399,7 @@ class TextEntityExtractionAnnotation(proto.Message):

class SequentialSegment(proto.Message):
r"""Start and end position in a sequence (e.g. text segment).
Attributes:
start (int):
Start position (inclusive).
Expand Down Expand Up @@ -425,6 +436,7 @@ class TimeSegment(proto.Message):

class VideoClassificationAnnotation(proto.Message):
r"""Video classification annotation.
Attributes:
time_segment (google.cloud.datalabeling_v1beta1.types.TimeSegment):
The time segment of the video to which the
Expand Down Expand Up @@ -464,6 +476,7 @@ class ObjectTrackingFrame(proto.Message):

class VideoObjectTrackingAnnotation(proto.Message):
r"""Video object tracking annotation.
Attributes:
annotation_spec (google.cloud.datalabeling_v1beta1.types.AnnotationSpec):
Label of the object tracked in this
Expand All @@ -487,6 +500,7 @@ class VideoObjectTrackingAnnotation(proto.Message):

class VideoEventAnnotation(proto.Message):
r"""Video event annotation.
Attributes:
annotation_spec (google.cloud.datalabeling_v1beta1.types.AnnotationSpec):
Label of the event in this annotation.
Expand All @@ -503,6 +517,7 @@ class VideoEventAnnotation(proto.Message):

class AnnotationMetadata(proto.Message):
r"""Additional information associated with the annotation.
Attributes:
operator_metadata (google.cloud.datalabeling_v1beta1.types.OperatorMetadata):
Metadata related to human labeling.
Expand Down

0 comments on commit 4332378

Please sign in to comment.