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 (#240)
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 8, 2021
1 parent ed2bc71 commit c403d1d
Show file tree
Hide file tree
Showing 48 changed files with 537 additions and 24 deletions.
Expand Up @@ -2911,6 +2911,12 @@ async def test_iam_permissions(
# 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/datacatalog_v1/services/data_catalog/client.py
Expand Up @@ -454,10 +454,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_catalog(
Expand Down Expand Up @@ -3120,6 +3117,19 @@ def test_iam_permissions(
# 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 @@ -344,6 +344,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_catalog(
self,
Expand Down
Expand Up @@ -1157,5 +1157,8 @@ def test_iam_permissions(
)
return self._stubs["test_iam_permissions"]

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


__all__ = ("DataCatalogGrpcTransport",)
Expand Up @@ -1188,5 +1188,8 @@ def test_iam_permissions(
)
return self._stubs["test_iam_permissions"]

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


__all__ = ("DataCatalogGrpcAsyncIOTransport",)
Expand Up @@ -1238,6 +1238,12 @@ async def test_iam_permissions(
# 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/datacatalog_v1/services/policy_tag_manager/client.py
Expand Up @@ -374,10 +374,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_taxonomy(
Expand Down Expand Up @@ -1443,6 +1440,19 @@ def test_iam_permissions(
# 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 @@ -200,6 +200,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_taxonomy(
self,
Expand Down
Expand Up @@ -597,5 +597,8 @@ def test_iam_permissions(
)
return self._stubs["test_iam_permissions"]

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


__all__ = ("PolicyTagManagerGrpcTransport",)
Expand Up @@ -610,5 +610,8 @@ def test_iam_permissions(
)
return self._stubs["test_iam_permissions"]

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


__all__ = ("PolicyTagManagerGrpcAsyncIOTransport",)
Expand Up @@ -357,6 +357,12 @@ async def export_taxonomies(
# 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 @@ -355,10 +355,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 replace_taxonomy(
Expand Down Expand Up @@ -558,6 +555,19 @@ def export_taxonomies(
# 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 @@ -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 replace_taxonomy(
self,
Expand Down
Expand Up @@ -343,5 +343,8 @@ def export_taxonomies(
)
return self._stubs["export_taxonomies"]

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


__all__ = ("PolicyTagManagerSerializationGrpcTransport",)
Expand Up @@ -346,5 +346,8 @@ def export_taxonomies(
)
return self._stubs["export_taxonomies"]

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


__all__ = ("PolicyTagManagerSerializationGrpcAsyncIOTransport",)
2 changes: 2 additions & 0 deletions google/cloud/datacatalog_v1/types/bigquery.py
Expand Up @@ -28,6 +28,7 @@

class BigQueryConnectionSpec(proto.Message):
r"""Specification for the BigQuery connection.
Attributes:
connection_type (google.cloud.datacatalog_v1.types.BigQueryConnectionSpec.ConnectionType):
The type of the BigQuery connection.
Expand Down Expand Up @@ -81,6 +82,7 @@ class DatabaseType(proto.Enum):

class BigQueryRoutineSpec(proto.Message):
r"""Fields specific for BigQuery routines.
Attributes:
imported_libraries (Sequence[str]):
Paths of the imported libraries.
Expand Down
1 change: 1 addition & 0 deletions google/cloud/datacatalog_v1/types/data_source.py
Expand Up @@ -23,6 +23,7 @@

class DataSource(proto.Message):
r"""Physical location of an entry.
Attributes:
service (google.cloud.datacatalog_v1.types.DataSource.Service):
Service that physically stores the data.
Expand Down
1 change: 1 addition & 0 deletions google/cloud/datacatalog_v1/types/datacatalog.py
Expand Up @@ -786,6 +786,7 @@ class RoutineType(proto.Enum):

class Argument(proto.Message):
r"""Input or output argument of a function or stored procedure.
Attributes:
name (str):
The name of the argument. A return argument
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/datacatalog_v1/types/gcs_fileset_spec.py
Expand Up @@ -25,6 +25,7 @@

class GcsFilesetSpec(proto.Message):
r"""Describes a Cloud Storage fileset entry.
Attributes:
file_patterns (Sequence[str]):
Required. Patterns to identify a set of files in Google
Expand Down Expand Up @@ -75,6 +76,7 @@ class GcsFilesetSpec(proto.Message):

class GcsFileSpec(proto.Message):
r"""Specification of a single file in Cloud Storage.
Attributes:
file_path (str):
Required. Full file path. Example:
Expand Down
Expand Up @@ -137,6 +137,7 @@ class ImportTaxonomiesRequest(proto.Message):

class InlineSource(proto.Message):
r"""Inline source containing taxonomies to import.
Attributes:
taxonomies (Sequence[google.cloud.datacatalog_v1.types.SerializedTaxonomy]):
Required. Taxonomies to import.
Expand Down
3 changes: 3 additions & 0 deletions google/cloud/datacatalog_v1/types/table_spec.py
Expand Up @@ -38,6 +38,7 @@ class TableSourceType(proto.Enum):

class BigQueryTableSpec(proto.Message):
r"""Describes a BigQuery table.
Attributes:
table_source_type (google.cloud.datacatalog_v1.types.TableSourceType):
Output only. The table source type.
Expand All @@ -60,6 +61,7 @@ class BigQueryTableSpec(proto.Message):

class ViewSpec(proto.Message):
r"""Table view specification.
Attributes:
view_query (str):
Output only. The query that defines the table
Expand All @@ -71,6 +73,7 @@ class ViewSpec(proto.Message):

class TableSpec(proto.Message):
r"""Normal BigQuery table specification.
Attributes:
grouped_entry (str):
Output only. If the table is date-sharded, that is, it
Expand Down
5 changes: 5 additions & 0 deletions google/cloud/datacatalog_v1/types/tags.py
Expand Up @@ -113,6 +113,7 @@ class TagField(proto.Message):

class EnumValue(proto.Message):
r"""An enum value.
Attributes:
display_name (str):
The display name of the enum value.
Expand Down Expand Up @@ -216,6 +217,7 @@ class TagTemplate(proto.Message):

class TagTemplateField(proto.Message):
r"""The template for an individual field within a tag template.
Attributes:
name (str):
Output only. The resource name of the tag template field in
Expand Down Expand Up @@ -266,6 +268,7 @@ class TagTemplateField(proto.Message):

class FieldType(proto.Message):
r"""
Attributes:
primitive_type (google.cloud.datacatalog_v1.types.FieldType.PrimitiveType):
Primitive types, such as string, boolean,
Expand All @@ -285,6 +288,7 @@ class PrimitiveType(proto.Enum):

class EnumType(proto.Message):
r"""
Attributes:
allowed_values (Sequence[google.cloud.datacatalog_v1.types.FieldType.EnumType.EnumValue]):
The set of allowed values for this enum.
Expand All @@ -302,6 +306,7 @@ class EnumType(proto.Message):

class EnumValue(proto.Message):
r"""
Attributes:
display_name (str):
Required. The display name of the enum value. Must not be an
Expand Down
Expand Up @@ -2796,6 +2796,12 @@ async def test_iam_permissions(
# 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

0 comments on commit c403d1d

Please sign in to comment.