From 57a982c7cafb2f91a9c2d2f0f8b85be1502f14be Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 10:46:11 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#60) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../services/service_usage/async_client.py | 40 +++---- .../services/service_usage/client.py | 14 ++- .../services/service_usage/transports/base.py | 37 +------ .../services/service_usage/transports/grpc.py | 2 +- .../service_usage/transports/grpc_asyncio.py | 3 +- setup.py | 3 +- testing/constraints-3.6.txt | 4 +- .../service_usage_v1/test_service_usage.py | 103 ++---------------- 8 files changed, 44 insertions(+), 162 deletions(-) diff --git a/google/cloud/service_usage_v1/services/service_usage/async_client.py b/google/cloud/service_usage_v1/services/service_usage/async_client.py index ca54c71..c1774e6 100644 --- a/google/cloud/service_usage_v1/services/service_usage/async_client.py +++ b/google/cloud/service_usage_v1/services/service_usage/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.service_usage_v1.services.service_usage import pagers @@ -166,9 +168,9 @@ def __init__( async def enable_service( self, - request: serviceusage.EnableServiceRequest = None, + request: Union[serviceusage.EnableServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -176,7 +178,7 @@ async def enable_service( project. Args: - request (:class:`google.cloud.service_usage_v1.types.EnableServiceRequest`): + request (Union[google.cloud.service_usage_v1.types.EnableServiceRequest, dict]): The request object. Request message for the `EnableService` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -228,9 +230,9 @@ async def enable_service( async def disable_service( self, - request: serviceusage.DisableServiceRequest = None, + request: Union[serviceusage.DisableServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -244,7 +246,7 @@ async def disable_service( currently enabled. Args: - request (:class:`google.cloud.service_usage_v1.types.DisableServiceRequest`): + request (Union[google.cloud.service_usage_v1.types.DisableServiceRequest, dict]): The request object. Request message for the `DisableService` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -296,9 +298,9 @@ async def disable_service( async def get_service( self, - request: serviceusage.GetServiceRequest = None, + request: Union[serviceusage.GetServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Service: @@ -306,7 +308,7 @@ async def get_service( for a given service. Args: - request (:class:`google.cloud.service_usage_v1.types.GetServiceRequest`): + request (Union[google.cloud.service_usage_v1.types.GetServiceRequest, dict]): The request object. Request message for the `GetService` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -346,9 +348,9 @@ async def get_service( async def list_services( self, - request: serviceusage.ListServicesRequest = None, + request: Union[serviceusage.ListServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListServicesAsyncPager: @@ -368,7 +370,7 @@ async def list_services( capability. Args: - request (:class:`google.cloud.service_usage_v1.types.ListServicesRequest`): + request (Union[google.cloud.service_usage_v1.types.ListServicesRequest, dict]): The request object. Request message for the `ListServices` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -416,9 +418,9 @@ async def list_services( async def batch_enable_services( self, - request: serviceusage.BatchEnableServicesRequest = None, + request: Union[serviceusage.BatchEnableServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -428,7 +430,7 @@ async def batch_enable_services( ``EnableService`` method instead. Args: - request (:class:`google.cloud.service_usage_v1.types.BatchEnableServicesRequest`): + request (Union[google.cloud.service_usage_v1.types.BatchEnableServicesRequest, dict]): The request object. Request message for the `BatchEnableServices` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -480,9 +482,9 @@ async def batch_enable_services( async def batch_get_services( self, - request: serviceusage.BatchGetServicesRequest = None, + request: Union[serviceusage.BatchGetServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> serviceusage.BatchGetServicesResponse: @@ -490,7 +492,7 @@ async def batch_get_services( for a given list of services. Args: - request (:class:`google.cloud.service_usage_v1.types.BatchGetServicesRequest`): + request (Union[google.cloud.service_usage_v1.types.BatchGetServicesRequest, dict]): The request object. Request message for the `BatchGetServices` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/service_usage_v1/services/service_usage/client.py b/google/cloud/service_usage_v1/services/service_usage/client.py index ef34892..61a15f2 100644 --- a/google/cloud/service_usage_v1/services/service_usage/client.py +++ b/google/cloud/service_usage_v1/services/service_usage/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.service_usage_v1.services.service_usage import pagers @@ -342,7 +344,7 @@ def enable_service( self, request: Union[serviceusage.EnableServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -405,7 +407,7 @@ def disable_service( self, request: Union[serviceusage.DisableServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -474,7 +476,7 @@ def get_service( self, request: Union[serviceusage.GetServiceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Service: @@ -525,7 +527,7 @@ def list_services( self, request: Union[serviceusage.ListServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListServicesPager: @@ -596,7 +598,7 @@ def batch_enable_services( self, request: Union[serviceusage.BatchEnableServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -661,7 +663,7 @@ def batch_get_services( self, request: Union[serviceusage.BatchGetServicesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> serviceusage.BatchGetServicesResponse: diff --git a/google/cloud/service_usage_v1/services/service_usage/transports/base.py b/google/cloud/service_usage_v1/services/service_usage/transports/base.py index aef3be4..3c39880 100644 --- a/google/cloud/service_usage_v1/services/service_usage/transports/base.py +++ b/google/cloud/service_usage_v1/services/service_usage/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -40,15 +39,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class ServiceUsageTransport(abc.ABC): """Abstract transport class for ServiceUsage.""" @@ -102,7 +92,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -135,29 +125,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -193,7 +160,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/service_usage_v1/services/service_usage/transports/grpc.py b/google/cloud/service_usage_v1/services/service_usage/transports/grpc.py index 66e6bf6..5f2318b 100644 --- a/google/cloud/service_usage_v1/services/service_usage/transports/grpc.py +++ b/google/cloud/service_usage_v1/services/service_usage/transports/grpc.py @@ -118,7 +118,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/service_usage_v1/services/service_usage/transports/grpc_asyncio.py b/google/cloud/service_usage_v1/services/service_usage/transports/grpc_asyncio.py index 895a3b0..ab95ce1 100644 --- a/google/cloud/service_usage_v1/services/service_usage/transports/grpc_asyncio.py +++ b/google/cloud/service_usage_v1/services/service_usage/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -165,7 +164,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/setup.py b/setup.py index 2b9ec5d..3fe9f1e 100644 --- a/setup.py +++ b/setup.py @@ -29,9 +29,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.15.0", - "packaging >= 14.3", ] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 4bd5e67..1e3ec8b 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -4,7 +4,5 @@ # Pin the version to the lower bound. # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.15.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 si transitively required through google-api-core diff --git a/tests/unit/gapic/service_usage_v1/test_service_usage.py b/tests/unit/gapic/service_usage_v1/test_service_usage.py index 8d91ee9..2b79e01 100644 --- a/tests/unit/gapic/service_usage_v1/test_service_usage.py +++ b/tests/unit/gapic/service_usage_v1/test_service_usage.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.service_usage_v1.services.service_usage import ServiceUsageClient from google.cloud.service_usage_v1.services.service_usage import pagers from google.cloud.service_usage_v1.services.service_usage import transports -from google.cloud.service_usage_v1.services.service_usage.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.service_usage_v1.types import resources from google.cloud.service_usage_v1.types import serviceusage from google.longrunning import operations_pb2 @@ -49,20 +45,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -210,7 +192,7 @@ def test_service_usage_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -227,7 +209,7 @@ def test_service_usage_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,7 +226,7 @@ def test_service_usage_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -273,7 +255,7 @@ def test_service_usage_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -330,7 +312,7 @@ def test_service_usage_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -372,7 +354,7 @@ def test_service_usage_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -394,7 +376,7 @@ def test_service_usage_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -425,7 +407,7 @@ def test_service_usage_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -456,7 +438,7 @@ def test_service_usage_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1557,7 +1539,6 @@ def test_service_usage_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_service_usage_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1582,30 +1563,6 @@ def test_service_usage_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_service_usage_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.service_usage_v1.services.service_usage.transports.ServiceUsageTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ServiceUsageTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-platform.read-only", - "https://www.googleapis.com/auth/service.management", - ), - quota_project_id="octopus", - ) - - def test_service_usage_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1617,7 +1574,6 @@ def test_service_usage_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_service_usage_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1634,22 +1590,6 @@ def test_service_usage_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_service_usage_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ServiceUsageClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-platform.read-only", - "https://www.googleapis.com/auth/service.management", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1657,7 +1597,6 @@ def test_service_usage_auth_adc_old_google_auth(): transports.ServiceUsageGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_service_usage_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1675,30 +1614,6 @@ def test_service_usage_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ServiceUsageGrpcTransport, - transports.ServiceUsageGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_service_usage_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-platform.read-only", - "https://www.googleapis.com/auth/service.management", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [