From 2dca76c8520c8ade8a466f53e55d0db18834c7cc Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:42:13 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#234) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../async_client.py | 22 +++-- .../document_processor_service/client.py | 8 +- .../transports/base.py | 37 +------- .../transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../cloud/documentai_v1/types/document.py | 30 ++++++ .../cloud/documentai_v1/types/document_io.py | 13 +++ .../types/document_processor_service.py | 12 +++ .../async_client.py | 18 ++-- .../document_understanding_service/client.py | 6 +- .../transports/base.py | 37 +------- .../transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../documentai_v1beta2/types/document.py | 13 +++ .../types/document_understanding.py | 12 +++ .../async_client.py | 60 ++++++------ .../document_processor_service/client.py | 20 ++-- .../transports/base.py | 37 +------- .../transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../documentai_v1beta3/types/document.py | 30 ++++++ .../documentai_v1beta3/types/document_io.py | 13 +++ .../types/document_processor_service.py | 13 +++ packages/google-cloud-documentai/setup.py | 3 +- .../testing/constraints-3.6.txt | 4 +- .../test_document_processor_service.py | 91 ++---------------- .../test_document_understanding_service.py | 93 ++----------------- .../test_document_processor_service.py | 91 ++---------------- 28 files changed, 252 insertions(+), 426 deletions(-) diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py index b4cfb8cd36b5..b60c4fb21cc2 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/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.documentai_v1.types import document @@ -183,17 +185,17 @@ def __init__( async def process_document( self, - request: document_processor_service.ProcessRequest = None, + request: Union[document_processor_service.ProcessRequest, 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]] = (), ) -> document_processor_service.ProcessResponse: r"""Processes a single document. Args: - request (:class:`google.cloud.documentai_v1.types.ProcessRequest`): + request (Union[google.cloud.documentai_v1.types.ProcessRequest, dict]): The request object. Request message for the process document method. name (:class:`str`): @@ -264,10 +266,10 @@ async def process_document( async def batch_process_documents( self, - request: document_processor_service.BatchProcessRequest = None, + request: Union[document_processor_service.BatchProcessRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -275,7 +277,7 @@ async def batch_process_documents( written to Cloud Storage as JSON in the [Document] format. Args: - request (:class:`google.cloud.documentai_v1.types.BatchProcessRequest`): + request (Union[google.cloud.documentai_v1.types.BatchProcessRequest, dict]): The request object. Request message for batch process document method. name (:class:`str`): @@ -357,10 +359,10 @@ async def batch_process_documents( async def review_document( self, - request: document_processor_service.ReviewDocumentRequest = None, + request: Union[document_processor_service.ReviewDocumentRequest, dict] = None, *, human_review_config: 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: @@ -368,7 +370,7 @@ async def review_document( should be processed by the specified processor. Args: - request (:class:`google.cloud.documentai_v1.types.ReviewDocumentRequest`): + request (Union[google.cloud.documentai_v1.types.ReviewDocumentRequest, dict]): The request object. Request message for review document method. human_review_config (:class:`str`): diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py index f094486eaecf..0ea8ab3243d7 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/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.documentai_v1.types import document @@ -377,7 +379,7 @@ def process_document( request: Union[document_processor_service.ProcessRequest, 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]] = (), ) -> document_processor_service.ProcessResponse: @@ -448,7 +450,7 @@ def batch_process_documents( request: Union[document_processor_service.BatchProcessRequest, 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]] = (), ) -> operation.Operation: @@ -531,7 +533,7 @@ def review_document( request: Union[document_processor_service.ReviewDocumentRequest, dict] = None, *, human_review_config: 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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index c01879dcccf4..0675db22a4e7 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/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 @@ -39,15 +38,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 DocumentProcessorServiceTransport(abc.ABC): """Abstract transport class for DocumentProcessorService.""" @@ -97,7 +87,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 @@ -130,29 +120,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 = { @@ -213,7 +180,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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index ea350b190992..6b1f89f7d90e 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -116,7 +116,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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index bfb639af6fe0..75b35ea35faa 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/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 @@ -163,7 +162,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-documentai/google/cloud/documentai_v1/types/document.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document.py index 711f74106040..3ca79a6c4a01 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document.py @@ -37,6 +37,13 @@ class Document(proto.Message): documents and allows for collaboration between users and Document Understanding AI to iterate and optimize for quality. + 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: uri (str): Optional. Currently supports Google Cloud Storage URI of the @@ -44,11 +51,13 @@ class Document(proto.Message): not supported. See `Google Cloud Storage Request URIs `__ for more info. + This field is a member of `oneof`_ ``source``. content (bytes): Optional. Inline document content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. + This field is a member of `oneof`_ ``source``. mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see @@ -683,24 +692,36 @@ class Entity(proto.Message): class NormalizedValue(proto.Message): r"""Parsed and normalized entity value. + 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: money_value (google.type.money_pb2.Money): Money value. See also: https://github.com/googleapis/googleapis/blob/master/google/type/money.proto + This field is a member of `oneof`_ ``structured_value``. date_value (google.type.date_pb2.Date): Date value. Includes year, month, day. See also: https://github.com/googleapis/googleapis/blob/master/google/type/date.proto + This field is a member of `oneof`_ ``structured_value``. datetime_value (google.type.datetime_pb2.DateTime): DateTime value. Includes date, time, and timezone. See also: https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto + This field is a member of `oneof`_ ``structured_value``. address_value (google.type.postal_address_pb2.PostalAddress): Postal address. See also: https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto + This field is a member of `oneof`_ ``structured_value``. boolean_value (bool): Boolean value. Can be used for entities with binary values, or for checkboxes. + This field is a member of `oneof`_ ``structured_value``. text (str): Required. Normalized entity value stored as a string. This field is populated for supported document type (e.g. @@ -947,13 +968,22 @@ class Parent(proto.Message): class Revision(proto.Message): r"""Contains past or forward revisions of this document. + 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: agent (str): If the change was made by a person specify the name or id of that person. + This field is a member of `oneof`_ ``source``. processor (str): If the annotation was made by processor identify the processor by its resource name. + This field is a member of `oneof`_ ``source``. id (str): Id of the revision. Unique within the context of the document. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_io.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_io.py index 4692f6d96350..715b9dfe4c54 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_io.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_io.py @@ -85,13 +85,22 @@ class BatchDocumentsInputConfig(proto.Message): r"""The common config to specify a set of documents used as input. + 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: gcs_prefix (google.cloud.documentai_v1.types.GcsPrefix): The set of documents that match the specified Cloud Storage [gcs_prefix]. + This field is a member of `oneof`_ ``source``. gcs_documents (google.cloud.documentai_v1.types.GcsDocuments): The set of documents individually specified on Cloud Storage. + This field is a member of `oneof`_ ``source``. """ gcs_prefix = proto.Field( @@ -106,10 +115,14 @@ class DocumentOutputConfig(proto.Message): r"""Config that controls the output of documents. All documents will be written as a JSON file. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig.GcsOutputConfig): Output config to write the results to Cloud Storage. + This field is a member of `oneof`_ ``destination``. """ class GcsOutputConfig(proto.Message): diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_processor_service.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_processor_service.py index 8955dfe23cc7..1f543b2d908e 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_processor_service.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/types/document_processor_service.py @@ -41,11 +41,20 @@ class ProcessRequest(proto.Message): r"""Request message for the process document 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: inline_document (google.cloud.documentai_v1.types.Document): An inline document proto. + This field is a member of `oneof`_ ``source``. raw_document (google.cloud.documentai_v1.types.RawDocument): A raw document content (bytes). + This field is a member of `oneof`_ ``source``. name (str): Required. The processor resource name. skip_human_review (bool): @@ -212,9 +221,12 @@ class IndividualProcessStatus(proto.Message): class ReviewDocumentRequest(proto.Message): r"""Request message for review document method. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: inline_document (google.cloud.documentai_v1.types.Document): An inline document proto. + This field is a member of `oneof`_ ``source``. human_review_config (str): Required. The resource name of the HumanReviewConfig that the document will be diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py index 206ccd6e5350..2c7a3fa275b4 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/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.documentai_v1beta2.types import document @@ -174,10 +176,12 @@ def __init__( async def batch_process_documents( self, - request: document_understanding.BatchProcessDocumentsRequest = None, + request: Union[ + document_understanding.BatchProcessDocumentsRequest, dict + ] = None, *, requests: Sequence[document_understanding.ProcessDocumentRequest] = 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: @@ -185,7 +189,7 @@ async def batch_process_documents( written to Cloud Storage as JSON in the [Document] format. Args: - request (:class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest`): + request (Union[google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest, dict]): The request object. Request to batch process documents as an asynchronous operation. The output is written to Cloud Storage as JSON in the [Document] format. @@ -267,16 +271,16 @@ async def batch_process_documents( async def process_document( self, - request: document_understanding.ProcessDocumentRequest = None, + request: Union[document_understanding.ProcessDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: r"""Processes a single document. Args: - request (:class:`google.cloud.documentai_v1beta2.types.ProcessDocumentRequest`): + request (Union[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest, dict]): The request object. Request to process one document. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index a35bd0372c55..7f54b66291b3 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/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.documentai_v1beta2.types import document @@ -350,7 +352,7 @@ def batch_process_documents( ] = None, *, requests: Sequence[document_understanding.ProcessDocumentRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -432,7 +434,7 @@ def process_document( self, request: Union[document_understanding.ProcessDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index bd478c7b2f36..12bb81013680 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -40,15 +39,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class DocumentUnderstandingServiceTransport(abc.ABC): """Abstract transport class for DocumentUnderstandingService.""" @@ -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-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index 6c42f8012bc8..4176ebba1159 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/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-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index fabd9696f270..93c876988eab 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/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 @@ -164,7 +163,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-documentai/google/cloud/documentai_v1beta2/types/document.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document.py index 5b4214777907..5dad81a885d2 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document.py @@ -32,6 +32,13 @@ class Document(proto.Message): documents and allows for collaboration between users and Document Understanding AI to iterate and optimize for quality. + 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: uri (str): Currently supports Google Cloud Storage URI of the form @@ -39,11 +46,13 @@ class Document(proto.Message): supported. See `Google Cloud Storage Request URIs `__ for more info. + This field is a member of `oneof`_ ``source``. content (bytes): Inline document content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. + This field is a member of `oneof`_ ``source``. mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see @@ -107,6 +116,9 @@ class Label(proto.Message): instances of the same label created at different times, or some combination of both. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: automl_model (str): Label is generated AutoML model. This field stores the full @@ -114,6 +126,7 @@ class Label(proto.Message): Format: ``projects/{project-id}/locations/{location-id}/models/{model-id}`` + This field is a member of `oneof`_ ``source``. name (str): Name of the label. When the label is generated from AutoML Text diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document_understanding.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document_understanding.py index f36ad3b57930..9280d8a81992 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document_understanding.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/types/document_understanding.py @@ -314,10 +314,18 @@ class AutoMlParams(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + 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: gcs_source (google.cloud.documentai_v1beta2.types.GcsSource): The Google Cloud Storage location to read the input from. This must be a single file. + This field is a member of `oneof`_ ``source``. contents (bytes): Content in bytes, represented as a stream of bytes. Note: As with all ``bytes`` fields, proto buffer messages use a pure @@ -326,6 +334,7 @@ class InputConfig(proto.Message): This field only works for synchronous ProcessDocument method. + This field is a member of `oneof`_ ``source``. mime_type (str): Required. Mimetype of the input. Current supported mimetypes are application/pdf, image/tiff, and image/gif. In addition, @@ -345,10 +354,13 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.documentai_v1beta2.types.GcsDestination): The Google Cloud Storage location to write the output to. + This field is a member of `oneof`_ ``destination``. pages_per_shard (int): The max number of pages to include into each output Document shard JSON on Google Cloud Storage. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index ea5a8ffa895d..00543d792045 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/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.documentai_v1beta3.services.document_processor_service import pagers @@ -195,17 +197,17 @@ def __init__( async def process_document( self, - request: document_processor_service.ProcessRequest = None, + request: Union[document_processor_service.ProcessRequest, 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]] = (), ) -> document_processor_service.ProcessResponse: r"""Processes a single document. Args: - request (:class:`google.cloud.documentai_v1beta3.types.ProcessRequest`): + request (Union[google.cloud.documentai_v1beta3.types.ProcessRequest, dict]): The request object. Request message for the process document method. name (:class:`str`): @@ -276,10 +278,10 @@ async def process_document( async def batch_process_documents( self, - request: document_processor_service.BatchProcessRequest = None, + request: Union[document_processor_service.BatchProcessRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -287,7 +289,7 @@ async def batch_process_documents( written to Cloud Storage as JSON in the [Document] format. Args: - request (:class:`google.cloud.documentai_v1beta3.types.BatchProcessRequest`): + request (Union[google.cloud.documentai_v1beta3.types.BatchProcessRequest, dict]): The request object. Request message for batch process document method. name (:class:`str`): @@ -369,17 +371,19 @@ async def batch_process_documents( async def fetch_processor_types( self, - request: document_processor_service.FetchProcessorTypesRequest = None, + request: Union[ + document_processor_service.FetchProcessorTypesRequest, 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]] = (), ) -> document_processor_service.FetchProcessorTypesResponse: r"""Fetches processor types. Args: - request (:class:`google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest`): + request (Union[google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest, dict]): The request object. Request message for fetch processor types. parent (:class:`str`): @@ -441,17 +445,17 @@ async def fetch_processor_types( async def list_processors( self, - request: document_processor_service.ListProcessorsRequest = None, + request: Union[document_processor_service.ListProcessorsRequest, 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.ListProcessorsAsyncPager: r"""Lists all processors which belong to this project. Args: - request (:class:`google.cloud.documentai_v1beta3.types.ListProcessorsRequest`): + request (Union[google.cloud.documentai_v1beta3.types.ListProcessorsRequest, dict]): The request object. Request message for list all processors belongs to a project. parent (:class:`str`): @@ -522,11 +526,11 @@ async def list_processors( async def create_processor( self, - request: document_processor_service.CreateProcessorRequest = None, + request: Union[document_processor_service.CreateProcessorRequest, dict] = None, *, parent: str = None, processor: gcd_processor.Processor = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_processor.Processor: @@ -535,7 +539,7 @@ async def create_processor( default after its creation. Args: - request (:class:`google.cloud.documentai_v1beta3.types.CreateProcessorRequest`): + request (Union[google.cloud.documentai_v1beta3.types.CreateProcessorRequest, dict]): The request object. Request message for create a processor. Notice this request is sent to a regionalized backend service, and if the processor type is not @@ -612,10 +616,10 @@ async def create_processor( async def delete_processor( self, - request: document_processor_service.DeleteProcessorRequest = None, + request: Union[document_processor_service.DeleteProcessorRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -624,7 +628,7 @@ async def delete_processor( artifacts associated with this processor. Args: - request (:class:`google.cloud.documentai_v1beta3.types.DeleteProcessorRequest`): + request (Union[google.cloud.documentai_v1beta3.types.DeleteProcessorRequest, dict]): The request object. Request message for the delete processor method. name (:class:`str`): @@ -706,16 +710,16 @@ async def delete_processor( async def enable_processor( self, - request: document_processor_service.EnableProcessorRequest = None, + request: Union[document_processor_service.EnableProcessorRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Enables a processor Args: - request (:class:`google.cloud.documentai_v1beta3.types.EnableProcessorRequest`): + request (Union[google.cloud.documentai_v1beta3.types.EnableProcessorRequest, dict]): The request object. Request message for the enable processor method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -766,16 +770,16 @@ async def enable_processor( async def disable_processor( self, - request: document_processor_service.DisableProcessorRequest = None, + request: Union[document_processor_service.DisableProcessorRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Disables a processor Args: - request (:class:`google.cloud.documentai_v1beta3.types.DisableProcessorRequest`): + request (Union[google.cloud.documentai_v1beta3.types.DisableProcessorRequest, dict]): The request object. Request message for the disable processor method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -826,10 +830,10 @@ async def disable_processor( async def review_document( self, - request: document_processor_service.ReviewDocumentRequest = None, + request: Union[document_processor_service.ReviewDocumentRequest, dict] = None, *, human_review_config: 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: @@ -837,7 +841,7 @@ async def review_document( should be processed by the specified processor. Args: - request (:class:`google.cloud.documentai_v1beta3.types.ReviewDocumentRequest`): + request (Union[google.cloud.documentai_v1beta3.types.ReviewDocumentRequest, dict]): The request object. Request message for review document method. Next Id: 6. human_review_config (:class:`str`): diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index 958223dc74c2..eb6f18c0e5e1 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/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.documentai_v1beta3.services.document_processor_service import pagers @@ -399,7 +401,7 @@ def process_document( request: Union[document_processor_service.ProcessRequest, 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]] = (), ) -> document_processor_service.ProcessResponse: @@ -470,7 +472,7 @@ def batch_process_documents( request: Union[document_processor_service.BatchProcessRequest, 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]] = (), ) -> operation.Operation: @@ -555,7 +557,7 @@ def fetch_processor_types( ] = 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]] = (), ) -> document_processor_service.FetchProcessorTypesResponse: @@ -629,7 +631,7 @@ def list_processors( request: Union[document_processor_service.ListProcessorsRequest, 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.ListProcessorsPager: @@ -711,7 +713,7 @@ def create_processor( *, parent: str = None, processor: gcd_processor.Processor = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_processor.Processor: @@ -800,7 +802,7 @@ def delete_processor( request: Union[document_processor_service.DeleteProcessorRequest, 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]] = (), ) -> operation.Operation: @@ -893,7 +895,7 @@ def enable_processor( self, request: Union[document_processor_service.EnableProcessorRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -954,7 +956,7 @@ def disable_processor( self, request: Union[document_processor_service.DisableProcessorRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1016,7 +1018,7 @@ def review_document( request: Union[document_processor_service.ReviewDocumentRequest, dict] = None, *, human_review_config: 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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index fa1b23f23d06..ba99f93af977 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -40,15 +39,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class DocumentProcessorServiceTransport(abc.ABC): """Abstract transport class for DocumentProcessorService.""" @@ -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 = { @@ -234,7 +201,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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index 8382c9d5d089..f85488186117 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -117,7 +117,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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index fd19a769ae2b..2b90cbdce010 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/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 @@ -164,7 +163,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-documentai/google/cloud/documentai_v1beta3/types/document.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document.py index 6c428279d20a..7be0ee2472e1 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document.py @@ -37,6 +37,13 @@ class Document(proto.Message): documents and allows for collaboration between users and Document Understanding AI to iterate and optimize for quality. + 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: uri (str): Optional. Currently supports Google Cloud Storage URI of the @@ -44,11 +51,13 @@ class Document(proto.Message): not supported. See `Google Cloud Storage Request URIs `__ for more info. + This field is a member of `oneof`_ ``source``. content (bytes): Optional. Inline document content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. + This field is a member of `oneof`_ ``source``. mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see @@ -687,24 +696,36 @@ class Entity(proto.Message): class NormalizedValue(proto.Message): r"""Parsed and normalized entity value. + 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: money_value (google.type.money_pb2.Money): Money value. See also: https://github.com/googleapis/googleapis/blob/master/google/type/money.proto + This field is a member of `oneof`_ ``structured_value``. date_value (google.type.date_pb2.Date): Date value. Includes year, month, day. See also: https://github.com/googleapis/googleapis/blob/master/google/type/date.proto + This field is a member of `oneof`_ ``structured_value``. datetime_value (google.type.datetime_pb2.DateTime): DateTime value. Includes date, time, and timezone. See also: https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto + This field is a member of `oneof`_ ``structured_value``. address_value (google.type.postal_address_pb2.PostalAddress): Postal address. See also: https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto + This field is a member of `oneof`_ ``structured_value``. boolean_value (bool): Boolean value. Can be used for entities with binary values, or for checkboxes. + This field is a member of `oneof`_ ``structured_value``. text (str): Required. Normalized entity value stored as a string. This field is populated for supported document type (e.g. @@ -951,13 +972,22 @@ class Parent(proto.Message): class Revision(proto.Message): r"""Contains past or forward revisions of this document. + 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: agent (str): If the change was made by a person specify the name or id of that person. + This field is a member of `oneof`_ ``source``. processor (str): If the annotation was made by processor identify the processor by its resource name. + This field is a member of `oneof`_ ``source``. id (str): Id of the revision. Unique within the context of the document. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_io.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_io.py index 71831439b019..3303e0edb198 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_io.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_io.py @@ -85,13 +85,22 @@ class BatchDocumentsInputConfig(proto.Message): r"""The common config to specify a set of documents used as input. + 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: gcs_prefix (google.cloud.documentai_v1beta3.types.GcsPrefix): The set of documents that match the specified Cloud Storage [gcs_prefix]. + This field is a member of `oneof`_ ``source``. gcs_documents (google.cloud.documentai_v1beta3.types.GcsDocuments): The set of documents individually specified on Cloud Storage. + This field is a member of `oneof`_ ``source``. """ gcs_prefix = proto.Field( @@ -106,10 +115,14 @@ class DocumentOutputConfig(proto.Message): r"""Config that controls the output of documents. All documents will be written as a JSON file. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_output_config (google.cloud.documentai_v1beta3.types.DocumentOutputConfig.GcsOutputConfig): Output config to write the results to Cloud Storage. + This field is a member of `oneof`_ ``destination``. """ class GcsOutputConfig(proto.Message): diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_processor_service.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_processor_service.py index 7a26d2bc6b8a..f5fd524556ca 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -56,11 +56,20 @@ class ProcessRequest(proto.Message): r"""Request message for the process document 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: inline_document (google.cloud.documentai_v1beta3.types.Document): An inline document proto. + This field is a member of `oneof`_ ``source``. raw_document (google.cloud.documentai_v1beta3.types.RawDocument): A raw document content (bytes). + This field is a member of `oneof`_ ``source``. name (str): Required. The processor resource name. document (google.cloud.documentai_v1beta3.types.Document): @@ -467,9 +476,13 @@ class ReviewDocumentRequest(proto.Message): r"""Request message for review document method. Next Id: 6. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: inline_document (google.cloud.documentai_v1beta3.types.Document): An inline document proto. + This field is a member of `oneof`_ ``source``. human_review_config (str): Required. The resource name of the HumanReviewConfig that the document will be diff --git a/packages/google-cloud-documentai/setup.py b/packages/google-cloud-documentai/setup.py index e9602ff5fbdd..112467716028 100644 --- a/packages/google-cloud-documentai/setup.py +++ b/packages/google-cloud-documentai/setup.py @@ -48,9 +48,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.10.0", - "packaging >= 14.3", ), python_requires=">=3.6", setup_requires=["libcst >= 0.2.5"], diff --git a/packages/google-cloud-documentai/testing/constraints-3.6.txt b/packages/google-cloud-documentai/testing/constraints-3.6.txt index 63d16e7e9cb5..da8c5737dc9d 100644 --- a/packages/google-cloud-documentai/testing/constraints-3.6.txt +++ b/packages/google-cloud-documentai/testing/constraints-3.6.txt @@ -5,7 +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.10.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py index 14c874faeba5..bbc3db0de29d 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -42,9 +41,6 @@ DocumentProcessorServiceClient, ) from google.cloud.documentai_v1.services.document_processor_service import transports -from google.cloud.documentai_v1.services.document_processor_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.documentai_v1.types import document from google.cloud.documentai_v1.types import document_io from google.cloud.documentai_v1.types import document_processor_service @@ -64,20 +60,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" @@ -245,7 +227,7 @@ def test_document_processor_service_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, @@ -262,7 +244,7 @@ def test_document_processor_service_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, @@ -279,7 +261,7 @@ def test_document_processor_service_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, @@ -308,7 +290,7 @@ def test_document_processor_service_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, @@ -377,7 +359,7 @@ def test_document_processor_service_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 @@ -419,7 +401,7 @@ def test_document_processor_service_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, @@ -441,7 +423,7 @@ def test_document_processor_service_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, @@ -476,7 +458,7 @@ def test_document_processor_service_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, @@ -511,7 +493,7 @@ def test_document_processor_service_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", @@ -1308,7 +1290,6 @@ def test_document_processor_service_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1329,26 +1310,6 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_document_processor_service_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( @@ -1360,7 +1321,6 @@ def test_document_processor_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_document_processor_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1373,18 +1333,6 @@ def test_document_processor_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1392,7 +1340,6 @@ def test_document_processor_service_auth_adc_old_google_auth(): transports.DocumentProcessorServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_document_processor_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1406,26 +1353,6 @@ def test_document_processor_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 6aa3f59c2fd3..39765111cbf9 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -44,9 +43,6 @@ from google.cloud.documentai_v1beta2.services.document_understanding_service import ( transports, ) -from google.cloud.documentai_v1beta2.services.document_understanding_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.documentai_v1beta2.types import document from google.cloud.documentai_v1beta2.types import document_understanding from google.cloud.documentai_v1beta2.types import geometry @@ -56,20 +52,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" @@ -239,7 +221,7 @@ def test_document_understanding_service_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, @@ -256,7 +238,7 @@ def test_document_understanding_service_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, @@ -273,7 +255,7 @@ def test_document_understanding_service_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, @@ -302,7 +284,7 @@ def test_document_understanding_service_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, @@ -371,7 +353,7 @@ def test_document_understanding_service_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 @@ -413,7 +395,7 @@ def test_document_understanding_service_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, @@ -435,7 +417,7 @@ def test_document_understanding_service_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, @@ -470,7 +452,7 @@ def test_document_understanding_service_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, @@ -505,7 +487,7 @@ def test_document_understanding_service_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", @@ -1034,7 +1016,6 @@ def test_document_understanding_service_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_document_understanding_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1055,26 +1036,6 @@ def test_document_understanding_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_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.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentUnderstandingServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_document_understanding_service_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( @@ -1086,7 +1047,6 @@ def test_document_understanding_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_document_understanding_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1099,18 +1059,6 @@ def test_document_understanding_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_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) - DocumentUnderstandingServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1118,7 +1066,6 @@ def test_document_understanding_service_auth_adc_old_google_auth(): transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_document_understanding_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1132,28 +1079,6 @@ def test_document_understanding_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentUnderstandingServiceGrpcTransport, - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_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",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 45746ed32542..df7daeb767f8 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -45,9 +44,6 @@ from google.cloud.documentai_v1beta3.services.document_processor_service import ( transports, ) -from google.cloud.documentai_v1beta3.services.document_processor_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.documentai_v1beta3.types import document from google.cloud.documentai_v1beta3.types import document_io from google.cloud.documentai_v1beta3.types import document_processor_service @@ -70,20 +66,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" @@ -251,7 +233,7 @@ def test_document_processor_service_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, @@ -268,7 +250,7 @@ def test_document_processor_service_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, @@ -285,7 +267,7 @@ def test_document_processor_service_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, @@ -314,7 +296,7 @@ def test_document_processor_service_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, @@ -383,7 +365,7 @@ def test_document_processor_service_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 @@ -425,7 +407,7 @@ def test_document_processor_service_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, @@ -447,7 +429,7 @@ def test_document_processor_service_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, @@ -482,7 +464,7 @@ def test_document_processor_service_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, @@ -517,7 +499,7 @@ def test_document_processor_service_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", @@ -2656,7 +2638,6 @@ def test_document_processor_service_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2677,26 +2658,6 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_document_processor_service_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( @@ -2708,7 +2669,6 @@ def test_document_processor_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_document_processor_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2721,18 +2681,6 @@ def test_document_processor_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2740,7 +2688,6 @@ def test_document_processor_service_auth_adc_old_google_auth(): transports.DocumentProcessorServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_document_processor_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2754,26 +2701,6 @@ def test_document_processor_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_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",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [