From f567a7eee3d36c075e36bd2ec1b674ab0665951e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 12 Apr 2022 07:13:45 -0400 Subject: [PATCH] chore: Use gapic-generator-python 0.65.0 (#263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Use gapic-generator-python 0.65.0 PiperOrigin-RevId: 440970084 Source-Link: https://github.com/googleapis/googleapis/commit/5e0a3d57254ab9857ccac77fc6ffade7b69a2dc7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b0c628a3fade768f225d76992791ea1ba2a881be Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBjNjI4YTNmYWRlNzY4ZjIyNWQ3Njk5Mjc5MWVhMWJhMmE4ODFiZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> --- .../services/cloud_build/async_client.py | 34 ++----- .../services/cloud_build/client.py | 13 +-- .../services/cloud_build/transports/base.py | 26 +++--- .../services/cloud_build/transports/grpc.py | 4 + .../cloudbuild_v1/types/cloudbuild.py | 16 ++-- .../gapic/cloudbuild_v1/test_cloud_build.py | 93 ++++++++++++++----- 6 files changed, 103 insertions(+), 83 deletions(-) diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py index a2d16ab6462e..04f7d31a8299 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -244,7 +244,6 @@ async def create_build( the build ID. Pass the build ID to ``GetBuild`` to determine the build status (such as ``SUCCESS`` or ``FAILURE``). - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -380,7 +379,6 @@ async def get_build( ``SUCCESS``, ``FAILURE``, or ``WORKING``), and timing information. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -475,8 +473,7 @@ def sample_get_build(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -509,7 +506,6 @@ async def list_builds( Previously requested builds may still be in-progress, or may have finished successfully or unsuccessfully. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -587,8 +583,7 @@ def sample_list_builds(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -773,7 +768,6 @@ async def retry_build( available depending on the bucket's lifecycle management settings. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -912,7 +906,6 @@ async def approve_build( If rejected, the returned LRO will be immediately done. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1055,7 +1048,6 @@ async def create_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1160,7 +1152,6 @@ async def get_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1240,8 +1231,7 @@ def sample_get_build_trigger(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -1273,7 +1263,6 @@ async def list_build_triggers( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1345,8 +1334,7 @@ def sample_list_build_triggers(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -1388,7 +1376,6 @@ async def delete_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1455,8 +1442,7 @@ def sample_delete_build_trigger(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -1487,7 +1473,6 @@ async def update_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1738,7 +1723,6 @@ async def receive_trigger_webhook( r"""ReceiveTriggerWebhook [Experimental] is called when the API receives a webhook request targeted at a specific trigger. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -2037,8 +2021,7 @@ def sample_get_worker_pool(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -2402,8 +2385,7 @@ def sample_list_worker_pools(): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py index 50ad86447808..65cf43bf200f 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -611,7 +611,6 @@ def create_build( the build ID. Pass the build ID to ``GetBuild`` to determine the build status (such as ``SUCCESS`` or ``FAILURE``). - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -747,7 +746,6 @@ def get_build( ``SUCCESS``, ``FAILURE``, or ``WORKING``), and timing information. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -866,7 +864,6 @@ def list_builds( Previously requested builds may still be in-progress, or may have finished successfully or unsuccessfully. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1120,7 +1117,6 @@ def retry_build( available depending on the bucket's lifecycle management settings. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1259,7 +1255,6 @@ def approve_build( If rejected, the returned LRO will be immediately done. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1402,7 +1397,6 @@ def create_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1507,7 +1501,6 @@ def get_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1610,7 +1603,6 @@ def list_build_triggers( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1715,7 +1707,6 @@ def delete_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -1804,7 +1795,6 @@ def update_build_trigger( This API is experimental. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 @@ -2055,7 +2045,6 @@ def receive_trigger_webhook( r"""ReceiveTriggerWebhook [Experimental] is called when the API receives a webhook request targeted at a specific trigger. - .. code-block:: python from google.cloud.devtools import cloudbuild_v1 diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py index baa771db28dd..6ae98e728093 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py @@ -83,6 +83,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -135,8 +136,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -150,8 +150,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -185,8 +184,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -200,8 +198,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -215,8 +212,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -250,8 +246,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -275,8 +270,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, + core_exceptions.GoogleAPICallError, ), deadline=600.0, ), @@ -470,5 +464,9 @@ def list_worker_pools( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("CloudBuildTransport",) diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py index c720a8572e90..55564d45f64f 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py @@ -782,5 +782,9 @@ def list_worker_pools( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("CloudBuildGrpcTransport",) diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py index 98c4c26a7a29..bb02940fecbc 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py @@ -225,7 +225,7 @@ class RepoSource(proto.Message): invert_regex (bool): Only trigger a build if the revision regex does NOT match the revision regex. - substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.RepoSource.SubstitutionsEntry]): + substitutions (Mapping[str, str]): Substitutions to use in a triggered build. Should only be used with RunBuildTrigger """ @@ -755,7 +755,7 @@ class Build(proto.Message): log_url (str): Output only. URL to logs for this build in Google Cloud Console. - substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.Build.SubstitutionsEntry]): + substitutions (Mapping[str, str]): Substitutions data for ``Build`` resource. tags (Sequence[str]): Tags for annotation of a ``Build``. These are not docker @@ -767,7 +767,7 @@ class Build(proto.Message): to configure builds to access secrets from Secret Manager. For instructions, see: https://cloud.google.com/cloud-build/docs/securing-builds/use-secrets - timing (Sequence[google.cloud.devtools.cloudbuild_v1.types.Build.TimingEntry]): + timing (Mapping[str, google.cloud.devtools.cloudbuild_v1.types.TimeSpan]): Output only. Stores timing information for phases of the build. Valid keys are: @@ -1139,7 +1139,7 @@ class SourceProvenance(proto.Message): A copy of the build's ``source.storage_source_manifest``, if exists, with any revisions resolved. This feature is in Preview. - file_hashes (Sequence[google.cloud.devtools.cloudbuild_v1.types.SourceProvenance.FileHashesEntry]): + file_hashes (Mapping[str, google.cloud.devtools.cloudbuild_v1.types.FileHashes]): Output only. Hash(es) of the build source, which can be used to verify that the original source integrity was maintained in the build. Note that ``FileHashes`` will only be @@ -1255,7 +1255,7 @@ class InlineSecret(proto.Message): Resource name of Cloud KMS crypto key to decrypt the encrypted value. In format: projects/\ */locations/*/keyRings/*/cryptoKeys/* - env_map (Sequence[google.cloud.devtools.cloudbuild_v1.types.InlineSecret.EnvMapEntry]): + env_map (Mapping[str, bytes]): Map of environment variable name to its encrypted value. Secret environment variables must be unique @@ -1312,7 +1312,7 @@ class Secret(proto.Message): kms_key_name (str): Cloud KMS key name to use to decrypt these envs. - secret_env (Sequence[google.cloud.devtools.cloudbuild_v1.types.Secret.SecretEnvEntry]): + secret_env (Mapping[str, bytes]): Map of environment variable name to its encrypted value. Secret environment variables must be unique @@ -1711,7 +1711,7 @@ class BuildTrigger(proto.Message): disabled (bool): If true, the trigger will never automatically execute a build. - substitutions (Sequence[google.cloud.devtools.cloudbuild_v1.types.BuildTrigger.SubstitutionsEntry]): + substitutions (Mapping[str, str]): Substitutions for Build resource. The keys must match the following regular expression: ``^_[A-Z0-9_]+$``. ignored_files (Sequence[str]): @@ -2543,7 +2543,7 @@ class WorkerPool(proto.Message): characters. uid (str): Output only. A unique identifier for the ``WorkerPool``. - annotations (Sequence[google.cloud.devtools.cloudbuild_v1.types.WorkerPool.AnnotationsEntry]): + annotations (Mapping[str, str]): User specified annotations. See https://google.aip.dev/128#annotations for more details such as format and size limitations. diff --git a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py index 6e783595c4c0..4b79454891bb 100644 --- a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py +++ b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py @@ -94,24 +94,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - CloudBuildClient, - CloudBuildAsyncClient, + (CloudBuildClient, "grpc"), + (CloudBuildAsyncClient, "grpc_asyncio"), ], ) -def test_cloud_build_client_from_service_account_info(client_class): +def test_cloud_build_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "cloudbuild.googleapis.com:443" + assert client.transport._host == ("cloudbuild.googleapis.com:443") @pytest.mark.parametrize( @@ -140,27 +140,31 @@ def test_cloud_build_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - CloudBuildClient, - CloudBuildAsyncClient, + (CloudBuildClient, "grpc"), + (CloudBuildAsyncClient, "grpc_asyncio"), ], ) -def test_cloud_build_client_from_service_account_file(client_class): +def test_cloud_build_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "cloudbuild.googleapis.com:443" + assert client.transport._host == ("cloudbuild.googleapis.com:443") def test_cloud_build_client_get_transport_class(): @@ -1336,7 +1340,7 @@ async def test_list_builds_async_pager(): ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1382,7 +1386,9 @@ async def test_list_builds_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_builds(request={})).pages: + async for page_ in ( + await client.list_builds(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -2800,7 +2806,7 @@ async def test_list_build_triggers_async_pager(): ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2848,7 +2854,9 @@ async def test_list_build_triggers_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_build_triggers(request={})).pages: + async for page_ in ( + await client.list_build_triggers(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -4947,7 +4955,7 @@ async def test_list_worker_pools_async_pager(): ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -4995,7 +5003,9 @@ async def test_list_worker_pools_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_worker_pools(request={})).pages: + async for page_ in ( + await client.list_worker_pools(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -5092,6 +5102,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = CloudBuildClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudBuildClient( @@ -5156,6 +5179,14 @@ def test_cloud_build_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_cloud_build_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -5298,24 +5329,40 @@ def test_cloud_build_grpc_transport_client_cert_source_for_mtls(transport_class) ) -def test_cloud_build_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_cloud_build_host_no_port(transport_name): client = CloudBuildClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudbuild.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "cloudbuild.googleapis.com:443" + assert client.transport._host == ("cloudbuild.googleapis.com:443") -def test_cloud_build_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_cloud_build_host_with_port(transport_name): client = CloudBuildClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="cloudbuild.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "cloudbuild.googleapis.com:8000" + assert client.transport._host == ("cloudbuild.googleapis.com:8000") def test_cloud_build_grpc_transport_channel():