diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py index 0bbb1767930b..c6f364015636 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/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.vision_v1.types import image_annotator @@ -170,10 +172,10 @@ def __init__( async def batch_annotate_images( self, - request: image_annotator.BatchAnnotateImagesRequest = None, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -181,7 +183,7 @@ async def batch_annotate_images( images. Args: - request (:class:`google.cloud.vision_v1.types.BatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): @@ -246,10 +248,10 @@ async def batch_annotate_images( async def batch_annotate_files( self, - request: image_annotator.BatchAnnotateFilesRequest = None, + request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateFilesResponse: @@ -263,7 +265,7 @@ async def batch_annotate_files( extracted. Args: - request (:class:`google.cloud.vision_v1.types.BatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]`): @@ -328,11 +330,11 @@ async def batch_annotate_files( async def async_batch_annotate_images( self, - request: image_annotator.AsyncBatchAnnotateImagesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, output_config: image_annotator.OutputConfig = 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: @@ -350,7 +352,7 @@ async def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation for a list of images. requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): @@ -435,10 +437,10 @@ async def async_batch_annotate_images( async def async_batch_annotate_files( self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = 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: @@ -451,7 +453,7 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py index 27a199d239b7..fd5e2285106b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/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.vision_v1.types import image_annotator @@ -373,7 +375,7 @@ def batch_annotate_images( request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -442,7 +444,7 @@ def batch_annotate_files( request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateFilesResponse: @@ -518,7 +520,7 @@ def async_batch_annotate_images( *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -619,7 +621,7 @@ def async_batch_annotate_files( request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py index d151cd5ac0e9..8f564aeacc26 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/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 @@ -37,15 +36,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 ImageAnnotatorTransport(abc.ABC): """Abstract transport class for ImageAnnotator.""" @@ -98,7 +88,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 @@ -131,29 +121,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 = { @@ -229,7 +196,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/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index 42f6671c499c..92dfcee96c31 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -115,7 +115,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/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index 17a5d34fa6f8..b57bf52f7d89 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/image_annotator/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 @@ -162,7 +161,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/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py index 4da3f2ff3fce..e2b152901726 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/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.vision_v1.services.product_search import pagers @@ -194,12 +196,12 @@ def __init__( async def create_product_set( self, - request: product_search_service.CreateProductSetRequest = None, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, *, parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -211,7 +213,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`google.cloud.vision_v1.types.CreateProductSetRequest`): + request (Union[google.cloud.vision_v1.types.CreateProductSetRequest, dict]): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -303,10 +305,10 @@ async def create_product_set( async def list_product_sets( self, - request: product_search_service.ListProductSetsRequest = None, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsAsyncPager: @@ -318,7 +320,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`google.cloud.vision_v1.types.ListProductSetsRequest`): + request (Union[google.cloud.vision_v1.types.ListProductSetsRequest, dict]): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -399,10 +401,10 @@ async def list_product_sets( async def get_product_set( self, - request: product_search_service.GetProductSetRequest = None, + request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -413,7 +415,7 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`google.cloud.vision_v1.types.GetProductSetRequest`): + request (Union[google.cloud.vision_v1.types.GetProductSetRequest, dict]): The request object. Request message for the `GetProductSet` method. name (:class:`str`): @@ -489,11 +491,11 @@ async def get_product_set( async def update_product_set( self, - request: product_search_service.UpdateProductSetRequest = None, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -508,7 +510,7 @@ async def update_product_set( characters. Args: - request (:class:`google.cloud.vision_v1.types.UpdateProductSetRequest`): + request (Union[google.cloud.vision_v1.types.UpdateProductSetRequest, dict]): The request object. Request message for the `UpdateProductSet` method. product_set (:class:`google.cloud.vision_v1.types.ProductSet`): @@ -595,10 +597,10 @@ async def update_product_set( async def delete_product_set( self, - request: product_search_service.DeleteProductSetRequest = None, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -608,7 +610,7 @@ async def delete_product_set( Storage. Args: - request (:class:`google.cloud.vision_v1.types.DeleteProductSetRequest`): + request (Union[google.cloud.vision_v1.types.DeleteProductSetRequest, dict]): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -674,12 +676,12 @@ async def delete_product_set( async def create_product( self, - request: product_search_service.CreateProductRequest = None, + request: Union[product_search_service.CreateProductRequest, dict] = None, *, parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -695,7 +697,7 @@ async def create_product( invalid. Args: - request (:class:`google.cloud.vision_v1.types.CreateProductRequest`): + request (Union[google.cloud.vision_v1.types.CreateProductRequest, dict]): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -782,10 +784,10 @@ async def create_product( async def list_products( self, - request: product_search_service.ListProductsRequest = None, + request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsAsyncPager: @@ -797,7 +799,7 @@ async def list_products( less than 1. Args: - request (:class:`google.cloud.vision_v1.types.ListProductsRequest`): + request (Union[google.cloud.vision_v1.types.ListProductsRequest, dict]): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -878,10 +880,10 @@ async def list_products( async def get_product( self, - request: product_search_service.GetProductRequest = None, + request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -892,7 +894,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`google.cloud.vision_v1.types.GetProductRequest`): + request (Union[google.cloud.vision_v1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -963,11 +965,11 @@ async def get_product( async def update_product( self, - request: product_search_service.UpdateProductRequest = None, + request: Union[product_search_service.UpdateProductRequest, dict] = None, *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -989,7 +991,7 @@ async def update_product( update_mask. Args: - request (:class:`google.cloud.vision_v1.types.UpdateProductRequest`): + request (Union[google.cloud.vision_v1.types.UpdateProductRequest, dict]): The request object. Request message for the `UpdateProduct` method. product (:class:`google.cloud.vision_v1.types.Product`): @@ -1073,10 +1075,10 @@ async def update_product( async def delete_product( self, - request: product_search_service.DeleteProductRequest = None, + request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1088,7 +1090,7 @@ async def delete_product( all related caches are refreshed. Args: - request (:class:`google.cloud.vision_v1.types.DeleteProductRequest`): + request (Union[google.cloud.vision_v1.types.DeleteProductRequest, dict]): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1154,12 +1156,12 @@ async def delete_product( async def create_reference_image( self, - request: product_search_service.CreateReferenceImageRequest = None, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, *, parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1187,7 +1189,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`google.cloud.vision_v1.types.CreateReferenceImageRequest`): + request (Union[google.cloud.vision_v1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1280,10 +1282,10 @@ async def create_reference_image( async def delete_reference_image( self, - request: product_search_service.DeleteReferenceImageRequest = None, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1296,7 +1298,7 @@ async def delete_reference_image( Storage. Args: - request (:class:`google.cloud.vision_v1.types.DeleteReferenceImageRequest`): + request (Union[google.cloud.vision_v1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1363,10 +1365,10 @@ async def delete_reference_image( async def list_reference_images( self, - request: product_search_service.ListReferenceImagesRequest = None, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesAsyncPager: @@ -1379,7 +1381,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`google.cloud.vision_v1.types.ListReferenceImagesRequest`): + request (Union[google.cloud.vision_v1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1461,10 +1463,10 @@ async def list_reference_images( async def get_reference_image( self, - request: product_search_service.GetReferenceImageRequest = None, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1475,7 +1477,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`google.cloud.vision_v1.types.GetReferenceImageRequest`): + request (Union[google.cloud.vision_v1.types.GetReferenceImageRequest, dict]): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1549,11 +1551,13 @@ async def get_reference_image( async def add_product_to_product_set( self, - request: product_search_service.AddProductToProductSetRequest = None, + request: Union[ + product_search_service.AddProductToProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1568,7 +1572,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`google.cloud.vision_v1.types.AddProductToProductSetRequest`): + request (Union[google.cloud.vision_v1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1647,18 +1651,20 @@ async def add_product_to_product_set( async def remove_product_from_product_set( self, - request: product_search_service.RemoveProductFromProductSetRequest = None, + request: Union[ + product_search_service.RemoveProductFromProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Removes a Product from the specified ProductSet. Args: - request (:class:`google.cloud.vision_v1.types.RemoveProductFromProductSetRequest`): + request (Union[google.cloud.vision_v1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1737,10 +1743,12 @@ async def remove_product_from_product_set( async def list_products_in_product_set( self, - request: product_search_service.ListProductsInProductSetRequest = None, + request: Union[ + product_search_service.ListProductsInProductSetRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetAsyncPager: @@ -1754,7 +1762,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`google.cloud.vision_v1.types.ListProductsInProductSetRequest`): + request (Union[google.cloud.vision_v1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1837,11 +1845,11 @@ async def list_products_in_product_set( async def import_product_sets( self, - request: product_search_service.ImportProductSetsRequest = None, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = 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: @@ -1859,7 +1867,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`google.cloud.vision_v1.types.ImportProductSetsRequest`): + request (Union[google.cloud.vision_v1.types.ImportProductSetsRequest, dict]): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): @@ -1955,10 +1963,10 @@ async def import_product_sets( async def purge_products( self, - request: product_search_service.PurgeProductsRequest = None, + request: Union[product_search_service.PurgeProductsRequest, dict] = None, *, parent: str = 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: @@ -1991,7 +1999,7 @@ async def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`google.cloud.vision_v1.types.PurgeProductsRequest`): + request (Union[google.cloud.vision_v1.types.PurgeProductsRequest, dict]): The request object. Request message for the `PurgeProducts` method. parent (:class:`str`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py index 7169a7531f4f..984fa4b1b119 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/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.vision_v1.services.product_search import pagers @@ -414,7 +416,7 @@ def create_product_set( parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -514,7 +516,7 @@ def list_product_sets( request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsPager: @@ -600,7 +602,7 @@ def get_product_set( request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -681,7 +683,7 @@ def update_product_set( *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -776,7 +778,7 @@ def delete_product_set( request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -847,7 +849,7 @@ def create_product( parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -946,7 +948,7 @@ def list_products( request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsPager: @@ -1032,7 +1034,7 @@ def get_product( request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1108,7 +1110,7 @@ def update_product( *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1207,7 +1209,7 @@ def delete_product( request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1280,7 +1282,7 @@ def create_reference_image( parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1397,7 +1399,7 @@ def delete_reference_image( request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1470,7 +1472,7 @@ def list_reference_images( request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesPager: @@ -1558,7 +1560,7 @@ def get_reference_image( request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1639,7 +1641,7 @@ def add_product_to_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1733,7 +1735,7 @@ def remove_product_from_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1818,7 +1820,7 @@ def list_products_in_product_set( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetPager: @@ -1913,7 +1915,7 @@ def import_product_sets( *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -2023,7 +2025,7 @@ def purge_products( request: Union[product_search_service.PurgeProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py index 4569d29a1a24..ceabc2a75e2e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/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 @@ -38,15 +37,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 ProductSearchTransport(abc.ABC): """Abstract transport class for ProductSearch.""" @@ -99,7 +89,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 @@ -132,29 +122,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 = { @@ -440,7 +407,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/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py index f35155a4935d..efd04d99fc29 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -130,7 +130,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/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 6713950dee1d..dd30008822d7 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/services/product_search/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 @@ -177,7 +176,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/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py index d3844e2cdcad..f4a9317af8a1 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1/types/product_search_service.py @@ -711,11 +711,14 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -822,13 +825,22 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): Specify which ProductSet contains the Products to be deleted. + This field is a member of `oneof`_ ``target``. delete_orphan_products (bool): If delete_orphan_products is true, all Products that are not in any ProductSet will be deleted. + This field is a member of `oneof`_ ``target``. parent (str): Required. The project and location in which the Products should be deleted. diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 79c154ffc888..6c68dede9ede 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/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.cloud.vision_v1p1beta1.types import image_annotator from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport @@ -164,10 +166,10 @@ def __init__( async def batch_annotate_images( self, - request: image_annotator.BatchAnnotateImagesRequest = None, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -175,7 +177,7 @@ async def batch_annotate_images( images. Args: - request (:class:`google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index c3ec4ee0cbc2..5ade38260dc9 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/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.cloud.vision_v1p1beta1.types import image_annotator from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ImageAnnotatorGrpcTransport @@ -339,7 +341,7 @@ def batch_annotate_images( request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py index 60872932a035..6f0663905cbc 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/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 @@ -35,15 +34,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 ImageAnnotatorTransport(abc.ABC): """Abstract transport class for ImageAnnotator.""" @@ -96,7 +86,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 @@ -129,29 +119,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 = { diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index b0d0aa31fd77..8f64a1bc1f96 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # 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 diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index d952f873c71f..bab8d5e550e3 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/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.vision_v1p2beta1.types import image_annotator @@ -166,10 +168,10 @@ def __init__( async def batch_annotate_images( self, - request: image_annotator.BatchAnnotateImagesRequest = None, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -177,7 +179,7 @@ async def batch_annotate_images( images. Args: - request (:class:`google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]`): @@ -242,10 +244,10 @@ async def batch_annotate_images( async def async_batch_annotate_files( self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = 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: @@ -258,7 +260,7 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index 5462d8464347..a9217b5cbb95 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/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.vision_v1p2beta1.types import image_annotator @@ -341,7 +343,7 @@ def batch_annotate_images( request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -410,7 +412,7 @@ def async_batch_annotate_files( request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py index cd9ee952fb1b..8afc6f65db4b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/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 @@ -37,15 +36,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 ImageAnnotatorTransport(abc.ABC): """Abstract transport class for ImageAnnotator.""" @@ -98,7 +88,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 @@ -131,29 +121,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 = { @@ -199,7 +166,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/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index 215ddf005e68..02a351e91273 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py @@ -115,7 +115,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/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index ebab6ad91496..9354a5605ef9 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p2beta1/services/image_annotator/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 @@ -162,7 +161,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index 1eeba8114706..b076383ea8d2 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/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.vision_v1p3beta1.types import image_annotator @@ -170,10 +172,10 @@ def __init__( async def batch_annotate_images( self, - request: image_annotator.BatchAnnotateImagesRequest = None, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -181,7 +183,7 @@ async def batch_annotate_images( images. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]`): @@ -246,10 +248,10 @@ async def batch_annotate_images( async def async_batch_annotate_files( self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = 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: @@ -262,7 +264,7 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index 30d68db0be84..5062ea91d1b3 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/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.vision_v1p3beta1.types import image_annotator @@ -373,7 +375,7 @@ def batch_annotate_images( request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -442,7 +444,7 @@ def async_batch_annotate_files( request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py index 4aef3c5ec9af..87320f063b9e 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/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 @@ -37,15 +36,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 ImageAnnotatorTransport(abc.ABC): """Abstract transport class for ImageAnnotator.""" @@ -98,7 +88,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 @@ -131,29 +121,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 = { @@ -196,7 +163,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index db3cb8d59c04..1946436ae37b 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py @@ -115,7 +115,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index 0114a89c2f28..60967a417527 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/image_annotator/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 @@ -162,7 +161,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index f50784917477..68fb8a1f4c34 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/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.vision_v1p3beta1.services.product_search import pagers @@ -195,12 +197,12 @@ def __init__( async def create_product_set( self, - request: product_search_service.CreateProductSetRequest = None, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, *, parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -212,7 +214,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -304,10 +306,10 @@ async def create_product_set( async def list_product_sets( self, - request: product_search_service.ListProductSetsRequest = None, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsAsyncPager: @@ -319,7 +321,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductSetsRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -400,10 +402,10 @@ async def list_product_sets( async def get_product_set( self, - request: product_search_service.GetProductSetRequest = None, + request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -414,7 +416,7 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): The request object. Request message for the `GetProductSet` method. name (:class:`str`): @@ -490,11 +492,11 @@ async def get_product_set( async def update_product_set( self, - request: product_search_service.UpdateProductSetRequest = None, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -509,7 +511,7 @@ async def update_product_set( characters. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the `UpdateProductSet` method. product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): @@ -593,10 +595,10 @@ async def update_product_set( async def delete_product_set( self, - request: product_search_service.DeleteProductSetRequest = None, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -611,7 +613,7 @@ async def delete_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -677,12 +679,12 @@ async def delete_product_set( async def create_product( self, - request: product_search_service.CreateProductRequest = None, + request: Union[product_search_service.CreateProductRequest, dict] = None, *, parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -698,7 +700,7 @@ async def create_product( invalid. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -785,10 +787,10 @@ async def create_product( async def list_products( self, - request: product_search_service.ListProductsRequest = None, + request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsAsyncPager: @@ -800,7 +802,7 @@ async def list_products( less than 1. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -881,10 +883,10 @@ async def list_products( async def get_product( self, - request: product_search_service.GetProductRequest = None, + request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -895,7 +897,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetProductRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -966,11 +968,11 @@ async def get_product( async def update_product( self, - request: product_search_service.UpdateProductRequest = None, + request: Union[product_search_service.UpdateProductRequest, dict] = None, *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -992,7 +994,7 @@ async def update_product( update_mask. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): The request object. Request message for the `UpdateProduct` method. product (:class:`google.cloud.vision_v1p3beta1.types.Product`): @@ -1073,10 +1075,10 @@ async def update_product( async def delete_product( self, - request: product_search_service.DeleteProductRequest = None, + request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1091,7 +1093,7 @@ async def delete_product( - Returns NOT_FOUND if the product does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1157,12 +1159,12 @@ async def delete_product( async def create_reference_image( self, - request: product_search_service.CreateReferenceImageRequest = None, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, *, parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1190,7 +1192,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1283,10 +1285,10 @@ async def create_reference_image( async def delete_reference_image( self, - request: product_search_service.DeleteReferenceImageRequest = None, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1304,7 +1306,7 @@ async def delete_reference_image( - Returns NOT_FOUND if the reference image does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1372,10 +1374,10 @@ async def delete_reference_image( async def list_reference_images( self, - request: product_search_service.ListReferenceImagesRequest = None, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesAsyncPager: @@ -1388,7 +1390,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1470,10 +1472,10 @@ async def list_reference_images( async def get_reference_image( self, - request: product_search_service.GetReferenceImageRequest = None, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1484,7 +1486,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1559,11 +1561,13 @@ async def get_reference_image( async def add_product_to_product_set( self, - request: product_search_service.AddProductToProductSetRequest = None, + request: Union[ + product_search_service.AddProductToProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1578,7 +1582,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1654,11 +1658,13 @@ async def add_product_to_product_set( async def remove_product_from_product_set( self, - request: product_search_service.RemoveProductFromProductSetRequest = None, + request: Union[ + product_search_service.RemoveProductFromProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1670,7 +1676,7 @@ async def remove_product_from_product_set( ProductSet. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1746,10 +1752,12 @@ async def remove_product_from_product_set( async def list_products_in_product_set( self, - request: product_search_service.ListProductsInProductSetRequest = None, + request: Union[ + product_search_service.ListProductsInProductSetRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetAsyncPager: @@ -1763,7 +1771,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1846,11 +1854,11 @@ async def list_products_in_product_set( async def import_product_sets( self, - request: product_search_service.ImportProductSetsRequest = None, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = 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: @@ -1868,7 +1876,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest`): + request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py index 4ea43f527697..a8033e906ba7 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/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.vision_v1p3beta1.services.product_search import pagers @@ -415,7 +417,7 @@ def create_product_set( parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -515,7 +517,7 @@ def list_product_sets( request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsPager: @@ -601,7 +603,7 @@ def get_product_set( request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -682,7 +684,7 @@ def update_product_set( *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -777,7 +779,7 @@ def delete_product_set( request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -853,7 +855,7 @@ def create_product( parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -952,7 +954,7 @@ def list_products( request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsPager: @@ -1038,7 +1040,7 @@ def get_product( request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1114,7 +1116,7 @@ def update_product( *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1213,7 +1215,7 @@ def delete_product( request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1289,7 +1291,7 @@ def create_reference_image( parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1406,7 +1408,7 @@ def delete_reference_image( request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1485,7 +1487,7 @@ def list_reference_images( request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesPager: @@ -1573,7 +1575,7 @@ def get_reference_image( request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1655,7 +1657,7 @@ def add_product_to_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1749,7 +1751,7 @@ def remove_product_from_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1839,7 +1841,7 @@ def list_products_in_product_set( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetPager: @@ -1934,7 +1936,7 @@ def import_product_sets( *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py index 14afcdb74983..f04547b3ef9c 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/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 @@ -38,15 +37,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 ProductSearchTransport(abc.ABC): """Abstract transport class for ProductSearch.""" @@ -99,7 +89,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 @@ -132,29 +122,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 = { @@ -416,7 +383,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index 5c642bbaf904..6e33bc987cf5 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -132,7 +132,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index 83fe6924fa4c..711f47fc6d09 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/services/product_search/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 @@ -179,7 +178,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/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py index de561f136707..0e98cb805dda 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -692,11 +692,14 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index abb4106ebd77..9635fbf3ff35 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/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.vision_v1p4beta1.types import image_annotator @@ -170,10 +172,10 @@ def __init__( async def batch_annotate_images( self, - request: image_annotator.BatchAnnotateImagesRequest = None, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -181,7 +183,7 @@ async def batch_annotate_images( images. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): @@ -243,10 +245,10 @@ async def batch_annotate_images( async def batch_annotate_files( self, - request: image_annotator.BatchAnnotateFilesRequest = None, + request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateFilesResponse: @@ -260,7 +262,7 @@ async def batch_annotate_files( extracted. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]`): @@ -322,11 +324,11 @@ async def batch_annotate_files( async def async_batch_annotate_images( self, - request: image_annotator.AsyncBatchAnnotateImagesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, output_config: image_annotator.OutputConfig = 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: @@ -344,7 +346,7 @@ async def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation for a list of images. requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): @@ -426,10 +428,10 @@ async def async_batch_annotate_images( async def async_batch_annotate_files( self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = 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: @@ -442,7 +444,7 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation requests are batched into a single service call. requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index 758f47c9a6e3..580627017f00 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/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.vision_v1p4beta1.types import image_annotator @@ -373,7 +375,7 @@ def batch_annotate_images( request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateImagesResponse: @@ -442,7 +444,7 @@ def batch_annotate_files( request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> image_annotator.BatchAnnotateFilesResponse: @@ -518,7 +520,7 @@ def async_batch_annotate_images( *, requests: Sequence[image_annotator.AnnotateImageRequest] = None, output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -619,7 +621,7 @@ def async_batch_annotate_files( request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, *, requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py index b077e031aa46..a3985d915b71 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/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 @@ -37,15 +36,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 ImageAnnotatorTransport(abc.ABC): """Abstract transport class for ImageAnnotator.""" @@ -98,7 +88,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 @@ -131,29 +121,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 = { @@ -217,7 +184,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 53c1ab22b6c6..e79ff8f2ee86 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -115,7 +115,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index 41428155beb4..bee42ccff119 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/image_annotator/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 @@ -162,7 +161,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index cc062587afb7..c586f4fd095a 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/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.vision_v1p4beta1.services.product_search import pagers @@ -196,12 +198,12 @@ def __init__( async def create_product_set( self, - request: product_search_service.CreateProductSetRequest = None, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, *, parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -213,7 +215,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -305,10 +307,10 @@ async def create_product_set( async def list_product_sets( self, - request: product_search_service.ListProductSetsRequest = None, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsAsyncPager: @@ -320,7 +322,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductSetsRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -401,10 +403,10 @@ async def list_product_sets( async def get_product_set( self, - request: product_search_service.GetProductSetRequest = None, + request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -415,7 +417,7 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.GetProductSetRequest, dict]): The request object. Request message for the `GetProductSet` method. name (:class:`str`): @@ -491,11 +493,11 @@ async def get_product_set( async def update_product_set( self, - request: product_search_service.UpdateProductSetRequest = None, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -510,7 +512,7 @@ async def update_product_set( characters. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the `UpdateProductSet` method. product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): @@ -594,10 +596,10 @@ async def update_product_set( async def delete_product_set( self, - request: product_search_service.DeleteProductSetRequest = None, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -607,7 +609,7 @@ async def delete_product_set( Storage. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -673,12 +675,12 @@ async def delete_product_set( async def create_product( self, - request: product_search_service.CreateProductRequest = None, + request: Union[product_search_service.CreateProductRequest, dict] = None, *, parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -694,7 +696,7 @@ async def create_product( invalid. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.CreateProductRequest, dict]): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -781,10 +783,10 @@ async def create_product( async def list_products( self, - request: product_search_service.ListProductsRequest = None, + request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsAsyncPager: @@ -796,7 +798,7 @@ async def list_products( less than 1. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.ListProductsRequest, dict]): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -877,10 +879,10 @@ async def list_products( async def get_product( self, - request: product_search_service.GetProductRequest = None, + request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -891,7 +893,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetProductRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -962,11 +964,11 @@ async def get_product( async def update_product( self, - request: product_search_service.UpdateProductRequest = None, + request: Union[product_search_service.UpdateProductRequest, dict] = None, *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -988,7 +990,7 @@ async def update_product( update_mask. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductRequest, dict]): The request object. Request message for the `UpdateProduct` method. product (:class:`google.cloud.vision_v1p4beta1.types.Product`): @@ -1069,10 +1071,10 @@ async def update_product( async def delete_product( self, - request: product_search_service.DeleteProductRequest = None, + request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1084,7 +1086,7 @@ async def delete_product( all related caches are refreshed. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductRequest, dict]): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1150,12 +1152,12 @@ async def delete_product( async def create_reference_image( self, - request: product_search_service.CreateReferenceImageRequest = None, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, *, parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1183,7 +1185,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1276,10 +1278,10 @@ async def create_reference_image( async def delete_reference_image( self, - request: product_search_service.DeleteReferenceImageRequest = None, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1292,7 +1294,7 @@ async def delete_reference_image( Storage. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1360,10 +1362,10 @@ async def delete_reference_image( async def list_reference_images( self, - request: product_search_service.ListReferenceImagesRequest = None, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesAsyncPager: @@ -1376,7 +1378,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1458,10 +1460,10 @@ async def list_reference_images( async def get_reference_image( self, - request: product_search_service.GetReferenceImageRequest = None, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1472,7 +1474,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1547,11 +1549,13 @@ async def get_reference_image( async def add_product_to_product_set( self, - request: product_search_service.AddProductToProductSetRequest = None, + request: Union[ + product_search_service.AddProductToProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1566,7 +1570,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1642,18 +1646,20 @@ async def add_product_to_product_set( async def remove_product_from_product_set( self, - request: product_search_service.RemoveProductFromProductSetRequest = None, + request: Union[ + product_search_service.RemoveProductFromProductSetRequest, dict + ] = None, *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Removes a Product from the specified ProductSet. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1729,10 +1735,12 @@ async def remove_product_from_product_set( async def list_products_in_product_set( self, - request: product_search_service.ListProductsInProductSetRequest = None, + request: Union[ + product_search_service.ListProductsInProductSetRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetAsyncPager: @@ -1746,7 +1754,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1829,11 +1837,11 @@ async def list_products_in_product_set( async def import_product_sets( self, - request: product_search_service.ImportProductSetsRequest = None, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = 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: @@ -1851,7 +1859,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): @@ -1947,10 +1955,10 @@ async def import_product_sets( async def purge_products( self, - request: product_search_service.PurgeProductsRequest = None, + request: Union[product_search_service.PurgeProductsRequest, dict] = None, *, parent: str = 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: @@ -1983,7 +1991,7 @@ async def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`google.cloud.vision_v1p4beta1.types.PurgeProductsRequest`): + request (Union[google.cloud.vision_v1p4beta1.types.PurgeProductsRequest, dict]): The request object. Request message for the `PurgeProducts` method. parent (:class:`str`): diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py index 8ed9fa46fd42..fdeb27d0587f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/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.vision_v1p4beta1.services.product_search import pagers @@ -416,7 +418,7 @@ def create_product_set( parent: str = None, product_set: product_search_service.ProductSet = None, product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -516,7 +518,7 @@ def list_product_sets( request: Union[product_search_service.ListProductSetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductSetsPager: @@ -602,7 +604,7 @@ def get_product_set( request: Union[product_search_service.GetProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -683,7 +685,7 @@ def update_product_set( *, product_set: product_search_service.ProductSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ProductSet: @@ -778,7 +780,7 @@ def delete_product_set( request: Union[product_search_service.DeleteProductSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -849,7 +851,7 @@ def create_product( parent: str = None, product: product_search_service.Product = None, product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -948,7 +950,7 @@ def list_products( request: Union[product_search_service.ListProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsPager: @@ -1034,7 +1036,7 @@ def get_product( request: Union[product_search_service.GetProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1110,7 +1112,7 @@ def update_product( *, product: product_search_service.Product = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.Product: @@ -1209,7 +1211,7 @@ def delete_product( request: Union[product_search_service.DeleteProductRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1282,7 +1284,7 @@ def create_reference_image( parent: str = None, reference_image: product_search_service.ReferenceImage = None, reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1399,7 +1401,7 @@ def delete_reference_image( request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1473,7 +1475,7 @@ def list_reference_images( request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListReferenceImagesPager: @@ -1561,7 +1563,7 @@ def get_reference_image( request: Union[product_search_service.GetReferenceImageRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> product_search_service.ReferenceImage: @@ -1643,7 +1645,7 @@ def add_product_to_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1737,7 +1739,7 @@ def remove_product_from_product_set( *, name: str = None, product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1822,7 +1824,7 @@ def list_products_in_product_set( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListProductsInProductSetPager: @@ -1917,7 +1919,7 @@ def import_product_sets( *, parent: str = None, input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -2027,7 +2029,7 @@ def purge_products( request: Union[product_search_service.PurgeProductsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py index e63d65acd12a..2687367f8312 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/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 @@ -38,15 +37,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 ProductSearchTransport(abc.ABC): """Abstract transport class for ProductSearch.""" @@ -99,7 +89,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 @@ -132,29 +122,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 = { @@ -419,7 +386,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 9f96f612fc36..72d9ff61e43a 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -132,7 +132,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 266cf36e6161..798cf1d1ed01 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/services/product_search/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 @@ -179,7 +178,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/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py index 31c399779d33..135a434e599f 100644 --- a/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/packages/google-cloud-vision/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -713,11 +713,14 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -824,13 +827,22 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): Specify which ProductSet contains the Products to be deleted. + This field is a member of `oneof`_ ``target``. delete_orphan_products (bool): If delete_orphan_products is true, all Products that are not in any ProductSet will be deleted. + This field is a member of `oneof`_ ``target``. parent (str): Required. The project and location in which the Products should be deleted. diff --git a/packages/google-cloud-vision/setup.py b/packages/google-cloud-vision/setup.py index d5f7c6c818cc..9c1aee900982 100644 --- a/packages/google-cloud-vision/setup.py +++ b/packages/google-cloud-vision/setup.py @@ -25,9 +25,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", ] extras = {"libcst": "libcst >= 0.2.5"} diff --git a/packages/google-cloud-vision/testing/constraints-3.6.txt b/packages/google-cloud-vision/testing/constraints-3.6.txt index 0842601443fc..aff6bee661dd 100644 --- a/packages/google-cloud-vision/testing/constraints-3.6.txt +++ b/packages/google-cloud-vision/testing/constraints-3.6.txt @@ -5,6 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.15.0 -packaging==14.3 diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py index da4a490d0908..92c9f73d351e 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -38,9 +37,6 @@ from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorAsyncClient from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorClient from google.cloud.vision_v1.services.image_annotator import transports -from google.cloud.vision_v1.services.image_annotator.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1.types import geometry from google.cloud.vision_v1.types import image_annotator from google.cloud.vision_v1.types import product_search @@ -50,20 +46,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" @@ -220,7 +202,7 @@ def test_image_annotator_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, @@ -237,7 +219,7 @@ def test_image_annotator_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, @@ -254,7 +236,7 @@ def test_image_annotator_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, @@ -283,7 +265,7 @@ def test_image_annotator_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, @@ -342,7 +324,7 @@ def test_image_annotator_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 @@ -384,7 +366,7 @@ def test_image_annotator_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, @@ -406,7 +388,7 @@ def test_image_annotator_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, @@ -437,7 +419,7 @@ def test_image_annotator_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, @@ -468,7 +450,7 @@ def test_image_annotator_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", @@ -1411,7 +1393,6 @@ def test_image_annotator_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1435,29 +1416,6 @@ def test_image_annotator_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_image_annotator_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( @@ -1469,7 +1427,6 @@ def test_image_annotator_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_image_annotator_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1485,21 +1442,6 @@ def test_image_annotator_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1507,7 +1449,6 @@ def test_image_annotator_auth_adc_old_google_auth(): transports.ImageAnnotatorGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_image_annotator_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1524,29 +1465,6 @@ def test_image_annotator_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py index 35c5b80d87e7..49b181c58a69 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1/test_product_search.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.vision_v1.services.product_search import ProductSearchClient from google.cloud.vision_v1.services.product_search import pagers from google.cloud.vision_v1.services.product_search import transports -from google.cloud.vision_v1.services.product_search.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1.types import geometry from google.cloud.vision_v1.types import product_search_service from google.longrunning import operations_pb2 @@ -53,20 +49,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" @@ -223,7 +205,7 @@ def test_product_search_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, @@ -240,7 +222,7 @@ def test_product_search_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, @@ -257,7 +239,7 @@ def test_product_search_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, @@ -286,7 +268,7 @@ def test_product_search_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, @@ -345,7 +327,7 @@ def test_product_search_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 @@ -387,7 +369,7 @@ def test_product_search_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, @@ -409,7 +391,7 @@ def test_product_search_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, @@ -440,7 +422,7 @@ def test_product_search_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, @@ -471,7 +453,7 @@ def test_product_search_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", @@ -5543,7 +5525,6 @@ def test_product_search_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -5567,29 +5548,6 @@ def test_product_search_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_product_search_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( @@ -5601,7 +5559,6 @@ def test_product_search_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_product_search_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -5617,21 +5574,6 @@ def test_product_search_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -5639,7 +5581,6 @@ def test_product_search_auth_adc_old_google_auth(): transports.ProductSearchGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_product_search_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5656,29 +5597,6 @@ def test_product_search_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index a4c35d716015..173422716964 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -37,29 +36,12 @@ ) from google.cloud.vision_v1p1beta1.services.image_annotator import ImageAnnotatorClient from google.cloud.vision_v1p1beta1.services.image_annotator import transports -from google.cloud.vision_v1p1beta1.services.image_annotator.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p1beta1.types import image_annotator from google.oauth2 import service_account from google.type import latlng_pb2 # type: ignore 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" @@ -216,7 +198,7 @@ def test_image_annotator_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, @@ -233,7 +215,7 @@ def test_image_annotator_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, @@ -250,7 +232,7 @@ def test_image_annotator_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, @@ -279,7 +261,7 @@ def test_image_annotator_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, @@ -338,7 +320,7 @@ def test_image_annotator_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 @@ -380,7 +362,7 @@ def test_image_annotator_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, @@ -402,7 +384,7 @@ def test_image_annotator_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, @@ -433,7 +415,7 @@ def test_image_annotator_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, @@ -464,7 +446,7 @@ def test_image_annotator_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", @@ -790,7 +772,6 @@ def test_image_annotator_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -814,29 +795,6 @@ def test_image_annotator_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_image_annotator_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( @@ -848,7 +806,6 @@ def test_image_annotator_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_image_annotator_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -864,21 +821,6 @@ def test_image_annotator_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -886,7 +828,6 @@ def test_image_annotator_auth_adc_old_google_auth(): transports.ImageAnnotatorGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_image_annotator_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -903,29 +844,6 @@ def test_image_annotator_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index 3dc9c74c35d1..c3176d050129 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.vision_v1p2beta1.services.image_annotator import ImageAnnotatorClient from google.cloud.vision_v1p2beta1.services.image_annotator import transports -from google.cloud.vision_v1p2beta1.services.image_annotator.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p2beta1.types import image_annotator from google.longrunning import operations_pb2 from google.oauth2 import service_account @@ -50,20 +46,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" @@ -220,7 +202,7 @@ def test_image_annotator_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, @@ -237,7 +219,7 @@ def test_image_annotator_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, @@ -254,7 +236,7 @@ def test_image_annotator_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, @@ -283,7 +265,7 @@ def test_image_annotator_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, @@ -342,7 +324,7 @@ def test_image_annotator_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 @@ -384,7 +366,7 @@ def test_image_annotator_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, @@ -406,7 +388,7 @@ def test_image_annotator_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, @@ -437,7 +419,7 @@ def test_image_annotator_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, @@ -468,7 +450,7 @@ def test_image_annotator_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", @@ -1002,7 +984,6 @@ def test_image_annotator_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1026,29 +1007,6 @@ def test_image_annotator_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_image_annotator_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( @@ -1060,7 +1018,6 @@ def test_image_annotator_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_image_annotator_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1076,21 +1033,6 @@ def test_image_annotator_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1098,7 +1040,6 @@ def test_image_annotator_auth_adc_old_google_auth(): transports.ImageAnnotatorGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_image_annotator_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1115,29 +1056,6 @@ def test_image_annotator_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index 8dea7855b8a3..595422bcaf34 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.vision_v1p3beta1.services.image_annotator import ImageAnnotatorClient from google.cloud.vision_v1p3beta1.services.image_annotator import transports -from google.cloud.vision_v1p3beta1.services.image_annotator.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p3beta1.types import geometry from google.cloud.vision_v1p3beta1.types import image_annotator from google.cloud.vision_v1p3beta1.types import product_search @@ -52,20 +48,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" @@ -222,7 +204,7 @@ def test_image_annotator_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, @@ -239,7 +221,7 @@ def test_image_annotator_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, @@ -256,7 +238,7 @@ def test_image_annotator_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, @@ -285,7 +267,7 @@ def test_image_annotator_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, @@ -344,7 +326,7 @@ def test_image_annotator_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 @@ -386,7 +368,7 @@ def test_image_annotator_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, @@ -408,7 +390,7 @@ def test_image_annotator_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, @@ -439,7 +421,7 @@ def test_image_annotator_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, @@ -470,7 +452,7 @@ def test_image_annotator_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", @@ -1004,7 +986,6 @@ def test_image_annotator_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1028,29 +1009,6 @@ def test_image_annotator_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_image_annotator_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( @@ -1062,7 +1020,6 @@ def test_image_annotator_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_image_annotator_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1078,21 +1035,6 @@ def test_image_annotator_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1100,7 +1042,6 @@ def test_image_annotator_auth_adc_old_google_auth(): transports.ImageAnnotatorGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_image_annotator_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1117,29 +1058,6 @@ def test_image_annotator_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index 09a0c8feae2d..c5eaa0de4353 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -41,9 +40,6 @@ from google.cloud.vision_v1p3beta1.services.product_search import ProductSearchClient from google.cloud.vision_v1p3beta1.services.product_search import pagers from google.cloud.vision_v1p3beta1.services.product_search import transports -from google.cloud.vision_v1p3beta1.services.product_search.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p3beta1.types import geometry from google.cloud.vision_v1p3beta1.types import product_search_service from google.longrunning import operations_pb2 @@ -55,20 +51,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" @@ -225,7 +207,7 @@ def test_product_search_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, @@ -242,7 +224,7 @@ def test_product_search_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, @@ -259,7 +241,7 @@ def test_product_search_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, @@ -288,7 +270,7 @@ def test_product_search_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, @@ -347,7 +329,7 @@ def test_product_search_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 @@ -389,7 +371,7 @@ def test_product_search_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, @@ -411,7 +393,7 @@ def test_product_search_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, @@ -442,7 +424,7 @@ def test_product_search_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, @@ -473,7 +455,7 @@ def test_product_search_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", @@ -5343,7 +5325,6 @@ def test_product_search_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -5367,29 +5348,6 @@ def test_product_search_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_product_search_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( @@ -5401,7 +5359,6 @@ def test_product_search_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_product_search_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -5417,21 +5374,6 @@ def test_product_search_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -5439,7 +5381,6 @@ def test_product_search_auth_adc_old_google_auth(): transports.ProductSearchGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_product_search_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5456,29 +5397,6 @@ def test_product_search_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index aab0a04f273c..813316f0839e 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.vision_v1p4beta1.services.image_annotator import ImageAnnotatorClient from google.cloud.vision_v1p4beta1.services.image_annotator import transports -from google.cloud.vision_v1p4beta1.services.image_annotator.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p4beta1.types import face from google.cloud.vision_v1p4beta1.types import geometry from google.cloud.vision_v1p4beta1.types import image_annotator @@ -53,20 +49,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" @@ -223,7 +205,7 @@ def test_image_annotator_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, @@ -240,7 +222,7 @@ def test_image_annotator_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, @@ -257,7 +239,7 @@ def test_image_annotator_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, @@ -286,7 +268,7 @@ def test_image_annotator_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, @@ -345,7 +327,7 @@ def test_image_annotator_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 @@ -387,7 +369,7 @@ def test_image_annotator_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, @@ -409,7 +391,7 @@ def test_image_annotator_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, @@ -440,7 +422,7 @@ def test_image_annotator_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, @@ -471,7 +453,7 @@ def test_image_annotator_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", @@ -1414,7 +1396,6 @@ def test_image_annotator_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1438,29 +1419,6 @@ def test_image_annotator_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_image_annotator_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( @@ -1472,7 +1430,6 @@ def test_image_annotator_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_image_annotator_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1488,21 +1445,6 @@ def test_image_annotator_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1510,7 +1452,6 @@ def test_image_annotator_auth_adc_old_google_auth(): transports.ImageAnnotatorGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_image_annotator_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1527,29 +1468,6 @@ def test_image_annotator_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index afc237d2b2a2..a34ee76a3da8 100644 --- a/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/packages/google-cloud-vision/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -41,9 +40,6 @@ from google.cloud.vision_v1p4beta1.services.product_search import ProductSearchClient from google.cloud.vision_v1p4beta1.services.product_search import pagers from google.cloud.vision_v1p4beta1.services.product_search import transports -from google.cloud.vision_v1p4beta1.services.product_search.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.vision_v1p4beta1.types import geometry from google.cloud.vision_v1p4beta1.types import product_search_service from google.longrunning import operations_pb2 @@ -55,20 +51,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" @@ -225,7 +207,7 @@ def test_product_search_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, @@ -242,7 +224,7 @@ def test_product_search_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, @@ -259,7 +241,7 @@ def test_product_search_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, @@ -288,7 +270,7 @@ def test_product_search_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, @@ -347,7 +329,7 @@ def test_product_search_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 @@ -389,7 +371,7 @@ def test_product_search_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, @@ -411,7 +393,7 @@ def test_product_search_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, @@ -442,7 +424,7 @@ def test_product_search_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, @@ -473,7 +455,7 @@ def test_product_search_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", @@ -5545,7 +5527,6 @@ def test_product_search_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_product_search_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -5569,29 +5550,6 @@ def test_product_search_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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-vision", - ), - quota_project_id="octopus", - ) - - def test_product_search_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( @@ -5603,7 +5561,6 @@ def test_product_search_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_product_search_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -5619,21 +5576,6 @@ def test_product_search_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-vision", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -5641,7 +5583,6 @@ def test_product_search_auth_adc_old_google_auth(): transports.ProductSearchGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_product_search_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5658,29 +5599,6 @@ def test_product_search_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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-vision", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [