diff --git a/.flake8 b/.flake8 index 29227d4c..2e438749 100644 --- a/.flake8 +++ b/.flake8 @@ -16,7 +16,7 @@ # Generated by synthtool. DO NOT EDIT! [flake8] -ignore = E203, E266, E501, W503 +ignore = E203, E231, E266, E501, W503 exclude = # Exclude generated code. **/proto/** diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 44c78f7c..64f82d6b 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4e1991042fe54b991db9ca17c8fb386e61b22fe4d1472a568bf0fcac85dcf5d3 + digest: sha256:bc5eed3804aec2f05fad42aacf973821d9500c174015341f721a984a0825b6fd +# created: 2022-04-21T15:43:16.246106921Z diff --git a/samples/snippets/set_endpoint_v1beta2_test.py b/.github/auto-label.yaml similarity index 52% rename from samples/snippets/set_endpoint_v1beta2_test.py rename to .github/auto-label.yaml index be535a28..41bff0b5 100644 --- a/samples/snippets/set_endpoint_v1beta2_test.py +++ b/.github/auto-label.yaml @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -9,19 +9,7 @@ # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and +# See the License for the specific language governing permissions and # limitations under the License. - -import os - -from samples.snippets import set_endpoint_v1beta2 - - -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" - - -def test_set_endpoint(capsys): - set_endpoint_v1beta2.set_endpoint(PROJECT_ID, INPUT_URI) - out, _ = capsys.readouterr() - assert "Document Text" in out +requestsize: + enabled: true diff --git a/.github/release-please.yml b/.github/release-please.yml index 466597e5..6def37a8 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1,2 +1,8 @@ releaseType: python handleGHRelease: true +# NOTE: this section is generated by synthtool.languages.python +# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py +branches: +- branch: v0 + handleGHRelease: true + releaseType: python diff --git a/.kokoro/docker/docs/Dockerfile b/.kokoro/docker/docs/Dockerfile index 4e1b1fb8..238b87b9 100644 --- a/.kokoro/docker/docs/Dockerfile +++ b/.kokoro/docker/docs/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ubuntu:20.04 +from ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -60,8 +60,24 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && rm -f /var/cache/apt/archives/*.deb +###################### Install python 3.8.11 + +# Download python 3.8.11 +RUN wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz + +# Extract files +RUN tar -xvf Python-3.8.11.tgz + +# Install python 3.8.11 +RUN ./Python-3.8.11/configure --enable-optimizations +RUN make altinstall + +###################### Install pip RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ - && python3.8 /tmp/get-pip.py \ + && python3 /tmp/get-pip.py \ && rm /tmp/get-pip.py +# Test pip +RUN python3 -m pip + CMD ["python3.8"] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62eb5a77..46d23716 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/CHANGELOG.md b/CHANGELOG.md index d952f926..e4e3ef3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### [1.4.1](https://github.com/googleapis/python-documentai/compare/v1.4.0...v1.4.1) (2022-04-28) + + +### Bug Fixes + +* mark Document.Entity.type as REQUIRED in all versions ([#317](https://github.com/googleapis/python-documentai/issues/317)) ([2d82c64](https://github.com/googleapis/python-documentai/commit/2d82c64b5034bb6315031c31a11198a6f3b7f393)) +* remove Document.Entity.bounding_poly_for_demo_frontend from v1beta2 ([2d82c64](https://github.com/googleapis/python-documentai/commit/2d82c64b5034bb6315031c31a11198a6f3b7f393)) + ## [1.4.0](https://github.com/googleapis/python-documentai/compare/v1.3.0...v1.4.0) (2022-03-19) diff --git a/docs/conf.py b/docs/conf.py index 17981c4e..bc32283e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,9 +24,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os import shlex +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -361,7 +361,10 @@ intersphinx_mapping = { "python": ("https://python.readthedocs.org/en/latest/", None), "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), diff --git a/google/cloud/documentai/__init__.py b/google/cloud/documentai/__init__.py index 0687f19b..13b35504 100644 --- a/google/cloud/documentai/__init__.py +++ b/google/cloud/documentai/__init__.py @@ -14,46 +14,37 @@ # limitations under the License. # -from google.cloud.documentai_v1.services.document_processor_service.client import ( - DocumentProcessorServiceClient, -) from google.cloud.documentai_v1.services.document_processor_service.async_client import ( DocumentProcessorServiceAsyncClient, ) - +from google.cloud.documentai_v1.services.document_processor_service.client import ( + DocumentProcessorServiceClient, +) from google.cloud.documentai_v1.types.document import Document -from google.cloud.documentai_v1.types.document_io import BatchDocumentsInputConfig -from google.cloud.documentai_v1.types.document_io import DocumentOutputConfig -from google.cloud.documentai_v1.types.document_io import GcsDocument -from google.cloud.documentai_v1.types.document_io import GcsDocuments -from google.cloud.documentai_v1.types.document_io import GcsPrefix -from google.cloud.documentai_v1.types.document_io import RawDocument -from google.cloud.documentai_v1.types.document_processor_service import ( - BatchProcessMetadata, +from google.cloud.documentai_v1.types.document_io import ( + BatchDocumentsInputConfig, + DocumentOutputConfig, + GcsDocument, + GcsDocuments, + GcsPrefix, + RawDocument, ) from google.cloud.documentai_v1.types.document_processor_service import ( + BatchProcessMetadata, BatchProcessRequest, -) -from google.cloud.documentai_v1.types.document_processor_service import ( BatchProcessResponse, -) -from google.cloud.documentai_v1.types.document_processor_service import ( HumanReviewStatus, -) -from google.cloud.documentai_v1.types.document_processor_service import ProcessRequest -from google.cloud.documentai_v1.types.document_processor_service import ProcessResponse -from google.cloud.documentai_v1.types.document_processor_service import ( + ProcessRequest, + ProcessResponse, ReviewDocumentOperationMetadata, -) -from google.cloud.documentai_v1.types.document_processor_service import ( ReviewDocumentRequest, -) -from google.cloud.documentai_v1.types.document_processor_service import ( ReviewDocumentResponse, ) -from google.cloud.documentai_v1.types.geometry import BoundingPoly -from google.cloud.documentai_v1.types.geometry import NormalizedVertex -from google.cloud.documentai_v1.types.geometry import Vertex +from google.cloud.documentai_v1.types.geometry import ( + BoundingPoly, + NormalizedVertex, + Vertex, +) from google.cloud.documentai_v1.types.operation_metadata import CommonOperationMetadata __all__ = ( diff --git a/google/cloud/documentai_v1/__init__.py b/google/cloud/documentai_v1/__init__.py index 2b683bd7..735cb126 100644 --- a/google/cloud/documentai_v1/__init__.py +++ b/google/cloud/documentai_v1/__init__.py @@ -14,28 +14,31 @@ # limitations under the License. # -from .services.document_processor_service import DocumentProcessorServiceClient -from .services.document_processor_service import DocumentProcessorServiceAsyncClient - +from .services.document_processor_service import ( + DocumentProcessorServiceAsyncClient, + DocumentProcessorServiceClient, +) from .types.document import Document -from .types.document_io import BatchDocumentsInputConfig -from .types.document_io import DocumentOutputConfig -from .types.document_io import GcsDocument -from .types.document_io import GcsDocuments -from .types.document_io import GcsPrefix -from .types.document_io import RawDocument -from .types.document_processor_service import BatchProcessMetadata -from .types.document_processor_service import BatchProcessRequest -from .types.document_processor_service import BatchProcessResponse -from .types.document_processor_service import HumanReviewStatus -from .types.document_processor_service import ProcessRequest -from .types.document_processor_service import ProcessResponse -from .types.document_processor_service import ReviewDocumentOperationMetadata -from .types.document_processor_service import ReviewDocumentRequest -from .types.document_processor_service import ReviewDocumentResponse -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex +from .types.document_io import ( + BatchDocumentsInputConfig, + DocumentOutputConfig, + GcsDocument, + GcsDocuments, + GcsPrefix, + RawDocument, +) +from .types.document_processor_service import ( + BatchProcessMetadata, + BatchProcessRequest, + BatchProcessResponse, + HumanReviewStatus, + ProcessRequest, + ProcessResponse, + ReviewDocumentOperationMetadata, + ReviewDocumentRequest, + ReviewDocumentResponse, +) +from .types.geometry import BoundingPoly, NormalizedVertex, Vertex from .types.operation_metadata import CommonOperationMetadata __all__ = ( diff --git a/google/cloud/documentai_v1/services/document_processor_service/__init__.py b/google/cloud/documentai_v1/services/document_processor_service/__init__.py index d454baaa..a16bb495 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/__init__.py +++ b/google/cloud/documentai_v1/services/document_processor_service/__init__.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import DocumentProcessorServiceClient from .async_client import DocumentProcessorServiceAsyncClient +from .client import DocumentProcessorServiceClient __all__ = ( "DocumentProcessorServiceClient", diff --git a/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/google/cloud/documentai_v1/services/document_processor_service/async_client.py index d1bf70a6..de3c45ed 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -16,15 +16,15 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,11 +33,12 @@ 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 -from google.cloud.documentai_v1.types import document_processor_service -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + +from google.cloud.documentai_v1.types import document, document_processor_service + from .client import DocumentProcessorServiceClient +from .transports.base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport class DocumentProcessorServiceAsyncClient: @@ -237,9 +238,9 @@ async def process_document( from google.cloud import documentai_v1 - def sample_process_document(): + async def sample_process_document(): # Create a client - client = documentai_v1.DocumentProcessorServiceClient() + client = documentai_v1.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) inline_document = documentai_v1.Document() @@ -251,7 +252,7 @@ def sample_process_document(): ) # Make the request - response = client.process_document(request=request) + response = await client.process_document(request=request) # Handle the response print(response) @@ -321,7 +322,12 @@ def sample_process_document(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -338,14 +344,13 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1 - def sample_batch_process_documents(): + async def sample_batch_process_documents(): # Create a client - client = documentai_v1.DocumentProcessorServiceClient() + client = documentai_v1.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1.BatchProcessRequest( @@ -357,7 +362,7 @@ def sample_batch_process_documents(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -430,7 +435,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -455,14 +465,13 @@ async def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. - .. code-block:: python from google.cloud import documentai_v1 - def sample_review_document(): + async def sample_review_document(): # Create a client - client = documentai_v1.DocumentProcessorServiceClient() + client = documentai_v1.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) inline_document = documentai_v1.Document() @@ -478,7 +487,7 @@ def sample_review_document(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -554,7 +563,12 @@ def sample_review_document(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( diff --git a/google/cloud/documentai_v1/services/document_processor_service/client.py b/google/cloud/documentai_v1/services/document_processor_service/client.py index ed696473..be7729ba 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -16,18 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,9 +36,10 @@ 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 -from google.cloud.documentai_v1.types import document_processor_service -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from google.cloud.documentai_v1.types import document, document_processor_service + +from .transports.base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport from .transports.grpc import DocumentProcessorServiceGrpcTransport from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport @@ -58,7 +59,8 @@ class DocumentProcessorServiceClientMeta(type): _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[DocumentProcessorServiceTransport]: """Returns an appropriate transport class. @@ -169,10 +171,16 @@ def transport(self) -> DocumentProcessorServiceTransport: return self._transport @staticmethod - def human_review_config_path(project: str, location: str, processor: str,) -> str: + def human_review_config_path( + project: str, + location: str, + processor: str, + ) -> str: """Returns a fully-qualified human_review_config string.""" return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) @staticmethod @@ -185,10 +193,16 @@ def parse_human_review_config_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def processor_path(project: str, location: str, processor: str,) -> str: + def processor_path( + project: str, + location: str, + processor: str, + ) -> str: """Returns a fully-qualified processor string.""" return "projects/{project}/locations/{location}/processors/{processor}".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) @staticmethod @@ -201,7 +215,9 @@ def parse_processor_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -214,9 +230,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -225,9 +245,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -236,9 +260,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -247,10 +275,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -513,7 +545,12 @@ def sample_process_document(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -530,7 +567,6 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1 @@ -612,7 +648,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -637,7 +678,6 @@ def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. - .. code-block:: python from google.cloud import documentai_v1 @@ -726,7 +766,12 @@ def sample_review_document(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py b/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py index edfa7d68..e4955876 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py @@ -20,7 +20,6 @@ from .grpc import DocumentProcessorServiceGrpcTransport from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - # Compile a registry of transports. _transport_registry = ( OrderedDict() diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index e6f5168c..96dc7558 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -15,19 +15,18 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries -from google.api_core import operations_v1 +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -82,6 +81,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -172,9 +172,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -213,5 +213,9 @@ def review_document( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DocumentProcessorServiceTransport",) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 2ab86d83..445d30d3 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -13,21 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): @@ -231,8 +229,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -339,5 +336,9 @@ def review_document( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DocumentProcessorServiceGrpcTransport",) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index 759c82fd..6d76af32 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -13,21 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport from .grpc import DocumentProcessorServiceGrpcTransport diff --git a/google/cloud/documentai_v1/types/__init__.py b/google/cloud/documentai_v1/types/__init__.py index 079dd069..f1918d3f 100644 --- a/google/cloud/documentai_v1/types/__init__.py +++ b/google/cloud/documentai_v1/types/__init__.py @@ -33,11 +33,7 @@ ReviewDocumentRequest, ReviewDocumentResponse, ) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) +from .geometry import BoundingPoly, NormalizedVertex, Vertex from .operation_metadata import CommonOperationMetadata __all__ = ( diff --git a/google/cloud/documentai_v1/types/document.py b/google/cloud/documentai_v1/types/document.py index 904f46e2..5aa2a42e 100644 --- a/google/cloud/documentai_v1/types/document.py +++ b/google/cloud/documentai_v1/types/document.py @@ -13,9 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - -from google.cloud.documentai_v1.types import geometry from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from google.type import color_pb2 # type: ignore @@ -23,10 +20,15 @@ from google.type import datetime_pb2 # type: ignore from google.type import money_pb2 # type: ignore from google.type import postal_address_pb2 # type: ignore +import proto # type: ignore +from google.cloud.documentai_v1.types import geometry __protobuf__ = proto.module( - package="google.cloud.documentai.v1", manifest={"Document",}, + package="google.cloud.documentai.v1", + manifest={ + "Document", + }, ) @@ -114,9 +116,18 @@ class ShardInfo(proto.Message): the overall document global text. """ - shard_index = proto.Field(proto.INT64, number=1,) - shard_count = proto.Field(proto.INT64, number=2,) - text_offset = proto.Field(proto.INT64, number=3,) + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) class Style(proto.Message): r"""Annotation for common text style attributes. This adheres to @@ -154,21 +165,46 @@ class FontSize(proto.Message): (in, px, pt, etc.). """ - size = proto.Field(proto.FLOAT, number=1,) - unit = proto.Field(proto.STRING, number=2,) + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, ) - color = proto.Field(proto.MESSAGE, number=2, message=color_pb2.Color,) background_color = proto.Field( - proto.MESSAGE, number=3, message=color_pb2.Color, + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, ) - font_weight = proto.Field(proto.STRING, number=4,) - text_style = proto.Field(proto.STRING, number=5,) - text_decoration = proto.Field(proto.STRING, number=6,) font_size = proto.Field( - proto.MESSAGE, number=7, message="Document.Style.FontSize", + proto.MESSAGE, + number=7, + message="Document.Style.FontSize", ) class Page(proto.Message): @@ -243,9 +279,18 @@ class Dimension(proto.Message): Dimension unit. """ - width = proto.Field(proto.FLOAT, number=1,) - height = proto.Field(proto.FLOAT, number=2,) - unit = proto.Field(proto.STRING, number=3,) + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) class Image(proto.Message): r"""Rendered image contents for this page. @@ -261,10 +306,22 @@ class Image(proto.Message): Height of the image in pixels. """ - content = proto.Field(proto.BYTES, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - width = proto.Field(proto.INT32, number=3,) - height = proto.Field(proto.INT32, number=4,) + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + width = proto.Field( + proto.INT32, + number=3, + ) + height = proto.Field( + proto.INT32, + number=4, + ) class Matrix(proto.Message): r"""Representation for transformation matrix, intended to be @@ -285,10 +342,22 @@ class Matrix(proto.Message): The matrix data. """ - rows = proto.Field(proto.INT32, number=1,) - cols = proto.Field(proto.INT32, number=2,) - type_ = proto.Field(proto.INT32, number=3,) - data = proto.Field(proto.BYTES, number=4,) + rows = proto.Field( + proto.INT32, + number=1, + ) + cols = proto.Field( + proto.INT32, + number=2, + ) + type_ = proto.Field( + proto.INT32, + number=3, + ) + data = proto.Field( + proto.BYTES, + number=4, + ) class Layout(proto.Message): r"""Visual element describing a layout unit on a page. @@ -320,14 +389,23 @@ class Orientation(proto.Enum): PAGE_LEFT = 4 text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + confidence = proto.Field( + proto.FLOAT, + number=2, ) - confidence = proto.Field(proto.FLOAT, number=2,) bounding_poly = proto.Field( - proto.MESSAGE, number=3, message=geometry.BoundingPoly, + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, ) orientation = proto.Field( - proto.ENUM, number=4, enum="Document.Page.Layout.Orientation", + proto.ENUM, + number=4, + enum="Document.Page.Layout.Orientation", ) class Block(proto.Message): @@ -346,13 +424,19 @@ class Block(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Paragraph(proto.Message): @@ -372,13 +456,19 @@ class Paragraph(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Line(proto.Message): @@ -398,13 +488,19 @@ class Line(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Token(proto.Message): @@ -441,20 +537,30 @@ class Type(proto.Enum): HYPHEN = 3 type_ = proto.Field( - proto.ENUM, number=1, enum="Document.Page.Token.DetectedBreak.Type", + proto.ENUM, + number=1, + enum="Document.Page.Token.DetectedBreak.Type", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_break = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Token.DetectedBreak", + proto.MESSAGE, + number=2, + message="Document.Page.Token.DetectedBreak", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=4, message="Document.Provenance", + proto.MESSAGE, + number=4, + message="Document.Provenance", ) class Symbol(proto.Message): @@ -471,10 +577,14 @@ class Symbol(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) class VisualElement(proto.Message): @@ -495,11 +605,18 @@ class VisualElement(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + type_ = proto.Field( + proto.STRING, + number=2, ) - type_ = proto.Field(proto.STRING, number=2,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) class Table(proto.Message): @@ -527,7 +644,9 @@ class TableRow(proto.Message): """ cells = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.Page.Table.TableCell", + proto.MESSAGE, + number=1, + message="Document.Page.Table.TableCell", ) class TableCell(proto.Message): @@ -548,25 +667,43 @@ class TableCell(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, ) - row_span = proto.Field(proto.INT32, number=2,) - col_span = proto.Field(proto.INT32, number=3,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) header_rows = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=2, + message="Document.Page.Table.TableRow", ) body_rows = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=3, + message="Document.Page.Table.TableRow", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) class FormField(proto.Message): @@ -602,20 +739,33 @@ class FormField(proto.Message): """ field_name = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) field_value = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Layout", + proto.MESSAGE, + number=2, + message="Document.Page.Layout", ) name_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) value_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", + ) + value_type = proto.Field( + proto.STRING, + number=5, ) - value_type = proto.Field(proto.STRING, number=5,) provenance = proto.Field( - proto.MESSAGE, number=8, message="Document.Provenance", + proto.MESSAGE, + number=8, + message="Document.Provenance", ) class DetectedLanguage(proto.Message): @@ -630,47 +780,88 @@ class DetectedLanguage(proto.Message): Confidence of detected language. Range [0, 1]. """ - language_code = proto.Field(proto.STRING, number=1,) - confidence = proto.Field(proto.FLOAT, number=2,) + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) - page_number = proto.Field(proto.INT32, number=1,) - image = proto.Field(proto.MESSAGE, number=13, message="Document.Page.Image",) + page_number = proto.Field( + proto.INT32, + number=1, + ) + image = proto.Field( + proto.MESSAGE, + number=13, + message="Document.Page.Image", + ) transforms = proto.RepeatedField( - proto.MESSAGE, number=14, message="Document.Page.Matrix", + proto.MESSAGE, + number=14, + message="Document.Page.Matrix", ) dimension = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Dimension", + proto.MESSAGE, + number=2, + message="Document.Page.Dimension", + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message="Document.Page.Layout", ) - layout = proto.Field(proto.MESSAGE, number=3, message="Document.Page.Layout",) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) blocks = proto.RepeatedField( - proto.MESSAGE, number=5, message="Document.Page.Block", + proto.MESSAGE, + number=5, + message="Document.Page.Block", ) paragraphs = proto.RepeatedField( - proto.MESSAGE, number=6, message="Document.Page.Paragraph", + proto.MESSAGE, + number=6, + message="Document.Page.Paragraph", ) lines = proto.RepeatedField( - proto.MESSAGE, number=7, message="Document.Page.Line", + proto.MESSAGE, + number=7, + message="Document.Page.Line", ) tokens = proto.RepeatedField( - proto.MESSAGE, number=8, message="Document.Page.Token", + proto.MESSAGE, + number=8, + message="Document.Page.Token", ) visual_elements = proto.RepeatedField( - proto.MESSAGE, number=9, message="Document.Page.VisualElement", + proto.MESSAGE, + number=9, + message="Document.Page.VisualElement", ) tables = proto.RepeatedField( - proto.MESSAGE, number=10, message="Document.Page.Table", + proto.MESSAGE, + number=10, + message="Document.Page.Table", ) form_fields = proto.RepeatedField( - proto.MESSAGE, number=11, message="Document.Page.FormField", + proto.MESSAGE, + number=11, + message="Document.Page.FormField", ) symbols = proto.RepeatedField( - proto.MESSAGE, number=12, message="Document.Page.Symbol", + proto.MESSAGE, + number=12, + message="Document.Page.Symbol", ) provenance = proto.Field( - proto.MESSAGE, number=16, message="Document.Provenance", + proto.MESSAGE, + number=16, + message="Document.Provenance", ) class Entity(proto.Message): @@ -684,7 +875,7 @@ class Entity(proto.Message): into the [Document.text][google.cloud.documentai.v1.Document.text]. type_ (str): - Entity type from a schema e.g. ``Address``. + Required. Entity type from a schema e.g. ``Address``. mention_text (str): Optional. Text value in the document e.g. ``1600 Amphitheatre Pkwy``. If the entity is not present in @@ -798,30 +989,65 @@ class NormalizedValue(proto.Message): oneof="structured_value", message=postal_address_pb2.PostalAddress, ) - boolean_value = proto.Field(proto.BOOL, number=6, oneof="structured_value",) - text = proto.Field(proto.STRING, number=1,) + boolean_value = proto.Field( + proto.BOOL, + number=6, + oneof="structured_value", + ) + text = proto.Field( + proto.STRING, + number=1, + ) text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, ) - type_ = proto.Field(proto.STRING, number=2,) - mention_text = proto.Field(proto.STRING, number=3,) - mention_id = proto.Field(proto.STRING, number=4,) - confidence = proto.Field(proto.FLOAT, number=5,) page_anchor = proto.Field( - proto.MESSAGE, number=6, message="Document.PageAnchor", + proto.MESSAGE, + number=6, + message="Document.PageAnchor", + ) + id = proto.Field( + proto.STRING, + number=7, ) - id = proto.Field(proto.STRING, number=7,) normalized_value = proto.Field( - proto.MESSAGE, number=9, message="Document.Entity.NormalizedValue", + proto.MESSAGE, + number=9, + message="Document.Entity.NormalizedValue", ) properties = proto.RepeatedField( - proto.MESSAGE, number=10, message="Document.Entity", + proto.MESSAGE, + number=10, + message="Document.Entity", ) provenance = proto.Field( - proto.MESSAGE, number=11, message="Document.Provenance", + proto.MESSAGE, + number=11, + message="Document.Provenance", + ) + redacted = proto.Field( + proto.BOOL, + number=12, ) - redacted = proto.Field(proto.BOOL, number=12,) class EntityRelation(proto.Message): r"""Relationship between @@ -836,9 +1062,18 @@ class EntityRelation(proto.Message): Relationship description. """ - subject_id = proto.Field(proto.STRING, number=1,) - object_id = proto.Field(proto.STRING, number=2,) - relation = proto.Field(proto.STRING, number=3,) + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) class TextAnchor(proto.Message): r"""Text reference indexing into the @@ -872,13 +1107,24 @@ class TextSegment(proto.Message): [Document.text][google.cloud.documentai.v1.Document.text]. """ - start_index = proto.Field(proto.INT64, number=1,) - end_index = proto.Field(proto.INT64, number=2,) + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) text_segments = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.TextAnchor.TextSegment", + proto.MESSAGE, + number=1, + message="Document.TextAnchor.TextSegment", + ) + content = proto.Field( + proto.STRING, + number=2, ) - content = proto.Field(proto.STRING, number=2,) class PageAnchor(proto.Message): r"""Referencing the visual context of the entity in the @@ -930,18 +1176,33 @@ class LayoutType(proto.Enum): TABLE = 6 FORM_FIELD = 7 - page = proto.Field(proto.INT64, number=1,) + page = proto.Field( + proto.INT64, + number=1, + ) layout_type = proto.Field( - proto.ENUM, number=2, enum="Document.PageAnchor.PageRef.LayoutType", + proto.ENUM, + number=2, + enum="Document.PageAnchor.PageRef.LayoutType", + ) + layout_id = proto.Field( + proto.STRING, + number=3, ) - layout_id = proto.Field(proto.STRING, number=3,) bounding_poly = proto.Field( - proto.MESSAGE, number=4, message=geometry.BoundingPoly, + proto.MESSAGE, + number=4, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, ) - confidence = proto.Field(proto.FLOAT, number=5,) page_refs = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.PageAnchor.PageRef", + proto.MESSAGE, + number=1, + message="Document.PageAnchor.PageRef", ) class Provenance(proto.Message): @@ -991,17 +1252,36 @@ class Parent(proto.Message): The id of the parent provenance. """ - revision = proto.Field(proto.INT32, number=1,) - index = proto.Field(proto.INT32, number=3,) - id = proto.Field(proto.INT32, number=2,) + revision = proto.Field( + proto.INT32, + number=1, + ) + index = proto.Field( + proto.INT32, + number=3, + ) + id = proto.Field( + proto.INT32, + number=2, + ) - revision = proto.Field(proto.INT32, number=1,) - id = proto.Field(proto.INT32, number=2,) + revision = proto.Field( + proto.INT32, + number=1, + ) + id = proto.Field( + proto.INT32, + number=2, + ) parents = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Provenance.Parent", + proto.MESSAGE, + number=3, + message="Document.Provenance.Parent", ) type_ = proto.Field( - proto.ENUM, number=4, enum="Document.Provenance.OperationType", + proto.ENUM, + number=4, + enum="Document.Provenance.OperationType", ) class Revision(proto.Message): @@ -1051,18 +1331,42 @@ class HumanReview(proto.Message): is ``rejected``. """ - state = proto.Field(proto.STRING, number=1,) - state_message = proto.Field(proto.STRING, number=2,) + state = proto.Field( + proto.STRING, + number=1, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) - agent = proto.Field(proto.STRING, number=4, oneof="source",) - processor = proto.Field(proto.STRING, number=5, oneof="source",) - id = proto.Field(proto.STRING, number=1,) - parent = proto.RepeatedField(proto.INT32, number=2,) + agent = proto.Field( + proto.STRING, + number=4, + oneof="source", + ) + processor = proto.Field( + proto.STRING, + number=5, + oneof="source", + ) + id = proto.Field( + proto.STRING, + number=1, + ) + parent = proto.RepeatedField( + proto.INT32, + number=2, + ) create_time = proto.Field( - proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, ) human_review = proto.Field( - proto.MESSAGE, number=6, message="Document.Revision.HumanReview", + proto.MESSAGE, + number=6, + message="Document.Revision.HumanReview", ) class TextChange(proto.Message): @@ -1083,27 +1387,78 @@ class TextChange(proto.Message): """ text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + changed_text = proto.Field( + proto.STRING, + number=2, ) - changed_text = proto.Field(proto.STRING, number=2,) provenance = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) - uri = proto.Field(proto.STRING, number=1, oneof="source",) - content = proto.Field(proto.BYTES, number=2, oneof="source",) - mime_type = proto.Field(proto.STRING, number=3,) - text = proto.Field(proto.STRING, number=4,) - text_styles = proto.RepeatedField(proto.MESSAGE, number=5, message=Style,) - pages = proto.RepeatedField(proto.MESSAGE, number=6, message=Page,) - entities = proto.RepeatedField(proto.MESSAGE, number=7, message=Entity,) + uri = proto.Field( + proto.STRING, + number=1, + oneof="source", + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof="source", + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) entity_relations = proto.RepeatedField( - proto.MESSAGE, number=8, message=EntityRelation, + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + text_changes = proto.RepeatedField( + proto.MESSAGE, + number=14, + message=TextChange, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + revisions = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=Revision, ) - text_changes = proto.RepeatedField(proto.MESSAGE, number=14, message=TextChange,) - shard_info = proto.Field(proto.MESSAGE, number=9, message=ShardInfo,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) - revisions = proto.RepeatedField(proto.MESSAGE, number=13, message=Revision,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1/types/document_io.py b/google/cloud/documentai_v1/types/document_io.py index 2f5d326b..a5d5e69e 100644 --- a/google/cloud/documentai_v1/types/document_io.py +++ b/google/cloud/documentai_v1/types/document_io.py @@ -15,7 +15,6 @@ # import proto # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1", manifest={ @@ -40,8 +39,14 @@ class RawDocument(proto.Message): of the [content]. """ - content = proto.Field(proto.BYTES, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) class GcsDocument(proto.Message): @@ -54,8 +59,14 @@ class GcsDocument(proto.Message): An IANA MIME type (RFC6838) of the content. """ - gcs_uri = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) class GcsDocuments(proto.Message): @@ -66,7 +77,11 @@ class GcsDocuments(proto.Message): The list of documents. """ - documents = proto.RepeatedField(proto.MESSAGE, number=1, message="GcsDocument",) + documents = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="GcsDocument", + ) class GcsPrefix(proto.Message): @@ -78,7 +93,10 @@ class GcsPrefix(proto.Message): The URI prefix. """ - gcs_uri_prefix = proto.Field(proto.STRING, number=1,) + gcs_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) class BatchDocumentsInputConfig(proto.Message): @@ -106,10 +124,16 @@ class BatchDocumentsInputConfig(proto.Message): """ gcs_prefix = proto.Field( - proto.MESSAGE, number=1, oneof="source", message="GcsPrefix", + proto.MESSAGE, + number=1, + oneof="source", + message="GcsPrefix", ) gcs_documents = proto.Field( - proto.MESSAGE, number=2, oneof="source", message="GcsDocuments", + proto.MESSAGE, + number=2, + oneof="source", + message="GcsDocuments", ) @@ -137,10 +161,16 @@ class GcsOutputConfig(proto.Message): output. """ - gcs_uri = proto.Field(proto.STRING, number=1,) + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) gcs_output_config = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=GcsOutputConfig, + proto.MESSAGE, + number=1, + oneof="destination", + message=GcsOutputConfig, ) diff --git a/google/cloud/documentai_v1/types/document_processor_service.py b/google/cloud/documentai_v1/types/document_processor_service.py index c7a71cd9..8ebe0d46 100644 --- a/google/cloud/documentai_v1/types/document_processor_service.py +++ b/google/cloud/documentai_v1/types/document_processor_service.py @@ -13,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - -from google.cloud.documentai_v1.types import document as gcd_document -from google.cloud.documentai_v1.types import document_io -from google.cloud.documentai_v1.types import operation_metadata from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore +import proto # type: ignore +from google.cloud.documentai_v1.types import document as gcd_document +from google.cloud.documentai_v1.types import document_io, operation_metadata __protobuf__ = proto.module( package="google.cloud.documentai.v1", @@ -65,13 +63,25 @@ class ProcessRequest(proto.Message): """ inline_document = proto.Field( - proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document, + proto.MESSAGE, + number=4, + oneof="source", + message=gcd_document.Document, ) raw_document = proto.Field( - proto.MESSAGE, number=5, oneof="source", message=document_io.RawDocument, + proto.MESSAGE, + number=5, + oneof="source", + message=document_io.RawDocument, + ) + name = proto.Field( + proto.STRING, + number=1, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=3, ) - name = proto.Field(proto.STRING, number=1,) - skip_human_review = proto.Field(proto.BOOL, number=3,) class HumanReviewStatus(proto.Message): @@ -100,9 +110,19 @@ class State(proto.Enum): IN_PROGRESS = 3 ERROR = 4 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - human_review_operation = proto.Field(proto.STRING, number=3,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + human_review_operation = proto.Field( + proto.STRING, + number=3, + ) class ProcessResponse(proto.Message): @@ -117,9 +137,15 @@ class ProcessResponse(proto.Message): document. """ - document = proto.Field(proto.MESSAGE, number=1, message=gcd_document.Document,) + document = proto.Field( + proto.MESSAGE, + number=1, + message=gcd_document.Document, + ) human_review_status = proto.Field( - proto.MESSAGE, number=3, message="HumanReviewStatus", + proto.MESSAGE, + number=3, + message="HumanReviewStatus", ) @@ -138,19 +164,28 @@ class BatchProcessRequest(proto.Message): skipped for this request. Default to false. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) input_documents = proto.Field( - proto.MESSAGE, number=5, message=document_io.BatchDocumentsInputConfig, + proto.MESSAGE, + number=5, + message=document_io.BatchDocumentsInputConfig, ) document_output_config = proto.Field( - proto.MESSAGE, number=6, message=document_io.DocumentOutputConfig, + proto.MESSAGE, + number=6, + message=document_io.DocumentOutputConfig, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=4, ) - skip_human_review = proto.Field(proto.BOOL, number=4,) class BatchProcessResponse(proto.Message): - r"""Response message for batch process document method. - """ + r"""Response message for batch process document method.""" class BatchProcessMetadata(proto.Message): @@ -204,19 +239,48 @@ class IndividualProcessStatus(proto.Message): document. """ - input_gcs_source = proto.Field(proto.STRING, number=1,) - status = proto.Field(proto.MESSAGE, number=2, message=status_pb2.Status,) - output_gcs_destination = proto.Field(proto.STRING, number=3,) + input_gcs_source = proto.Field( + proto.STRING, + number=1, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + output_gcs_destination = proto.Field( + proto.STRING, + number=3, + ) human_review_status = proto.Field( - proto.MESSAGE, number=5, message="HumanReviewStatus", + proto.MESSAGE, + number=5, + message="HumanReviewStatus", ) - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) individual_process_statuses = proto.RepeatedField( - proto.MESSAGE, number=5, message=IndividualProcessStatus, + proto.MESSAGE, + number=5, + message=IndividualProcessStatus, ) @@ -247,11 +311,24 @@ class Priority(proto.Enum): URGENT = 1 inline_document = proto.Field( - proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document, + proto.MESSAGE, + number=4, + oneof="source", + message=gcd_document.Document, + ) + human_review_config = proto.Field( + proto.STRING, + number=1, + ) + enable_schema_validation = proto.Field( + proto.BOOL, + number=3, + ) + priority = proto.Field( + proto.ENUM, + number=5, + enum=Priority, ) - human_review_config = proto.Field(proto.STRING, number=1,) - enable_schema_validation = proto.Field(proto.BOOL, number=3,) - priority = proto.Field(proto.ENUM, number=5, enum=Priority,) class ReviewDocumentResponse(proto.Message): @@ -263,7 +340,10 @@ class ReviewDocumentResponse(proto.Message): document. """ - gcs_destination = proto.Field(proto.STRING, number=1,) + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) class ReviewDocumentOperationMetadata(proto.Message): @@ -279,9 +359,14 @@ class ReviewDocumentOperationMetadata(proto.Message): """ common_metadata = proto.Field( - proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + question_id = proto.Field( + proto.STRING, + number=6, ) - question_id = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1/types/geometry.py b/google/cloud/documentai_v1/types/geometry.py index d6b41600..4794fcda 100644 --- a/google/cloud/documentai_v1/types/geometry.py +++ b/google/cloud/documentai_v1/types/geometry.py @@ -15,10 +15,13 @@ # import proto # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1", - manifest={"Vertex", "NormalizedVertex", "BoundingPoly",}, + manifest={ + "Vertex", + "NormalizedVertex", + "BoundingPoly", + }, ) @@ -35,8 +38,14 @@ class Vertex(proto.Message): image). """ - x = proto.Field(proto.INT32, number=1,) - y = proto.Field(proto.INT32, number=2,) + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) class NormalizedVertex(proto.Message): @@ -52,8 +61,14 @@ class NormalizedVertex(proto.Message): image). """ - x = proto.Field(proto.FLOAT, number=1,) - y = proto.Field(proto.FLOAT, number=2,) + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) class BoundingPoly(proto.Message): @@ -66,9 +81,15 @@ class BoundingPoly(proto.Message): The bounding polygon normalized vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Vertex", + ) normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=2, message="NormalizedVertex", + proto.MESSAGE, + number=2, + message="NormalizedVertex", ) diff --git a/google/cloud/documentai_v1/types/operation_metadata.py b/google/cloud/documentai_v1/types/operation_metadata.py index 32db9d66..d207bde3 100644 --- a/google/cloud/documentai_v1/types/operation_metadata.py +++ b/google/cloud/documentai_v1/types/operation_metadata.py @@ -13,13 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - from google.protobuf import timestamp_pb2 # type: ignore - +import proto # type: ignore __protobuf__ = proto.module( - package="google.cloud.documentai.v1", manifest={"CommonOperationMetadata",}, + package="google.cloud.documentai.v1", + manifest={ + "CommonOperationMetadata", + }, ) @@ -47,10 +48,25 @@ class State(proto.Enum): FAILED = 4 CANCELLED = 5 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta2/__init__.py b/google/cloud/documentai_v1beta2/__init__.py index f73206c8..8d12c25c 100644 --- a/google/cloud/documentai_v1beta2/__init__.py +++ b/google/cloud/documentai_v1beta2/__init__.py @@ -14,31 +14,30 @@ # limitations under the License. # -from .services.document_understanding_service import DocumentUnderstandingServiceClient from .services.document_understanding_service import ( DocumentUnderstandingServiceAsyncClient, + DocumentUnderstandingServiceClient, ) - from .types.document import Document -from .types.document_understanding import AutoMlParams -from .types.document_understanding import BatchProcessDocumentsRequest -from .types.document_understanding import BatchProcessDocumentsResponse -from .types.document_understanding import EntityExtractionParams -from .types.document_understanding import FormExtractionParams -from .types.document_understanding import GcsDestination -from .types.document_understanding import GcsSource -from .types.document_understanding import InputConfig -from .types.document_understanding import KeyValuePairHint -from .types.document_understanding import OcrParams -from .types.document_understanding import OperationMetadata -from .types.document_understanding import OutputConfig -from .types.document_understanding import ProcessDocumentRequest -from .types.document_understanding import ProcessDocumentResponse -from .types.document_understanding import TableBoundHint -from .types.document_understanding import TableExtractionParams -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex +from .types.document_understanding import ( + AutoMlParams, + BatchProcessDocumentsRequest, + BatchProcessDocumentsResponse, + EntityExtractionParams, + FormExtractionParams, + GcsDestination, + GcsSource, + InputConfig, + KeyValuePairHint, + OcrParams, + OperationMetadata, + OutputConfig, + ProcessDocumentRequest, + ProcessDocumentResponse, + TableBoundHint, + TableExtractionParams, +) +from .types.geometry import BoundingPoly, NormalizedVertex, Vertex __all__ = ( "DocumentUnderstandingServiceAsyncClient", diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py index 17f69842..223bdbd2 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import DocumentUnderstandingServiceClient from .async_client import DocumentUnderstandingServiceAsyncClient +from .client import DocumentUnderstandingServiceClient __all__ = ( "DocumentUnderstandingServiceClient", diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py index 0f83bafa..9dd7fc49 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py @@ -16,15 +16,15 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,12 +33,13 @@ 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 -from google.cloud.documentai_v1beta2.types import document_understanding from google.rpc import status_pb2 # type: ignore -from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport + +from google.cloud.documentai_v1beta2.types import document, document_understanding + from .client import DocumentUnderstandingServiceClient +from .transports.base import DEFAULT_CLIENT_INFO, DocumentUnderstandingServiceTransport +from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport class DocumentUnderstandingServiceAsyncClient: @@ -227,14 +228,13 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1beta2 - def sample_batch_process_documents(): + async def sample_batch_process_documents(): # Create a client - client = documentai_v1beta2.DocumentUnderstandingServiceClient() + client = documentai_v1beta2.DocumentUnderstandingServiceAsyncClient() # Initialize request argument(s) requests = documentai_v1beta2.ProcessDocumentRequest() @@ -250,7 +250,7 @@ def sample_batch_process_documents(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -323,7 +323,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -350,9 +355,9 @@ async def process_document( from google.cloud import documentai_v1beta2 - def sample_process_document(): + async def sample_process_document(): # Create a client - client = documentai_v1beta2.DocumentUnderstandingServiceClient() + client = documentai_v1beta2.DocumentUnderstandingServiceAsyncClient() # Initialize request argument(s) input_config = documentai_v1beta2.InputConfig() @@ -364,7 +369,7 @@ def sample_process_document(): ) # Make the request - response = client.process_document(request=request) + response = await client.process_document(request=request) # Handle the response print(response) @@ -417,7 +422,12 @@ def sample_process_document(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index ba817046..65902516 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -16,18 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,10 +36,11 @@ 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 -from google.cloud.documentai_v1beta2.types import document_understanding from google.rpc import status_pb2 # type: ignore -from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO + +from google.cloud.documentai_v1beta2.types import document, document_understanding + +from .transports.base import DEFAULT_CLIENT_INFO, DocumentUnderstandingServiceTransport from .transports.grpc import DocumentUnderstandingServiceGrpcTransport from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport @@ -61,7 +62,8 @@ class DocumentUnderstandingServiceClientMeta(type): ] = DocumentUnderstandingServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[DocumentUnderstandingServiceTransport]: """Returns an appropriate transport class. @@ -172,7 +174,9 @@ def transport(self) -> DocumentUnderstandingServiceTransport: return self._transport @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -185,9 +189,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -196,9 +204,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -207,9 +219,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -218,10 +234,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -409,7 +429,6 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1beta2 @@ -495,7 +514,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -580,7 +604,12 @@ def sample_process_document(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py index c4d38059..07aaeb7c 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py @@ -20,7 +20,6 @@ from .grpc import DocumentUnderstandingServiceGrpcTransport from .grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport - # Compile a registry of transports. _transport_registry = ( OrderedDict() diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index d231500e..db46f8b6 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -15,20 +15,18 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries -from google.api_core import operations_v1 +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore +from google.cloud.documentai_v1beta2.types import document, document_understanding try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -83,6 +81,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -158,9 +157,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -187,5 +186,9 @@ def process_document( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DocumentUnderstandingServiceTransport",) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index d58f124c..cee76f48 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -13,22 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO +from google.cloud.documentai_v1beta2.types import document, document_understanding + +from .base import DEFAULT_CLIENT_INFO, DocumentUnderstandingServiceTransport class DocumentUnderstandingServiceGrpcTransport(DocumentUnderstandingServiceTransport): @@ -230,8 +227,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -306,5 +302,9 @@ def process_document( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DocumentUnderstandingServiceGrpcTransport",) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index 82d18beb..0633f38b 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -13,22 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO +from google.cloud.documentai_v1beta2.types import document, document_understanding + +from .base import DEFAULT_CLIENT_INFO, DocumentUnderstandingServiceTransport from .grpc import DocumentUnderstandingServiceGrpcTransport diff --git a/google/cloud/documentai_v1beta2/types/__init__.py b/google/cloud/documentai_v1beta2/types/__init__.py index 31c275ea..27b50c0d 100644 --- a/google/cloud/documentai_v1beta2/types/__init__.py +++ b/google/cloud/documentai_v1beta2/types/__init__.py @@ -32,11 +32,7 @@ TableBoundHint, TableExtractionParams, ) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) +from .geometry import BoundingPoly, NormalizedVertex, Vertex __all__ = ( "Document", diff --git a/google/cloud/documentai_v1beta2/types/document.py b/google/cloud/documentai_v1beta2/types/document.py index 94be9ebb..92e50574 100644 --- a/google/cloud/documentai_v1beta2/types/document.py +++ b/google/cloud/documentai_v1beta2/types/document.py @@ -13,15 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - -from google.cloud.documentai_v1beta2.types import geometry from google.rpc import status_pb2 # type: ignore from google.type import color_pb2 # type: ignore +import proto # type: ignore +from google.cloud.documentai_v1beta2.types import geometry __protobuf__ = proto.module( - package="google.cloud.documentai.v1beta2", manifest={"Document",}, + package="google.cloud.documentai.v1beta2", + manifest={ + "Document", + }, ) @@ -105,9 +107,18 @@ class ShardInfo(proto.Message): in the overall document global text. """ - shard_index = proto.Field(proto.INT64, number=1,) - shard_count = proto.Field(proto.INT64, number=2,) - text_offset = proto.Field(proto.INT64, number=3,) + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) class Label(proto.Message): r"""Label attaches schema information and/or other metadata to segments @@ -139,9 +150,19 @@ class Label(proto.Message): assignment. """ - automl_model = proto.Field(proto.STRING, number=2, oneof="source",) - name = proto.Field(proto.STRING, number=1,) - confidence = proto.Field(proto.FLOAT, number=3,) + automl_model = proto.Field( + proto.STRING, + number=2, + oneof="source", + ) + name = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=3, + ) class Style(proto.Message): r"""Annotation for common text style attributes. This adheres to @@ -179,21 +200,46 @@ class FontSize(proto.Message): (in, px, pt, etc.). """ - size = proto.Field(proto.FLOAT, number=1,) - unit = proto.Field(proto.STRING, number=2,) + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, ) - color = proto.Field(proto.MESSAGE, number=2, message=color_pb2.Color,) background_color = proto.Field( - proto.MESSAGE, number=3, message=color_pb2.Color, + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, ) - font_weight = proto.Field(proto.STRING, number=4,) - text_style = proto.Field(proto.STRING, number=5,) - text_decoration = proto.Field(proto.STRING, number=6,) font_size = proto.Field( - proto.MESSAGE, number=7, message="Document.Style.FontSize", + proto.MESSAGE, + number=7, + message="Document.Style.FontSize", ) class Page(proto.Message): @@ -254,9 +300,18 @@ class Dimension(proto.Message): Dimension unit. """ - width = proto.Field(proto.FLOAT, number=1,) - height = proto.Field(proto.FLOAT, number=2,) - unit = proto.Field(proto.STRING, number=3,) + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) class Layout(proto.Message): r"""Visual element describing a layout unit on a page. @@ -291,16 +346,28 @@ class Orientation(proto.Enum): PAGE_LEFT = 4 text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + confidence = proto.Field( + proto.FLOAT, + number=2, ) - confidence = proto.Field(proto.FLOAT, number=2,) bounding_poly = proto.Field( - proto.MESSAGE, number=3, message=geometry.BoundingPoly, + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, ) orientation = proto.Field( - proto.ENUM, number=4, enum="Document.Page.Layout.Orientation", + proto.ENUM, + number=4, + enum="Document.Page.Layout.Orientation", + ) + id = proto.Field( + proto.STRING, + number=5, ) - id = proto.Field(proto.STRING, number=5,) class Block(proto.Message): r"""A block has a set of lines (collected into paragraphs) that @@ -317,10 +384,14 @@ class Block(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) class Paragraph(proto.Message): @@ -338,10 +409,14 @@ class Paragraph(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) class Line(proto.Message): @@ -360,10 +435,14 @@ class Line(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) class Token(proto.Message): @@ -399,17 +478,25 @@ class Type(proto.Enum): HYPHEN = 3 type_ = proto.Field( - proto.ENUM, number=1, enum="Document.Page.Token.DetectedBreak.Type", + proto.ENUM, + number=1, + enum="Document.Page.Token.DetectedBreak.Type", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_break = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Token.DetectedBreak", + proto.MESSAGE, + number=2, + message="Document.Page.Token.DetectedBreak", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) class VisualElement(proto.Message): @@ -430,11 +517,18 @@ class VisualElement(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + type_ = proto.Field( + proto.STRING, + number=2, ) - type_ = proto.Field(proto.STRING, number=2,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) class Table(proto.Message): @@ -463,7 +557,9 @@ class TableRow(proto.Message): """ cells = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.Page.Table.TableCell", + proto.MESSAGE, + number=1, + message="Document.Page.Table.TableCell", ) class TableCell(proto.Message): @@ -484,25 +580,43 @@ class TableCell(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, ) - row_span = proto.Field(proto.INT32, number=2,) - col_span = proto.Field(proto.INT32, number=3,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) header_rows = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=2, + message="Document.Page.Table.TableRow", ) body_rows = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=3, + message="Document.Page.Table.TableRow", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) class FormField(proto.Message): @@ -542,20 +656,37 @@ class FormField(proto.Message): """ field_name = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) field_value = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Layout", + proto.MESSAGE, + number=2, + message="Document.Page.Layout", ) name_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) value_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", + ) + value_type = proto.Field( + proto.STRING, + number=5, + ) + corrected_key_text = proto.Field( + proto.STRING, + number=6, + ) + corrected_value_text = proto.Field( + proto.STRING, + number=7, ) - value_type = proto.Field(proto.STRING, number=5,) - corrected_key_text = proto.Field(proto.STRING, number=6,) - corrected_value_text = proto.Field(proto.STRING, number=7,) class DetectedLanguage(proto.Message): r"""Detected language for a structural component. @@ -569,37 +700,68 @@ class DetectedLanguage(proto.Message): Confidence of detected language. Range [0, 1]. """ - language_code = proto.Field(proto.STRING, number=1,) - confidence = proto.Field(proto.FLOAT, number=2,) + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) - page_number = proto.Field(proto.INT32, number=1,) + page_number = proto.Field( + proto.INT32, + number=1, + ) dimension = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Dimension", + proto.MESSAGE, + number=2, + message="Document.Page.Dimension", + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message="Document.Page.Layout", ) - layout = proto.Field(proto.MESSAGE, number=3, message="Document.Page.Layout",) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) blocks = proto.RepeatedField( - proto.MESSAGE, number=5, message="Document.Page.Block", + proto.MESSAGE, + number=5, + message="Document.Page.Block", ) paragraphs = proto.RepeatedField( - proto.MESSAGE, number=6, message="Document.Page.Paragraph", + proto.MESSAGE, + number=6, + message="Document.Page.Paragraph", ) lines = proto.RepeatedField( - proto.MESSAGE, number=7, message="Document.Page.Line", + proto.MESSAGE, + number=7, + message="Document.Page.Line", ) tokens = proto.RepeatedField( - proto.MESSAGE, number=8, message="Document.Page.Token", + proto.MESSAGE, + number=8, + message="Document.Page.Token", ) visual_elements = proto.RepeatedField( - proto.MESSAGE, number=9, message="Document.Page.VisualElement", + proto.MESSAGE, + number=9, + message="Document.Page.VisualElement", ) tables = proto.RepeatedField( - proto.MESSAGE, number=10, message="Document.Page.Table", + proto.MESSAGE, + number=10, + message="Document.Page.Table", ) form_fields = proto.RepeatedField( - proto.MESSAGE, number=11, message="Document.Page.FormField", + proto.MESSAGE, + number=11, + message="Document.Page.FormField", ) class Entity(proto.Message): @@ -611,7 +773,7 @@ class Entity(proto.Message): Provenance of the entity. Text anchor indexing into the [Document.text][google.cloud.documentai.v1beta2.Document.text]. type_ (str): - Entity type from a schema e.g. ``Address``. + Required. Entity type from a schema e.g. ``Address``. mention_text (str): Text value in the document e.g. ``1600 Amphitheatre Pkwy``. mention_id (str): @@ -626,26 +788,37 @@ class Entity(proto.Message): id (str): Optional. Canonical id. This will be a unique value in the entity list for this document. - bounding_poly_for_demo_frontend (google.cloud.documentai_v1beta2.types.BoundingPoly): - Optional. Temporary field to store the - bounding poly for short-term POCs. Used by the - frontend only. Do not use before you talk to - ybo@ and lukasr@. """ text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, ) - type_ = proto.Field(proto.STRING, number=2,) - mention_text = proto.Field(proto.STRING, number=3,) - mention_id = proto.Field(proto.STRING, number=4,) - confidence = proto.Field(proto.FLOAT, number=5,) page_anchor = proto.Field( - proto.MESSAGE, number=6, message="Document.PageAnchor", + proto.MESSAGE, + number=6, + message="Document.PageAnchor", ) - id = proto.Field(proto.STRING, number=7,) - bounding_poly_for_demo_frontend = proto.Field( - proto.MESSAGE, number=8, message=geometry.BoundingPoly, + id = proto.Field( + proto.STRING, + number=7, ) class EntityRelation(proto.Message): @@ -661,9 +834,18 @@ class EntityRelation(proto.Message): Relationship description. """ - subject_id = proto.Field(proto.STRING, number=1,) - object_id = proto.Field(proto.STRING, number=2,) - relation = proto.Field(proto.STRING, number=3,) + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) class TextAnchor(proto.Message): r"""Text reference indexing into the @@ -696,13 +878,24 @@ class TextSegment(proto.Message): [Document.text][google.cloud.documentai.v1beta2.Document.text]. """ - start_index = proto.Field(proto.INT64, number=1,) - end_index = proto.Field(proto.INT64, number=2,) + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) text_segments = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.TextAnchor.TextSegment", + proto.MESSAGE, + number=1, + message="Document.TextAnchor.TextSegment", + ) + content = proto.Field( + proto.STRING, + number=2, ) - content = proto.Field(proto.STRING, number=2,) class PageAnchor(proto.Message): r"""Referencing elements in @@ -746,29 +939,79 @@ class LayoutType(proto.Enum): TABLE = 6 FORM_FIELD = 7 - page = proto.Field(proto.INT64, number=1,) + page = proto.Field( + proto.INT64, + number=1, + ) layout_type = proto.Field( - proto.ENUM, number=2, enum="Document.PageAnchor.PageRef.LayoutType", + proto.ENUM, + number=2, + enum="Document.PageAnchor.PageRef.LayoutType", + ) + layout_id = proto.Field( + proto.STRING, + number=3, ) - layout_id = proto.Field(proto.STRING, number=3,) page_refs = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.PageAnchor.PageRef", + proto.MESSAGE, + number=1, + message="Document.PageAnchor.PageRef", ) - uri = proto.Field(proto.STRING, number=1, oneof="source",) - content = proto.Field(proto.BYTES, number=2, oneof="source",) - mime_type = proto.Field(proto.STRING, number=3,) - text = proto.Field(proto.STRING, number=4,) - text_styles = proto.RepeatedField(proto.MESSAGE, number=5, message=Style,) - pages = proto.RepeatedField(proto.MESSAGE, number=6, message=Page,) - entities = proto.RepeatedField(proto.MESSAGE, number=7, message=Entity,) + uri = proto.Field( + proto.STRING, + number=1, + oneof="source", + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof="source", + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) entity_relations = proto.RepeatedField( - proto.MESSAGE, number=8, message=EntityRelation, + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + labels = proto.RepeatedField( + proto.MESSAGE, + number=11, + message=Label, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, ) - shard_info = proto.Field(proto.MESSAGE, number=9, message=ShardInfo,) - labels = proto.RepeatedField(proto.MESSAGE, number=11, message=Label,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta2/types/document_understanding.py b/google/cloud/documentai_v1beta2/types/document_understanding.py index d0df2906..ddf0e80e 100644 --- a/google/cloud/documentai_v1beta2/types/document_understanding.py +++ b/google/cloud/documentai_v1beta2/types/document_understanding.py @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore from google.cloud.documentai_v1beta2.types import geometry -from google.protobuf import timestamp_pb2 # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1beta2", @@ -60,9 +59,14 @@ class BatchProcessDocumentsRequest(proto.Message): """ requests = proto.RepeatedField( - proto.MESSAGE, number=1, message="ProcessDocumentRequest", + proto.MESSAGE, + number=1, + message="ProcessDocumentRequest", + ) + parent = proto.Field( + proto.STRING, + number=2, ) - parent = proto.Field(proto.STRING, number=2,) class ProcessDocumentRequest(proto.Message): @@ -110,21 +114,49 @@ class ProcessDocumentRequest(proto.Message): Params. """ - parent = proto.Field(proto.STRING, number=9,) - input_config = proto.Field(proto.MESSAGE, number=1, message="InputConfig",) - output_config = proto.Field(proto.MESSAGE, number=2, message="OutputConfig",) - document_type = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=9, + ) + input_config = proto.Field( + proto.MESSAGE, + number=1, + message="InputConfig", + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message="OutputConfig", + ) + document_type = proto.Field( + proto.STRING, + number=3, + ) table_extraction_params = proto.Field( - proto.MESSAGE, number=4, message="TableExtractionParams", + proto.MESSAGE, + number=4, + message="TableExtractionParams", ) form_extraction_params = proto.Field( - proto.MESSAGE, number=5, message="FormExtractionParams", + proto.MESSAGE, + number=5, + message="FormExtractionParams", ) entity_extraction_params = proto.Field( - proto.MESSAGE, number=6, message="EntityExtractionParams", + proto.MESSAGE, + number=6, + message="EntityExtractionParams", + ) + ocr_params = proto.Field( + proto.MESSAGE, + number=7, + message="OcrParams", + ) + automl_params = proto.Field( + proto.MESSAGE, + number=8, + message="AutoMlParams", ) - ocr_params = proto.Field(proto.MESSAGE, number=7, message="OcrParams",) - automl_params = proto.Field(proto.MESSAGE, number=8, message="AutoMlParams",) class BatchProcessDocumentsResponse(proto.Message): @@ -137,7 +169,9 @@ class BatchProcessDocumentsResponse(proto.Message): """ responses = proto.RepeatedField( - proto.MESSAGE, number=1, message="ProcessDocumentResponse", + proto.MESSAGE, + number=1, + message="ProcessDocumentResponse", ) @@ -155,8 +189,16 @@ class ProcessDocumentResponse(proto.Message): objects. """ - input_config = proto.Field(proto.MESSAGE, number=1, message="InputConfig",) - output_config = proto.Field(proto.MESSAGE, number=2, message="OutputConfig",) + input_config = proto.Field( + proto.MESSAGE, + number=1, + message="InputConfig", + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message="OutputConfig", + ) class OcrParams(proto.Message): @@ -176,7 +218,10 @@ class OcrParams(proto.Message): specified languages is not one of the supported languages. """ - language_hints = proto.RepeatedField(proto.STRING, number=1,) + language_hints = proto.RepeatedField( + proto.STRING, + number=1, + ) class TableExtractionParams(proto.Message): @@ -199,12 +244,23 @@ class TableExtractionParams(proto.Message): "builtin/latest" for the latest model. """ - enabled = proto.Field(proto.BOOL, number=1,) + enabled = proto.Field( + proto.BOOL, + number=1, + ) table_bound_hints = proto.RepeatedField( - proto.MESSAGE, number=2, message="TableBoundHint", + proto.MESSAGE, + number=2, + message="TableBoundHint", + ) + header_hints = proto.RepeatedField( + proto.STRING, + number=3, + ) + model_version = proto.Field( + proto.STRING, + number=4, ) - header_hints = proto.RepeatedField(proto.STRING, number=3,) - model_version = proto.Field(proto.STRING, number=4,) class TableBoundHint(proto.Message): @@ -223,8 +279,15 @@ class TableBoundHint(proto.Message): axis-aligned rectangle. """ - page_number = proto.Field(proto.INT32, number=1,) - bounding_box = proto.Field(proto.MESSAGE, number=2, message=geometry.BoundingPoly,) + page_number = proto.Field( + proto.INT32, + number=1, + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) class FormExtractionParams(proto.Message): @@ -257,11 +320,19 @@ class FormExtractionParams(proto.Message): are stored. """ - enabled = proto.Field(proto.BOOL, number=1,) + enabled = proto.Field( + proto.BOOL, + number=1, + ) key_value_pair_hints = proto.RepeatedField( - proto.MESSAGE, number=2, message="KeyValuePairHint", + proto.MESSAGE, + number=2, + message="KeyValuePairHint", + ) + model_version = proto.Field( + proto.STRING, + number=3, ) - model_version = proto.Field(proto.STRING, number=3,) class KeyValuePairHint(proto.Message): @@ -277,8 +348,14 @@ class KeyValuePairHint(proto.Message): Types not in this list will be ignored. """ - key = proto.Field(proto.STRING, number=1,) - value_types = proto.RepeatedField(proto.STRING, number=2,) + key = proto.Field( + proto.STRING, + number=1, + ) + value_types = proto.RepeatedField( + proto.STRING, + number=2, + ) class EntityExtractionParams(proto.Message): @@ -293,8 +370,14 @@ class EntityExtractionParams(proto.Message): "builtin/latest" for the latest model. """ - enabled = proto.Field(proto.BOOL, number=1,) - model_version = proto.Field(proto.STRING, number=2,) + enabled = proto.Field( + proto.BOOL, + number=1, + ) + model_version = proto.Field( + proto.STRING, + number=2, + ) class AutoMlParams(proto.Message): @@ -308,7 +391,10 @@ class AutoMlParams(proto.Message): ``projects/{project-id}/locations/{location-id}/models/{model-id}``. """ - model = proto.Field(proto.STRING, number=1,) + model = proto.Field( + proto.STRING, + number=1, + ) class InputConfig(proto.Message): @@ -347,10 +433,20 @@ class InputConfig(proto.Message): """ gcs_source = proto.Field( - proto.MESSAGE, number=1, oneof="source", message="GcsSource", + proto.MESSAGE, + number=1, + oneof="source", + message="GcsSource", + ) + contents = proto.Field( + proto.BYTES, + number=3, + oneof="source", + ) + mime_type = proto.Field( + proto.STRING, + number=2, ) - contents = proto.Field(proto.BYTES, number=3, oneof="source",) - mime_type = proto.Field(proto.STRING, number=2,) class OutputConfig(proto.Message): @@ -385,9 +481,15 @@ class OutputConfig(proto.Message): """ gcs_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", + proto.MESSAGE, + number=1, + oneof="destination", + message="GcsDestination", + ) + pages_per_shard = proto.Field( + proto.INT32, + number=2, ) - pages_per_shard = proto.Field(proto.INT32, number=2,) class GcsSource(proto.Message): @@ -399,7 +501,10 @@ class GcsSource(proto.Message): """ - uri = proto.Field(proto.STRING, number=1,) + uri = proto.Field( + proto.STRING, + number=1, + ) class GcsDestination(proto.Message): @@ -411,7 +516,10 @@ class GcsDestination(proto.Message): """ - uri = proto.Field(proto.STRING, number=1,) + uri = proto.Field( + proto.STRING, + number=1, + ) class OperationMetadata(proto.Message): @@ -439,10 +547,25 @@ class State(proto.Enum): CANCELLED = 5 FAILED = 6 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta2/types/geometry.py b/google/cloud/documentai_v1beta2/types/geometry.py index cb593df2..b5e2b887 100644 --- a/google/cloud/documentai_v1beta2/types/geometry.py +++ b/google/cloud/documentai_v1beta2/types/geometry.py @@ -15,10 +15,13 @@ # import proto # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1beta2", - manifest={"Vertex", "NormalizedVertex", "BoundingPoly",}, + manifest={ + "Vertex", + "NormalizedVertex", + "BoundingPoly", + }, ) @@ -34,8 +37,14 @@ class Vertex(proto.Message): Y coordinate. """ - x = proto.Field(proto.INT32, number=1,) - y = proto.Field(proto.INT32, number=2,) + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) class NormalizedVertex(proto.Message): @@ -50,8 +59,14 @@ class NormalizedVertex(proto.Message): Y coordinate. """ - x = proto.Field(proto.FLOAT, number=1,) - y = proto.Field(proto.FLOAT, number=2,) + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) class BoundingPoly(proto.Message): @@ -64,9 +79,15 @@ class BoundingPoly(proto.Message): The bounding polygon normalized vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Vertex", + ) normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=2, message="NormalizedVertex", + proto.MESSAGE, + number=2, + message="NormalizedVertex", ) diff --git a/google/cloud/documentai_v1beta3/__init__.py b/google/cloud/documentai_v1beta3/__init__.py index 06ce2fce..acb85bdc 100644 --- a/google/cloud/documentai_v1beta3/__init__.py +++ b/google/cloud/documentai_v1beta3/__init__.py @@ -14,41 +14,44 @@ # limitations under the License. # -from .services.document_processor_service import DocumentProcessorServiceClient -from .services.document_processor_service import DocumentProcessorServiceAsyncClient - +from .services.document_processor_service import ( + DocumentProcessorServiceAsyncClient, + DocumentProcessorServiceClient, +) from .types.document import Document -from .types.document_io import BatchDocumentsInputConfig -from .types.document_io import DocumentOutputConfig -from .types.document_io import GcsDocument -from .types.document_io import GcsDocuments -from .types.document_io import GcsPrefix -from .types.document_io import RawDocument -from .types.document_processor_service import BatchProcessMetadata -from .types.document_processor_service import BatchProcessRequest -from .types.document_processor_service import BatchProcessResponse -from .types.document_processor_service import CreateProcessorRequest -from .types.document_processor_service import DeleteProcessorMetadata -from .types.document_processor_service import DeleteProcessorRequest -from .types.document_processor_service import DisableProcessorMetadata -from .types.document_processor_service import DisableProcessorRequest -from .types.document_processor_service import DisableProcessorResponse -from .types.document_processor_service import EnableProcessorMetadata -from .types.document_processor_service import EnableProcessorRequest -from .types.document_processor_service import EnableProcessorResponse -from .types.document_processor_service import FetchProcessorTypesRequest -from .types.document_processor_service import FetchProcessorTypesResponse -from .types.document_processor_service import HumanReviewStatus -from .types.document_processor_service import ListProcessorsRequest -from .types.document_processor_service import ListProcessorsResponse -from .types.document_processor_service import ProcessRequest -from .types.document_processor_service import ProcessResponse -from .types.document_processor_service import ReviewDocumentOperationMetadata -from .types.document_processor_service import ReviewDocumentRequest -from .types.document_processor_service import ReviewDocumentResponse -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex +from .types.document_io import ( + BatchDocumentsInputConfig, + DocumentOutputConfig, + GcsDocument, + GcsDocuments, + GcsPrefix, + RawDocument, +) +from .types.document_processor_service import ( + BatchProcessMetadata, + BatchProcessRequest, + BatchProcessResponse, + CreateProcessorRequest, + DeleteProcessorMetadata, + DeleteProcessorRequest, + DisableProcessorMetadata, + DisableProcessorRequest, + DisableProcessorResponse, + EnableProcessorMetadata, + EnableProcessorRequest, + EnableProcessorResponse, + FetchProcessorTypesRequest, + FetchProcessorTypesResponse, + HumanReviewStatus, + ListProcessorsRequest, + ListProcessorsResponse, + ProcessRequest, + ProcessResponse, + ReviewDocumentOperationMetadata, + ReviewDocumentRequest, + ReviewDocumentResponse, +) +from .types.geometry import BoundingPoly, NormalizedVertex, Vertex from .types.operation_metadata import CommonOperationMetadata from .types.processor import Processor from .types.processor_type import ProcessorType diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py b/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py index d454baaa..a16bb495 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import DocumentProcessorServiceClient from .async_client import DocumentProcessorServiceAsyncClient +from .client import DocumentProcessorServiceClient __all__ = ( "DocumentProcessorServiceClient", diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index 64f6f451..2e479598 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py @@ -16,15 +16,15 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,17 +33,18 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.types import document -from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import document, document_processor_service from google.cloud.documentai_v1beta3.types import processor from google.cloud.documentai_v1beta3.types import processor as gcd_processor from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + from .client import DocumentProcessorServiceClient +from .transports.base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport class DocumentProcessorServiceAsyncClient: @@ -249,9 +250,9 @@ async def process_document( from google.cloud import documentai_v1beta3 - def sample_process_document(): + async def sample_process_document(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) inline_document = documentai_v1beta3.Document() @@ -263,7 +264,7 @@ def sample_process_document(): ) # Make the request - response = client.process_document(request=request) + response = await client.process_document(request=request) # Handle the response print(response) @@ -333,7 +334,12 @@ def sample_process_document(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -350,14 +356,13 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1beta3 - def sample_batch_process_documents(): + async def sample_batch_process_documents(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.BatchProcessRequest( @@ -369,7 +374,7 @@ def sample_batch_process_documents(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -442,7 +447,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -472,9 +482,9 @@ async def fetch_processor_types( from google.cloud import documentai_v1beta3 - def sample_fetch_processor_types(): + async def sample_fetch_processor_types(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.FetchProcessorTypesRequest( @@ -482,7 +492,7 @@ def sample_fetch_processor_types(): ) # Make the request - response = client.fetch_processor_types(request=request) + response = await client.fetch_processor_types(request=request) # Handle the response print(response) @@ -543,7 +553,12 @@ def sample_fetch_processor_types(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -563,9 +578,9 @@ async def list_processors( from google.cloud import documentai_v1beta3 - def sample_list_processors(): + async def sample_list_processors(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.ListProcessorsRequest( @@ -576,7 +591,7 @@ def sample_list_processors(): page_result = client.list_processors(request=request) # Handle the response - for response in page_result: + async for response in page_result: print(response) Args: @@ -638,12 +653,20 @@ def sample_list_processors(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListProcessorsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -663,14 +686,13 @@ async def create_processor( user chose. The processor will be at "ENABLED" state by default after its creation. - .. code-block:: python from google.cloud import documentai_v1beta3 - def sample_create_processor(): + async def sample_create_processor(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.CreateProcessorRequest( @@ -678,7 +700,7 @@ def sample_create_processor(): ) # Make the request - response = client.create_processor(request=request) + response = await client.create_processor(request=request) # Handle the response print(response) @@ -754,7 +776,12 @@ def sample_create_processor(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -772,14 +799,13 @@ async def delete_processor( artifacts if it was enabled and then deletes all artifacts associated with this processor. - .. code-block:: python from google.cloud import documentai_v1beta3 - def sample_delete_processor(): + async def sample_delete_processor(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.DeleteProcessorRequest( @@ -791,7 +817,7 @@ def sample_delete_processor(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -864,7 +890,12 @@ def sample_delete_processor(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -891,9 +922,9 @@ async def enable_processor( from google.cloud import documentai_v1beta3 - def sample_enable_processor(): + async def sample_enable_processor(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.EnableProcessorRequest( @@ -905,7 +936,7 @@ def sample_enable_processor(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -947,7 +978,12 @@ def sample_enable_processor(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -974,9 +1010,9 @@ async def disable_processor( from google.cloud import documentai_v1beta3 - def sample_disable_processor(): + async def sample_disable_processor(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) request = documentai_v1beta3.DisableProcessorRequest( @@ -988,7 +1024,7 @@ def sample_disable_processor(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -1030,7 +1066,12 @@ def sample_disable_processor(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1055,14 +1096,13 @@ async def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. - .. code-block:: python from google.cloud import documentai_v1beta3 - def sample_review_document(): + async def sample_review_document(): # Create a client - client = documentai_v1beta3.DocumentProcessorServiceClient() + client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) inline_document = documentai_v1beta3.Document() @@ -1078,7 +1118,7 @@ def sample_review_document(): print("Waiting for operation to complete...") - response = operation.result() + response = await operation.result() # Handle the response print(response) @@ -1154,7 +1194,12 @@ def sample_review_document(): ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index 00c31dd5..6d6fb5da 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -16,18 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,15 +36,16 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.types import document -from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import document, document_processor_service from google.cloud.documentai_v1beta3.types import processor from google.cloud.documentai_v1beta3.types import processor as gcd_processor from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from .transports.base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport from .transports.grpc import DocumentProcessorServiceGrpcTransport from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport @@ -64,7 +65,8 @@ class DocumentProcessorServiceClientMeta(type): _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[DocumentProcessorServiceTransport]: """Returns an appropriate transport class. @@ -175,10 +177,16 @@ def transport(self) -> DocumentProcessorServiceTransport: return self._transport @staticmethod - def human_review_config_path(project: str, location: str, processor: str,) -> str: + def human_review_config_path( + project: str, + location: str, + processor: str, + ) -> str: """Returns a fully-qualified human_review_config string.""" return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) @staticmethod @@ -191,10 +199,16 @@ def parse_human_review_config_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def processor_path(project: str, location: str, processor: str,) -> str: + def processor_path( + project: str, + location: str, + processor: str, + ) -> str: """Returns a fully-qualified processor string.""" return "projects/{project}/locations/{location}/processors/{processor}".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) @staticmethod @@ -207,10 +221,16 @@ def parse_processor_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def processor_type_path(project: str, location: str, processor_type: str,) -> str: + def processor_type_path( + project: str, + location: str, + processor_type: str, + ) -> str: """Returns a fully-qualified processor_type string.""" return "projects/{project}/locations/{location}/processorTypes/{processor_type}".format( - project=project, location=location, processor_type=processor_type, + project=project, + location=location, + processor_type=processor_type, ) @staticmethod @@ -223,7 +243,9 @@ def parse_processor_type_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -236,9 +258,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -247,9 +273,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -258,9 +288,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -269,10 +303,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -535,7 +573,12 @@ def sample_process_document(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -552,7 +595,6 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. - .. code-block:: python from google.cloud import documentai_v1beta3 @@ -634,7 +676,12 @@ def sample_batch_process_documents(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -737,7 +784,12 @@ def sample_fetch_processor_types(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -832,12 +884,20 @@ def sample_list_processors(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. response = pagers.ListProcessorsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -857,7 +917,6 @@ def create_processor( user chose. The processor will be at "ENABLED" state by default after its creation. - .. code-block:: python from google.cloud import documentai_v1beta3 @@ -948,7 +1007,12 @@ def sample_create_processor(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -966,7 +1030,6 @@ def delete_processor( artifacts if it was enabled and then deletes all artifacts associated with this processor. - .. code-block:: python from google.cloud import documentai_v1beta3 @@ -1058,7 +1121,12 @@ def sample_delete_processor(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1142,7 +1210,12 @@ def sample_enable_processor(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1226,7 +1299,12 @@ def sample_disable_processor(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1251,7 +1329,6 @@ def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. - .. code-block:: python from google.cloud import documentai_v1beta3 @@ -1340,7 +1417,12 @@ def sample_review_document(): ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py b/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py index 6f1a2e48..d2a145a4 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py @@ -18,14 +18,13 @@ AsyncIterator, Awaitable, Callable, + Iterator, + Optional, Sequence, Tuple, - Optional, - Iterator, ) -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor +from google.cloud.documentai_v1beta3.types import document_processor_service, processor class ListProcessorsPager: diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py index edfa7d68..e4955876 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py @@ -20,7 +20,6 @@ from .grpc import DocumentProcessorServiceGrpcTransport from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - # Compile a registry of transports. _transport_registry = ( OrderedDict() diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index 5053fe61..43945a98 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -15,20 +15,19 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries -from google.api_core import operations_v1 +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore +import pkg_resources from google.cloud.documentai_v1beta3.types import document_processor_service from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -83,6 +82,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -159,19 +159,29 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.list_processors: gapic_v1.method.wrap_method( - self.list_processors, default_timeout=None, client_info=client_info, + self.list_processors, + default_timeout=None, + client_info=client_info, ), self.create_processor: gapic_v1.method.wrap_method( - self.create_processor, default_timeout=None, client_info=client_info, + self.create_processor, + default_timeout=None, + client_info=client_info, ), self.delete_processor: gapic_v1.method.wrap_method( - self.delete_processor, default_timeout=None, client_info=client_info, + self.delete_processor, + default_timeout=None, + client_info=client_info, ), self.enable_processor: gapic_v1.method.wrap_method( - self.enable_processor, default_timeout=None, client_info=client_info, + self.enable_processor, + default_timeout=None, + client_info=client_info, ), self.disable_processor: gapic_v1.method.wrap_method( - self.disable_processor, default_timeout=None, client_info=client_info, + self.disable_processor, + default_timeout=None, + client_info=client_info, ), self.review_document: gapic_v1.method.wrap_method( self.review_document, @@ -193,9 +203,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -294,5 +304,9 @@ def review_document( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DocumentProcessorServiceTransport",) diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index a4ae4d3f..6b7426a0 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -13,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from google.cloud.documentai_v1beta3.types import document_processor_service from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): @@ -232,8 +230,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -514,5 +511,9 @@ def review_document( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DocumentProcessorServiceGrpcTransport",) diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index 0dc5696e..e9632828 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -13,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.documentai_v1beta3.types import document_processor_service from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport from .grpc import DocumentProcessorServiceGrpcTransport diff --git a/google/cloud/documentai_v1beta3/types/__init__.py b/google/cloud/documentai_v1beta3/types/__init__.py index 522631ea..6a5a9076 100644 --- a/google/cloud/documentai_v1beta3/types/__init__.py +++ b/google/cloud/documentai_v1beta3/types/__init__.py @@ -46,11 +46,7 @@ ReviewDocumentRequest, ReviewDocumentResponse, ) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) +from .geometry import BoundingPoly, NormalizedVertex, Vertex from .operation_metadata import CommonOperationMetadata from .processor import Processor from .processor_type import ProcessorType diff --git a/google/cloud/documentai_v1beta3/types/document.py b/google/cloud/documentai_v1beta3/types/document.py index 27d7d341..f945df4a 100644 --- a/google/cloud/documentai_v1beta3/types/document.py +++ b/google/cloud/documentai_v1beta3/types/document.py @@ -13,9 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - -from google.cloud.documentai_v1beta3.types import geometry from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from google.type import color_pb2 # type: ignore @@ -23,10 +20,15 @@ from google.type import datetime_pb2 # type: ignore from google.type import money_pb2 # type: ignore from google.type import postal_address_pb2 # type: ignore +import proto # type: ignore +from google.cloud.documentai_v1beta3.types import geometry __protobuf__ = proto.module( - package="google.cloud.documentai.v1beta3", manifest={"Document",}, + package="google.cloud.documentai.v1beta3", + manifest={ + "Document", + }, ) @@ -115,9 +117,18 @@ class ShardInfo(proto.Message): in the overall document global text. """ - shard_index = proto.Field(proto.INT64, number=1,) - shard_count = proto.Field(proto.INT64, number=2,) - text_offset = proto.Field(proto.INT64, number=3,) + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) class Style(proto.Message): r"""Annotation for common text style attributes. This adheres to @@ -155,21 +166,46 @@ class FontSize(proto.Message): (in, px, pt, etc.). """ - size = proto.Field(proto.FLOAT, number=1,) - unit = proto.Field(proto.STRING, number=2,) + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, ) - color = proto.Field(proto.MESSAGE, number=2, message=color_pb2.Color,) background_color = proto.Field( - proto.MESSAGE, number=3, message=color_pb2.Color, + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, ) - font_weight = proto.Field(proto.STRING, number=4,) - text_style = proto.Field(proto.STRING, number=5,) - text_decoration = proto.Field(proto.STRING, number=6,) font_size = proto.Field( - proto.MESSAGE, number=7, message="Document.Style.FontSize", + proto.MESSAGE, + number=7, + message="Document.Style.FontSize", ) class Page(proto.Message): @@ -244,9 +280,18 @@ class Dimension(proto.Message): Dimension unit. """ - width = proto.Field(proto.FLOAT, number=1,) - height = proto.Field(proto.FLOAT, number=2,) - unit = proto.Field(proto.STRING, number=3,) + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) class Image(proto.Message): r"""Rendered image contents for this page. @@ -262,10 +307,22 @@ class Image(proto.Message): Height of the image in pixels. """ - content = proto.Field(proto.BYTES, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - width = proto.Field(proto.INT32, number=3,) - height = proto.Field(proto.INT32, number=4,) + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + width = proto.Field( + proto.INT32, + number=3, + ) + height = proto.Field( + proto.INT32, + number=4, + ) class Matrix(proto.Message): r"""Representation for transformation matrix, intended to be @@ -286,10 +343,22 @@ class Matrix(proto.Message): The matrix data. """ - rows = proto.Field(proto.INT32, number=1,) - cols = proto.Field(proto.INT32, number=2,) - type_ = proto.Field(proto.INT32, number=3,) - data = proto.Field(proto.BYTES, number=4,) + rows = proto.Field( + proto.INT32, + number=1, + ) + cols = proto.Field( + proto.INT32, + number=2, + ) + type_ = proto.Field( + proto.INT32, + number=3, + ) + data = proto.Field( + proto.BYTES, + number=4, + ) class Layout(proto.Message): r"""Visual element describing a layout unit on a page. @@ -321,14 +390,23 @@ class Orientation(proto.Enum): PAGE_LEFT = 4 text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + confidence = proto.Field( + proto.FLOAT, + number=2, ) - confidence = proto.Field(proto.FLOAT, number=2,) bounding_poly = proto.Field( - proto.MESSAGE, number=3, message=geometry.BoundingPoly, + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, ) orientation = proto.Field( - proto.ENUM, number=4, enum="Document.Page.Layout.Orientation", + proto.ENUM, + number=4, + enum="Document.Page.Layout.Orientation", ) class Block(proto.Message): @@ -348,13 +426,19 @@ class Block(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Paragraph(proto.Message): @@ -374,13 +458,19 @@ class Paragraph(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Line(proto.Message): @@ -401,13 +491,19 @@ class Line(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) class Token(proto.Message): @@ -445,20 +541,30 @@ class Type(proto.Enum): HYPHEN = 3 type_ = proto.Field( - proto.ENUM, number=1, enum="Document.Page.Token.DetectedBreak.Type", + proto.ENUM, + number=1, + enum="Document.Page.Token.DetectedBreak.Type", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_break = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Token.DetectedBreak", + proto.MESSAGE, + number=2, + message="Document.Page.Token.DetectedBreak", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) provenance = proto.Field( - proto.MESSAGE, number=4, message="Document.Provenance", + proto.MESSAGE, + number=4, + message="Document.Provenance", ) class Symbol(proto.Message): @@ -475,10 +581,14 @@ class Symbol(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=2, + message="Document.Page.DetectedLanguage", ) class VisualElement(proto.Message): @@ -499,11 +609,18 @@ class VisualElement(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + type_ = proto.Field( + proto.STRING, + number=2, ) - type_ = proto.Field(proto.STRING, number=2,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) class Table(proto.Message): @@ -532,7 +649,9 @@ class TableRow(proto.Message): """ cells = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.Page.Table.TableCell", + proto.MESSAGE, + number=1, + message="Document.Page.Table.TableCell", ) class TableCell(proto.Message): @@ -553,25 +672,43 @@ class TableCell(proto.Message): """ layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, ) - row_span = proto.Field(proto.INT32, number=2,) - col_span = proto.Field(proto.INT32, number=3,) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) layout = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) header_rows = proto.RepeatedField( - proto.MESSAGE, number=2, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=2, + message="Document.Page.Table.TableRow", ) body_rows = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.Table.TableRow", + proto.MESSAGE, + number=3, + message="Document.Page.Table.TableRow", ) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) class FormField(proto.Message): @@ -607,20 +744,33 @@ class FormField(proto.Message): """ field_name = proto.Field( - proto.MESSAGE, number=1, message="Document.Page.Layout", + proto.MESSAGE, + number=1, + message="Document.Page.Layout", ) field_value = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Layout", + proto.MESSAGE, + number=2, + message="Document.Page.Layout", ) name_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=3, + message="Document.Page.DetectedLanguage", ) value_detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", + ) + value_type = proto.Field( + proto.STRING, + number=5, ) - value_type = proto.Field(proto.STRING, number=5,) provenance = proto.Field( - proto.MESSAGE, number=8, message="Document.Provenance", + proto.MESSAGE, + number=8, + message="Document.Provenance", ) class DetectedLanguage(proto.Message): @@ -635,47 +785,88 @@ class DetectedLanguage(proto.Message): Confidence of detected language. Range [0, 1]. """ - language_code = proto.Field(proto.STRING, number=1,) - confidence = proto.Field(proto.FLOAT, number=2,) + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) - page_number = proto.Field(proto.INT32, number=1,) - image = proto.Field(proto.MESSAGE, number=13, message="Document.Page.Image",) + page_number = proto.Field( + proto.INT32, + number=1, + ) + image = proto.Field( + proto.MESSAGE, + number=13, + message="Document.Page.Image", + ) transforms = proto.RepeatedField( - proto.MESSAGE, number=14, message="Document.Page.Matrix", + proto.MESSAGE, + number=14, + message="Document.Page.Matrix", ) dimension = proto.Field( - proto.MESSAGE, number=2, message="Document.Page.Dimension", + proto.MESSAGE, + number=2, + message="Document.Page.Dimension", + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message="Document.Page.Layout", ) - layout = proto.Field(proto.MESSAGE, number=3, message="Document.Page.Layout",) detected_languages = proto.RepeatedField( - proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", + proto.MESSAGE, + number=4, + message="Document.Page.DetectedLanguage", ) blocks = proto.RepeatedField( - proto.MESSAGE, number=5, message="Document.Page.Block", + proto.MESSAGE, + number=5, + message="Document.Page.Block", ) paragraphs = proto.RepeatedField( - proto.MESSAGE, number=6, message="Document.Page.Paragraph", + proto.MESSAGE, + number=6, + message="Document.Page.Paragraph", ) lines = proto.RepeatedField( - proto.MESSAGE, number=7, message="Document.Page.Line", + proto.MESSAGE, + number=7, + message="Document.Page.Line", ) tokens = proto.RepeatedField( - proto.MESSAGE, number=8, message="Document.Page.Token", + proto.MESSAGE, + number=8, + message="Document.Page.Token", ) visual_elements = proto.RepeatedField( - proto.MESSAGE, number=9, message="Document.Page.VisualElement", + proto.MESSAGE, + number=9, + message="Document.Page.VisualElement", ) tables = proto.RepeatedField( - proto.MESSAGE, number=10, message="Document.Page.Table", + proto.MESSAGE, + number=10, + message="Document.Page.Table", ) form_fields = proto.RepeatedField( - proto.MESSAGE, number=11, message="Document.Page.FormField", + proto.MESSAGE, + number=11, + message="Document.Page.FormField", ) symbols = proto.RepeatedField( - proto.MESSAGE, number=12, message="Document.Page.Symbol", + proto.MESSAGE, + number=12, + message="Document.Page.Symbol", ) provenance = proto.Field( - proto.MESSAGE, number=16, message="Document.Provenance", + proto.MESSAGE, + number=16, + message="Document.Provenance", ) class Entity(proto.Message): @@ -689,7 +880,7 @@ class Entity(proto.Message): into the [Document.text][google.cloud.documentai.v1beta3.Document.text]. type_ (str): - Entity type from a schema e.g. ``Address``. + Required. Entity type from a schema e.g. ``Address``. mention_text (str): Optional. Text value in the document e.g. ``1600 Amphitheatre Pkwy``. If the entity is not present in @@ -803,30 +994,65 @@ class NormalizedValue(proto.Message): oneof="structured_value", message=postal_address_pb2.PostalAddress, ) - boolean_value = proto.Field(proto.BOOL, number=6, oneof="structured_value",) - text = proto.Field(proto.STRING, number=1,) + boolean_value = proto.Field( + proto.BOOL, + number=6, + oneof="structured_value", + ) + text = proto.Field( + proto.STRING, + number=1, + ) text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, ) - type_ = proto.Field(proto.STRING, number=2,) - mention_text = proto.Field(proto.STRING, number=3,) - mention_id = proto.Field(proto.STRING, number=4,) - confidence = proto.Field(proto.FLOAT, number=5,) page_anchor = proto.Field( - proto.MESSAGE, number=6, message="Document.PageAnchor", + proto.MESSAGE, + number=6, + message="Document.PageAnchor", + ) + id = proto.Field( + proto.STRING, + number=7, ) - id = proto.Field(proto.STRING, number=7,) normalized_value = proto.Field( - proto.MESSAGE, number=9, message="Document.Entity.NormalizedValue", + proto.MESSAGE, + number=9, + message="Document.Entity.NormalizedValue", ) properties = proto.RepeatedField( - proto.MESSAGE, number=10, message="Document.Entity", + proto.MESSAGE, + number=10, + message="Document.Entity", ) provenance = proto.Field( - proto.MESSAGE, number=11, message="Document.Provenance", + proto.MESSAGE, + number=11, + message="Document.Provenance", + ) + redacted = proto.Field( + proto.BOOL, + number=12, ) - redacted = proto.Field(proto.BOOL, number=12,) class EntityRelation(proto.Message): r"""Relationship between @@ -841,9 +1067,18 @@ class EntityRelation(proto.Message): Relationship description. """ - subject_id = proto.Field(proto.STRING, number=1,) - object_id = proto.Field(proto.STRING, number=2,) - relation = proto.Field(proto.STRING, number=3,) + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) class TextAnchor(proto.Message): r"""Text reference indexing into the @@ -877,13 +1112,24 @@ class TextSegment(proto.Message): [Document.text][google.cloud.documentai.v1beta3.Document.text]. """ - start_index = proto.Field(proto.INT64, number=1,) - end_index = proto.Field(proto.INT64, number=2,) + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) text_segments = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.TextAnchor.TextSegment", + proto.MESSAGE, + number=1, + message="Document.TextAnchor.TextSegment", + ) + content = proto.Field( + proto.STRING, + number=2, ) - content = proto.Field(proto.STRING, number=2,) class PageAnchor(proto.Message): r"""Referencing the visual context of the entity in the @@ -935,18 +1181,33 @@ class LayoutType(proto.Enum): TABLE = 6 FORM_FIELD = 7 - page = proto.Field(proto.INT64, number=1,) + page = proto.Field( + proto.INT64, + number=1, + ) layout_type = proto.Field( - proto.ENUM, number=2, enum="Document.PageAnchor.PageRef.LayoutType", + proto.ENUM, + number=2, + enum="Document.PageAnchor.PageRef.LayoutType", + ) + layout_id = proto.Field( + proto.STRING, + number=3, ) - layout_id = proto.Field(proto.STRING, number=3,) bounding_poly = proto.Field( - proto.MESSAGE, number=4, message=geometry.BoundingPoly, + proto.MESSAGE, + number=4, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, ) - confidence = proto.Field(proto.FLOAT, number=5,) page_refs = proto.RepeatedField( - proto.MESSAGE, number=1, message="Document.PageAnchor.PageRef", + proto.MESSAGE, + number=1, + message="Document.PageAnchor.PageRef", ) class Provenance(proto.Message): @@ -996,17 +1257,36 @@ class Parent(proto.Message): The id of the parent provenance. """ - revision = proto.Field(proto.INT32, number=1,) - index = proto.Field(proto.INT32, number=3,) - id = proto.Field(proto.INT32, number=2,) + revision = proto.Field( + proto.INT32, + number=1, + ) + index = proto.Field( + proto.INT32, + number=3, + ) + id = proto.Field( + proto.INT32, + number=2, + ) - revision = proto.Field(proto.INT32, number=1,) - id = proto.Field(proto.INT32, number=2,) + revision = proto.Field( + proto.INT32, + number=1, + ) + id = proto.Field( + proto.INT32, + number=2, + ) parents = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Provenance.Parent", + proto.MESSAGE, + number=3, + message="Document.Provenance.Parent", ) type_ = proto.Field( - proto.ENUM, number=4, enum="Document.Provenance.OperationType", + proto.ENUM, + number=4, + enum="Document.Provenance.OperationType", ) class Revision(proto.Message): @@ -1056,18 +1336,42 @@ class HumanReview(proto.Message): is ``rejected``. """ - state = proto.Field(proto.STRING, number=1,) - state_message = proto.Field(proto.STRING, number=2,) + state = proto.Field( + proto.STRING, + number=1, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) - agent = proto.Field(proto.STRING, number=4, oneof="source",) - processor = proto.Field(proto.STRING, number=5, oneof="source",) - id = proto.Field(proto.STRING, number=1,) - parent = proto.RepeatedField(proto.INT32, number=2,) + agent = proto.Field( + proto.STRING, + number=4, + oneof="source", + ) + processor = proto.Field( + proto.STRING, + number=5, + oneof="source", + ) + id = proto.Field( + proto.STRING, + number=1, + ) + parent = proto.RepeatedField( + proto.INT32, + number=2, + ) create_time = proto.Field( - proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, ) human_review = proto.Field( - proto.MESSAGE, number=6, message="Document.Revision.HumanReview", + proto.MESSAGE, + number=6, + message="Document.Revision.HumanReview", ) class TextChange(proto.Message): @@ -1088,27 +1392,78 @@ class TextChange(proto.Message): """ text_anchor = proto.Field( - proto.MESSAGE, number=1, message="Document.TextAnchor", + proto.MESSAGE, + number=1, + message="Document.TextAnchor", + ) + changed_text = proto.Field( + proto.STRING, + number=2, ) - changed_text = proto.Field(proto.STRING, number=2,) provenance = proto.RepeatedField( - proto.MESSAGE, number=3, message="Document.Provenance", + proto.MESSAGE, + number=3, + message="Document.Provenance", ) - uri = proto.Field(proto.STRING, number=1, oneof="source",) - content = proto.Field(proto.BYTES, number=2, oneof="source",) - mime_type = proto.Field(proto.STRING, number=3,) - text = proto.Field(proto.STRING, number=4,) - text_styles = proto.RepeatedField(proto.MESSAGE, number=5, message=Style,) - pages = proto.RepeatedField(proto.MESSAGE, number=6, message=Page,) - entities = proto.RepeatedField(proto.MESSAGE, number=7, message=Entity,) + uri = proto.Field( + proto.STRING, + number=1, + oneof="source", + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof="source", + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) entity_relations = proto.RepeatedField( - proto.MESSAGE, number=8, message=EntityRelation, + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + text_changes = proto.RepeatedField( + proto.MESSAGE, + number=14, + message=TextChange, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + revisions = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=Revision, ) - text_changes = proto.RepeatedField(proto.MESSAGE, number=14, message=TextChange,) - shard_info = proto.Field(proto.MESSAGE, number=9, message=ShardInfo,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) - revisions = proto.RepeatedField(proto.MESSAGE, number=13, message=Revision,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta3/types/document_io.py b/google/cloud/documentai_v1beta3/types/document_io.py index 3bc1ec68..2fe7f436 100644 --- a/google/cloud/documentai_v1beta3/types/document_io.py +++ b/google/cloud/documentai_v1beta3/types/document_io.py @@ -15,7 +15,6 @@ # import proto # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1beta3", manifest={ @@ -40,8 +39,14 @@ class RawDocument(proto.Message): of the [content]. """ - content = proto.Field(proto.BYTES, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) class GcsDocument(proto.Message): @@ -54,8 +59,14 @@ class GcsDocument(proto.Message): An IANA MIME type (RFC6838) of the content. """ - gcs_uri = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) class GcsDocuments(proto.Message): @@ -66,7 +77,11 @@ class GcsDocuments(proto.Message): The list of documents. """ - documents = proto.RepeatedField(proto.MESSAGE, number=1, message="GcsDocument",) + documents = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="GcsDocument", + ) class GcsPrefix(proto.Message): @@ -78,7 +93,10 @@ class GcsPrefix(proto.Message): The URI prefix. """ - gcs_uri_prefix = proto.Field(proto.STRING, number=1,) + gcs_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) class BatchDocumentsInputConfig(proto.Message): @@ -106,10 +124,16 @@ class BatchDocumentsInputConfig(proto.Message): """ gcs_prefix = proto.Field( - proto.MESSAGE, number=1, oneof="source", message="GcsPrefix", + proto.MESSAGE, + number=1, + oneof="source", + message="GcsPrefix", ) gcs_documents = proto.Field( - proto.MESSAGE, number=2, oneof="source", message="GcsDocuments", + proto.MESSAGE, + number=2, + oneof="source", + message="GcsDocuments", ) @@ -137,10 +161,16 @@ class GcsOutputConfig(proto.Message): output. """ - gcs_uri = proto.Field(proto.STRING, number=1,) + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) gcs_output_config = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=GcsOutputConfig, + proto.MESSAGE, + number=1, + oneof="destination", + message=GcsOutputConfig, ) diff --git a/google/cloud/documentai_v1beta3/types/document_processor_service.py b/google/cloud/documentai_v1beta3/types/document_processor_service.py index 668e718f..98bee9fe 100644 --- a/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ b/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -13,16 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore import proto # type: ignore +from google.cloud.documentai_v1beta3.types import document_io, operation_metadata from google.cloud.documentai_v1beta3.types import document as gcd_document -from google.cloud.documentai_v1beta3.types import document_io -from google.cloud.documentai_v1beta3.types import operation_metadata from google.cloud.documentai_v1beta3.types import processor as gcd_processor from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1beta3", @@ -83,14 +81,30 @@ class ProcessRequest(proto.Message): """ inline_document = proto.Field( - proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document, + proto.MESSAGE, + number=4, + oneof="source", + message=gcd_document.Document, ) raw_document = proto.Field( - proto.MESSAGE, number=5, oneof="source", message=document_io.RawDocument, + proto.MESSAGE, + number=5, + oneof="source", + message=document_io.RawDocument, + ) + name = proto.Field( + proto.STRING, + number=1, + ) + document = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_document.Document, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=3, ) - name = proto.Field(proto.STRING, number=1,) - document = proto.Field(proto.MESSAGE, number=2, message=gcd_document.Document,) - skip_human_review = proto.Field(proto.BOOL, number=3,) class HumanReviewStatus(proto.Message): @@ -119,9 +133,19 @@ class State(proto.Enum): IN_PROGRESS = 3 ERROR = 4 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - human_review_operation = proto.Field(proto.STRING, number=3,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + human_review_operation = proto.Field( + proto.STRING, + number=3, + ) class ProcessResponse(proto.Message): @@ -143,10 +167,19 @@ class ProcessResponse(proto.Message): document. """ - document = proto.Field(proto.MESSAGE, number=1, message=gcd_document.Document,) - human_review_operation = proto.Field(proto.STRING, number=2,) + document = proto.Field( + proto.MESSAGE, + number=1, + message=gcd_document.Document, + ) + human_review_operation = proto.Field( + proto.STRING, + number=2, + ) human_review_status = proto.Field( - proto.MESSAGE, number=3, message="HumanReviewStatus", + proto.MESSAGE, + number=3, + message="HumanReviewStatus", ) @@ -184,8 +217,14 @@ class BatchInputConfig(proto.Message): should be application/json. """ - gcs_source = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + gcs_source = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) class BatchOutputConfig(proto.Message): r"""The message for output config in batch process. @@ -196,25 +235,43 @@ class BatchOutputConfig(proto.Message): processed documents. """ - gcs_destination = proto.Field(proto.STRING, number=1,) + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) input_configs = proto.RepeatedField( - proto.MESSAGE, number=2, message=BatchInputConfig, + proto.MESSAGE, + number=2, + message=BatchInputConfig, + ) + output_config = proto.Field( + proto.MESSAGE, + number=3, + message=BatchOutputConfig, ) - output_config = proto.Field(proto.MESSAGE, number=3, message=BatchOutputConfig,) input_documents = proto.Field( - proto.MESSAGE, number=5, message=document_io.BatchDocumentsInputConfig, + proto.MESSAGE, + number=5, + message=document_io.BatchDocumentsInputConfig, ) document_output_config = proto.Field( - proto.MESSAGE, number=6, message=document_io.DocumentOutputConfig, + proto.MESSAGE, + number=6, + message=document_io.DocumentOutputConfig, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=4, ) - skip_human_review = proto.Field(proto.BOOL, number=4,) class BatchProcessResponse(proto.Message): - r"""Response message for batch process document method. - """ + r"""Response message for batch process document method.""" class BatchProcessMetadata(proto.Message): @@ -275,20 +332,52 @@ class IndividualProcessStatus(proto.Message): document. """ - input_gcs_source = proto.Field(proto.STRING, number=1,) - status = proto.Field(proto.MESSAGE, number=2, message=status_pb2.Status,) - output_gcs_destination = proto.Field(proto.STRING, number=3,) - human_review_operation = proto.Field(proto.STRING, number=4,) + input_gcs_source = proto.Field( + proto.STRING, + number=1, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + output_gcs_destination = proto.Field( + proto.STRING, + number=3, + ) + human_review_operation = proto.Field( + proto.STRING, + number=4, + ) human_review_status = proto.Field( - proto.MESSAGE, number=5, message="HumanReviewStatus", + proto.MESSAGE, + number=5, + message="HumanReviewStatus", ) - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) individual_process_statuses = proto.RepeatedField( - proto.MESSAGE, number=5, message=IndividualProcessStatus, + proto.MESSAGE, + number=5, + message=IndividualProcessStatus, ) @@ -302,7 +391,10 @@ class FetchProcessorTypesRequest(proto.Message): projects/{project}/locations/{location} """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) class FetchProcessorTypesResponse(proto.Message): @@ -314,7 +406,9 @@ class FetchProcessorTypesResponse(proto.Message): """ processor_types = proto.RepeatedField( - proto.MESSAGE, number=1, message=processor_type.ProcessorType, + proto.MESSAGE, + number=1, + message=processor_type.ProcessorType, ) @@ -337,9 +431,18 @@ class ListProcessorsRequest(proto.Message): next processor. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) class ListProcessorsResponse(proto.Message): @@ -358,9 +461,14 @@ def raw_page(self): return self processors = proto.RepeatedField( - proto.MESSAGE, number=1, message=gcd_processor.Processor, + proto.MESSAGE, + number=1, + message=gcd_processor.Processor, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class CreateProcessorRequest(proto.Message): @@ -379,8 +487,15 @@ class CreateProcessorRequest(proto.Message): processor is under CMEK if CMEK fields are set. """ - parent = proto.Field(proto.STRING, number=1,) - processor = proto.Field(proto.MESSAGE, number=2, message=gcd_processor.Processor,) + parent = proto.Field( + proto.STRING, + number=1, + ) + processor = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_processor.Processor, + ) class DeleteProcessorRequest(proto.Message): @@ -392,7 +507,10 @@ class DeleteProcessorRequest(proto.Message): deleted. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DeleteProcessorMetadata(proto.Message): @@ -406,7 +524,9 @@ class DeleteProcessorMetadata(proto.Message): """ common_metadata = proto.Field( - proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, ) @@ -419,12 +539,14 @@ class EnableProcessorRequest(proto.Message): enabled. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class EnableProcessorResponse(proto.Message): - r"""Response message for the enable processor method. - """ + r"""Response message for the enable processor method.""" class EnableProcessorMetadata(proto.Message): @@ -438,7 +560,9 @@ class EnableProcessorMetadata(proto.Message): """ common_metadata = proto.Field( - proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, ) @@ -451,12 +575,14 @@ class DisableProcessorRequest(proto.Message): disabled. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DisableProcessorResponse(proto.Message): - r"""Response message for the disable processor method. - """ + r"""Response message for the disable processor method.""" class DisableProcessorMetadata(proto.Message): @@ -470,7 +596,9 @@ class DisableProcessorMetadata(proto.Message): """ common_metadata = proto.Field( - proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, ) @@ -505,12 +633,29 @@ class Priority(proto.Enum): URGENT = 1 inline_document = proto.Field( - proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document, + proto.MESSAGE, + number=4, + oneof="source", + message=gcd_document.Document, + ) + human_review_config = proto.Field( + proto.STRING, + number=1, + ) + document = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_document.Document, + ) + enable_schema_validation = proto.Field( + proto.BOOL, + number=3, + ) + priority = proto.Field( + proto.ENUM, + number=5, + enum=Priority, ) - human_review_config = proto.Field(proto.STRING, number=1,) - document = proto.Field(proto.MESSAGE, number=2, message=gcd_document.Document,) - enable_schema_validation = proto.Field(proto.BOOL, number=3,) - priority = proto.Field(proto.ENUM, number=5, enum=Priority,) class ReviewDocumentResponse(proto.Message): @@ -522,7 +667,10 @@ class ReviewDocumentResponse(proto.Message): document. """ - gcs_destination = proto.Field(proto.STRING, number=1,) + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) class ReviewDocumentOperationMetadata(proto.Message): @@ -556,14 +704,34 @@ class State(proto.Enum): FAILED = 4 CANCELLED = 5 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) common_metadata = proto.Field( - proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + question_id = proto.Field( + proto.STRING, + number=6, ) - question_id = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta3/types/geometry.py b/google/cloud/documentai_v1beta3/types/geometry.py index e1a103b5..2add8a91 100644 --- a/google/cloud/documentai_v1beta3/types/geometry.py +++ b/google/cloud/documentai_v1beta3/types/geometry.py @@ -15,10 +15,13 @@ # import proto # type: ignore - __protobuf__ = proto.module( package="google.cloud.documentai.v1beta3", - manifest={"Vertex", "NormalizedVertex", "BoundingPoly",}, + manifest={ + "Vertex", + "NormalizedVertex", + "BoundingPoly", + }, ) @@ -35,8 +38,14 @@ class Vertex(proto.Message): image). """ - x = proto.Field(proto.INT32, number=1,) - y = proto.Field(proto.INT32, number=2,) + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) class NormalizedVertex(proto.Message): @@ -52,8 +61,14 @@ class NormalizedVertex(proto.Message): image). """ - x = proto.Field(proto.FLOAT, number=1,) - y = proto.Field(proto.FLOAT, number=2,) + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) class BoundingPoly(proto.Message): @@ -66,9 +81,15 @@ class BoundingPoly(proto.Message): The bounding polygon normalized vertices. """ - vertices = proto.RepeatedField(proto.MESSAGE, number=1, message="Vertex",) + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Vertex", + ) normalized_vertices = proto.RepeatedField( - proto.MESSAGE, number=2, message="NormalizedVertex", + proto.MESSAGE, + number=2, + message="NormalizedVertex", ) diff --git a/google/cloud/documentai_v1beta3/types/operation_metadata.py b/google/cloud/documentai_v1beta3/types/operation_metadata.py index a4e57051..6ea500e2 100644 --- a/google/cloud/documentai_v1beta3/types/operation_metadata.py +++ b/google/cloud/documentai_v1beta3/types/operation_metadata.py @@ -13,13 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - from google.protobuf import timestamp_pb2 # type: ignore - +import proto # type: ignore __protobuf__ = proto.module( - package="google.cloud.documentai.v1beta3", manifest={"CommonOperationMetadata",}, + package="google.cloud.documentai.v1beta3", + manifest={ + "CommonOperationMetadata", + }, ) @@ -47,10 +48,25 @@ class State(proto.Enum): FAILED = 4 CANCELLED = 5 - state = proto.Field(proto.ENUM, number=1, enum=State,) - state_message = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta3/types/processor.py b/google/cloud/documentai_v1beta3/types/processor.py index dc0dc83b..2a098537 100644 --- a/google/cloud/documentai_v1beta3/types/processor.py +++ b/google/cloud/documentai_v1beta3/types/processor.py @@ -13,13 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import proto # type: ignore - from google.protobuf import timestamp_pb2 # type: ignore - +import proto # type: ignore __protobuf__ = proto.module( - package="google.cloud.documentai.v1beta3", manifest={"Processor",}, + package="google.cloud.documentai.v1beta3", + manifest={ + "Processor", + }, ) @@ -62,14 +63,40 @@ class State(proto.Enum): FAILED = 6 DELETING = 7 - name = proto.Field(proto.STRING, number=1,) - type_ = proto.Field(proto.STRING, number=2,) - display_name = proto.Field(proto.STRING, number=3,) - state = proto.Field(proto.ENUM, number=4, enum=State,) - default_processor_version = proto.Field(proto.STRING, number=9,) - process_endpoint = proto.Field(proto.STRING, number=6,) - create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - kms_key_name = proto.Field(proto.STRING, number=8,) + name = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=State, + ) + default_processor_version = proto.Field( + proto.STRING, + number=9, + ) + process_endpoint = proto.Field( + proto.STRING, + number=6, + ) + create_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + kms_key_name = proto.Field( + proto.STRING, + number=8, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta3/types/processor_type.py b/google/cloud/documentai_v1beta3/types/processor_type.py index 5161782c..be0a2b8e 100644 --- a/google/cloud/documentai_v1beta3/types/processor_type.py +++ b/google/cloud/documentai_v1beta3/types/processor_type.py @@ -15,9 +15,11 @@ # import proto # type: ignore - __protobuf__ = proto.module( - package="google.cloud.documentai.v1beta3", manifest={"ProcessorType",}, + package="google.cloud.documentai.v1beta3", + manifest={ + "ProcessorType", + }, ) @@ -51,15 +53,32 @@ class LocationInfo(proto.Message): The location id. """ - location_id = proto.Field(proto.STRING, number=1,) + location_id = proto.Field( + proto.STRING, + number=1, + ) - name = proto.Field(proto.STRING, number=1,) - type_ = proto.Field(proto.STRING, number=2,) - category = proto.Field(proto.STRING, number=3,) + name = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + category = proto.Field( + proto.STRING, + number=3, + ) available_locations = proto.RepeatedField( - proto.MESSAGE, number=4, message=LocationInfo, + proto.MESSAGE, + number=4, + message=LocationInfo, + ) + allow_creation = proto.Field( + proto.BOOL, + number=6, ) - allow_creation = proto.Field(proto.BOOL, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/noxfile.py b/noxfile.py index 2a2001c4..7c1742d2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,19 +17,45 @@ # Generated by synthtool. DO NOT EDIT! from __future__ import absolute_import + import os import pathlib import shutil +import warnings import nox - -BLACK_VERSION = "black==19.10b0" -BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" +LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] + UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_EXTRAS = [] +UNIT_TEST_EXTRAS_BY_PYTHON = {} + +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_EXTRAS = [] +SYSTEM_TEST_EXTRAS_BY_PYTHON = {} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -57,7 +83,9 @@ def lint(session): """ session.install("flake8", BLACK_VERSION) session.run( - "black", "--check", *BLACK_PATHS, + "black", + "--check", + *LINT_PATHS, ) session.run("flake8", "google", "tests") @@ -67,7 +95,28 @@ def blacken(session): """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( - "black", *BLACK_PATHS, + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def format(session): + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run( + "isort", + "--fss", + *LINT_PATHS, + ) + session.run( + "black", + *LINT_PATHS, ) @@ -78,23 +127,41 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + def default(session): # Install all test dependencies, then install this package in-place. constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install( - "mock", - "asyncmock", - "pytest", - "pytest-cov", - "pytest-asyncio", - "-c", - constraints_path, - ) - - session.install("-e", ".", "-c", constraints_path) + install_unittest_dependencies(session, "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -118,6 +185,35 @@ def unit(session): default(session) +def install_systemtest_dependencies(session, *constraints): + + # Use pre-release gRPC for system tests. + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" @@ -140,13 +236,7 @@ def system(session): if not system_test_exists and not system_test_folder_exists: session.skip("System tests were not found") - # Use pre-release gRPC for system tests. - session.install("--pre", "grpcio") - - # Install all test dependencies, then install this package into the - # virtualenv's dist-packages. - session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) - session.install("-e", ".", "-c", constraints_path) + install_systemtest_dependencies(session, "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: diff --git a/samples/generated_samples/snippet_metadata_documentai_v1.json b/samples/generated_samples/snippet_metadata_documentai_v1.json index e32e56f8..5c1b8d92 100644 --- a/samples/generated_samples/snippet_metadata_documentai_v1.json +++ b/samples/generated_samples/snippet_metadata_documentai_v1.json @@ -1,16 +1,61 @@ { + "clientLibrary": { + "apis": [ + { + "id": "google.cloud.documentai.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-documentai" + }, "snippets": [ { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.BatchProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1_generated_document_processor_service_batch_process_documents_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_async", "segments": [ { @@ -43,18 +88,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_batch_process_documents_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.BatchProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1_generated_document_processor_service_batch_process_documents_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_sync", "segments": [ { @@ -87,19 +168,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_batch_process_documents_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.ProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1.types.ProcessResponse", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1_generated_document_processor_service_process_document_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_ProcessDocument_async", "segments": [ { @@ -132,18 +249,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_process_document_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.ProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1.types.ProcessResponse", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1_generated_document_processor_service_process_document_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_ProcessDocument_sync", "segments": [ { @@ -176,19 +329,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_process_document_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceAsyncClient.review_document", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.ReviewDocument", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ReviewDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.ReviewDocumentRequest" + }, + { + "name": "human_review_config", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "review_document" }, + "description": "Sample for ReviewDocument", "file": "documentai_v1_generated_document_processor_service_review_document_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_ReviewDocument_async", "segments": [ { @@ -221,18 +410,54 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_review_document_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1.DocumentProcessorServiceClient.review_document", "method": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService.ReviewDocument", "service": { + "fullName": "google.cloud.documentai.v1.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ReviewDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1.types.ReviewDocumentRequest" + }, + { + "name": "human_review_config", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "review_document" }, + "description": "Sample for ReviewDocument", "file": "documentai_v1_generated_document_processor_service_review_document_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1_generated_DocumentProcessorService_ReviewDocument_sync", "segments": [ { @@ -265,7 +490,8 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1_generated_document_processor_service_review_document_sync.py" } ] } diff --git a/samples/generated_samples/snippet_metadata_documentai_v1beta2.json b/samples/generated_samples/snippet_metadata_documentai_v1beta2.json index 1d18b708..ec455c8b 100644 --- a/samples/generated_samples/snippet_metadata_documentai_v1beta2.json +++ b/samples/generated_samples/snippet_metadata_documentai_v1beta2.json @@ -1,16 +1,61 @@ { + "clientLibrary": { + "apis": [ + { + "id": "google.cloud.documentai.v1beta2", + "version": "v1beta2" + } + ], + "language": "PYTHON", + "name": "google-cloud-documentai" + }, "snippets": [ { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceAsyncClient", + "shortName": "DocumentUnderstandingServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceAsyncClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService", "shortName": "DocumentUnderstandingService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_async", "segments": [ { @@ -43,18 +88,54 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceClient", + "shortName": "DocumentUnderstandingServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService", "shortName": "DocumentUnderstandingService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_sync", "segments": [ { @@ -87,19 +168,51 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceAsyncClient", + "shortName": "DocumentUnderstandingServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceAsyncClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService", "shortName": "DocumentUnderstandingService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta2.types.ProcessDocumentRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta2.types.Document", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1beta2_generated_document_understanding_service_process_document_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_async", "segments": [ { @@ -132,18 +245,50 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta2_generated_document_understanding_service_process_document_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceClient", + "shortName": "DocumentUnderstandingServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta2.DocumentUnderstandingServiceClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1beta2.DocumentUnderstandingService", "shortName": "DocumentUnderstandingService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta2.types.ProcessDocumentRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta2.types.Document", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1beta2_generated_document_understanding_service_process_document_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_sync", "segments": [ { @@ -176,7 +321,8 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta2_generated_document_understanding_service_process_document_sync.py" } ] } diff --git a/samples/generated_samples/snippet_metadata_documentai_v1beta3.json b/samples/generated_samples/snippet_metadata_documentai_v1beta3.json index 53d92b3d..68d8827d 100644 --- a/samples/generated_samples/snippet_metadata_documentai_v1beta3.json +++ b/samples/generated_samples/snippet_metadata_documentai_v1beta3.json @@ -1,16 +1,61 @@ { + "clientLibrary": { + "apis": [ + { + "id": "google.cloud.documentai.v1beta3", + "version": "v1beta3" + } + ], + "language": "PYTHON", + "name": "google-cloud-documentai" + }, "snippets": [ { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.BatchProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_async", "segments": [ { @@ -43,18 +88,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.batch_process_documents", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "BatchProcessDocuments" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.BatchProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_process_documents" }, + "description": "Sample for BatchProcessDocuments", "file": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_sync", "segments": [ { @@ -87,19 +168,59 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.create_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.CreateProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "CreateProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.CreateProcessorRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "processor", + "type": "google.cloud.documentai_v1beta3.types.Processor" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.Processor", + "shortName": "create_processor" }, + "description": "Sample for CreateProcessor", "file": "documentai_v1beta3_generated_document_processor_service_create_processor_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_async", "segments": [ { @@ -132,18 +253,58 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_create_processor_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.create_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.CreateProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "CreateProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.CreateProcessorRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "processor", + "type": "google.cloud.documentai_v1beta3.types.Processor" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.Processor", + "shortName": "create_processor" }, + "description": "Sample for CreateProcessor", "file": "documentai_v1beta3_generated_document_processor_service_create_processor_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_sync", "segments": [ { @@ -176,19 +337,55 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_create_processor_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.delete_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.DeleteProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "DeleteProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.DeleteProcessorRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_processor" }, + "description": "Sample for DeleteProcessor", "file": "documentai_v1beta3_generated_document_processor_service_delete_processor_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_async", "segments": [ { @@ -221,18 +418,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_delete_processor_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.delete_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.DeleteProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "DeleteProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.DeleteProcessorRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_processor" }, + "description": "Sample for DeleteProcessor", "file": "documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_sync", "segments": [ { @@ -265,19 +498,51 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.disable_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.DisableProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "DisableProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.DisableProcessorRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "disable_processor" }, + "description": "Sample for DisableProcessor", "file": "documentai_v1beta3_generated_document_processor_service_disable_processor_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_async", "segments": [ { @@ -310,18 +575,50 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_disable_processor_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.disable_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.DisableProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "DisableProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.DisableProcessorRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "disable_processor" }, + "description": "Sample for DisableProcessor", "file": "documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_sync", "segments": [ { @@ -354,19 +651,51 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.enable_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.EnableProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "EnableProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.EnableProcessorRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "enable_processor" }, + "description": "Sample for EnableProcessor", "file": "documentai_v1beta3_generated_document_processor_service_enable_processor_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_async", "segments": [ { @@ -399,18 +728,50 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_enable_processor_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.enable_processor", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.EnableProcessor", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "EnableProcessor" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.EnableProcessorRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "enable_processor" }, + "description": "Sample for EnableProcessor", "file": "documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_sync", "segments": [ { @@ -443,19 +804,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.fetch_processor_types", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.FetchProcessorTypes", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "FetchProcessorTypes" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse", + "shortName": "fetch_processor_types" }, + "description": "Sample for FetchProcessorTypes", "file": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_async", "segments": [ { @@ -488,18 +885,54 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.fetch_processor_types", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.FetchProcessorTypes", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "FetchProcessorTypes" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse", + "shortName": "fetch_processor_types" }, + "description": "Sample for FetchProcessorTypes", "file": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_sync", "segments": [ { @@ -532,19 +965,55 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.list_processors", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ListProcessors", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ListProcessors" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ListProcessorsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsAsyncPager", + "shortName": "list_processors" }, + "description": "Sample for ListProcessors", "file": "documentai_v1beta3_generated_document_processor_service_list_processors_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_async", "segments": [ { @@ -577,18 +1046,54 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_list_processors_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.list_processors", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ListProcessors", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ListProcessors" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ListProcessorsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsPager", + "shortName": "list_processors" }, + "description": "Sample for ListProcessors", "file": "documentai_v1beta3_generated_document_processor_service_list_processors_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_sync", "segments": [ { @@ -621,19 +1126,55 @@ "start": 42, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_list_processors_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.ProcessResponse", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1beta3_generated_document_processor_service_process_document_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_async", "segments": [ { @@ -666,18 +1207,54 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_process_document_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.process_document", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ProcessDocument", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ProcessDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ProcessRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.documentai_v1beta3.types.ProcessResponse", + "shortName": "process_document" }, + "description": "Sample for ProcessDocument", "file": "documentai_v1beta3_generated_document_processor_service_process_document_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_sync", "segments": [ { @@ -710,19 +1287,55 @@ "start": 46, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_process_document_sync.py" }, { + "canonical": true, "clientMethod": { "async": true, + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient", + "shortName": "DocumentProcessorServiceAsyncClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceAsyncClient.review_document", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ReviewDocument", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ReviewDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ReviewDocumentRequest" + }, + { + "name": "human_review_config", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "review_document" }, + "description": "Sample for ReviewDocument", "file": "documentai_v1beta3_generated_document_processor_service_review_document_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_async", "segments": [ { @@ -755,18 +1368,54 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_review_document_async.py" }, { + "canonical": true, "clientMethod": { + "client": { + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient", + "shortName": "DocumentProcessorServiceClient" + }, + "fullName": "google.cloud.documentai_v1beta3.DocumentProcessorServiceClient.review_document", "method": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService.ReviewDocument", "service": { + "fullName": "google.cloud.documentai.v1beta3.DocumentProcessorService", "shortName": "DocumentProcessorService" }, "shortName": "ReviewDocument" - } + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.documentai_v1beta3.types.ReviewDocumentRequest" + }, + { + "name": "human_review_config", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "review_document" }, + "description": "Sample for ReviewDocument", "file": "documentai_v1beta3_generated_document_processor_service_review_document_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_sync", "segments": [ { @@ -799,7 +1448,8 @@ "start": 50, "type": "RESPONSE_HANDLING" } - ] + ], + "title": "documentai_v1beta3_generated_document_processor_service_review_document_sync.py" } ] } diff --git a/samples/snippets/batch_parse_form_v1beta2.py b/samples/snippets/batch_parse_form_v1beta2.py deleted file mode 100644 index a3220b4a..00000000 --- a/samples/snippets/batch_parse_form_v1beta2.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# [START documentai_batch_parse_form_beta] -import re - -from google.cloud import documentai_v1beta2 as documentai -from google.cloud import storage - - -def batch_parse_form( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/form.pdf", - destination_uri="gs://your-bucket-id/path/to/save/results/", - timeout=90, -): - """Parse a form""" - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # where to write results - output_config = documentai.types.OutputConfig( - gcs_destination=documentai.types.GcsDestination(uri=destination_uri), - pages_per_shard=1, # Map one doc page to one output page - ) - - # Improve form parsing results by providing key-value pair hints. - # For each key hint, key is text that is likely to appear in the - # document as a form field name (i.e. "DOB"). - # Value types are optional, but can be one or more of: - # ADDRESS, LOCATION, ORGANIZATION, PERSON, PHONE_NUMBER, ID, - # NUMBER, EMAIL, PRICE, TERMS, DATE, NAME - key_value_pair_hints = [ - documentai.types.KeyValuePairHint( - key="Emergency Contact", value_types=["NAME"] - ), - documentai.types.KeyValuePairHint(key="Referred By"), - ] - - # Setting enabled=True enables form extraction - form_extraction_params = documentai.types.FormExtractionParams( - enabled=True, key_value_pair_hints=key_value_pair_hints - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - input_config=input_config, - output_config=output_config, - form_extraction_params=form_extraction_params, - ) - - # Add each ProcessDocumentRequest to the batch request - requests = [] - requests.append(request) - - batch_request = documentai.types.BatchProcessDocumentsRequest( - parent=parent, requests=requests - ) - - operation = client.batch_process_documents(batch_request) - - # Wait for the operation to finish - operation.result(timeout) - - # Results are written to GCS. Use a regex to find - # output files - match = re.match(r"gs://([^/]+)/(.+)", destination_uri) - output_bucket = match.group(1) - prefix = match.group(2) - - storage_client = storage.client.Client() - bucket = storage_client.get_bucket(output_bucket) - blob_list = list(bucket.list_blobs(prefix=prefix)) - print("Output files:") - for blob in blob_list: - print(blob.name) - - -# [END documentai_batch_parse_form_beta] diff --git a/samples/snippets/batch_parse_form_v1beta2_test.py b/samples/snippets/batch_parse_form_v1beta2_test.py deleted file mode 100644 index f42cb249..00000000 --- a/samples/snippets/batch_parse_form_v1beta2_test.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os -import uuid - -from google.cloud import storage - -import pytest - -from samples.snippets import batch_parse_form_v1beta2 - - -BUCKET = "document-ai-{}".format(uuid.uuid4()) -OUTPUT_PREFIX = "TEST_OUTPUT_{}".format(uuid.uuid4()) -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" -BATCH_OUTPUT_URI = "gs://{}/{}/".format(BUCKET, OUTPUT_PREFIX) - - -@pytest.fixture(autouse=True) -def setup_teardown(): - """Create a temporary bucket to store annotation output.""" - storage_client = storage.Client() - bucket = storage_client.create_bucket(BUCKET) - - yield - - bucket.delete(force=True) - - -def test_batch_parse_form(capsys): - batch_parse_form_v1beta2.batch_parse_form( - PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120 - ) - out, _ = capsys.readouterr() - assert "Output files" in out diff --git a/samples/snippets/batch_parse_table_v1beta2.py b/samples/snippets/batch_parse_table_v1beta2.py deleted file mode 100644 index 16851437..00000000 --- a/samples/snippets/batch_parse_table_v1beta2.py +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# [START documentai_batch_parse_table_beta] -import re - -from google.cloud import documentai_v1beta2 as documentai -from google.cloud import storage - - -def batch_parse_table( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/form.pdf", - destination_uri="gs://your-bucket-id/path/to/save/results/", - timeout=90, -): - """Parse a form""" - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # where to write results - output_config = documentai.types.OutputConfig( - gcs_destination=documentai.types.GcsDestination(uri=destination_uri), - pages_per_shard=1, # Map one doc page to one output page - ) - - # Improve table parsing results by providing bounding boxes - # specifying where the box appears in the document (optional) - table_bound_hints = [ - documentai.types.TableBoundHint( - page_number=1, - bounding_box=documentai.types.BoundingPoly( - # Define a polygon around tables to detect - # Each vertice coordinate must be a number between 0 and 1 - normalized_vertices=[ - # Top left - documentai.types.geometry.NormalizedVertex(x=0, y=0), - # Top right - documentai.types.geometry.NormalizedVertex(x=1, y=0), - # Bottom right - documentai.types.geometry.NormalizedVertex(x=1, y=1), - # Bottom left - documentai.types.geometry.NormalizedVertex(x=0, y=1), - ] - ), - ) - ] - - # Setting enabled=True enables form extraction - table_extraction_params = documentai.types.TableExtractionParams( - enabled=True, table_bound_hints=table_bound_hints - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - input_config=input_config, - output_config=output_config, - table_extraction_params=table_extraction_params, - ) - - requests = [] - requests.append(request) - - batch_request = documentai.types.BatchProcessDocumentsRequest( - parent=parent, requests=requests - ) - - operation = client.batch_process_documents(batch_request) - - # Wait for the operation to finish - operation.result(timeout) - - # Results are written to GCS. Use a regex to find - # output files - match = re.match(r"gs://([^/]+)/(.+)", destination_uri) - output_bucket = match.group(1) - prefix = match.group(2) - - storage_client = storage.client.Client() - bucket = storage_client.get_bucket(output_bucket) - blob_list = list(bucket.list_blobs(prefix=prefix)) - print("Output files:") - for blob in blob_list: - print(blob.name) - - -# [END documentai_batch_parse_table_beta] diff --git a/samples/snippets/batch_parse_table_v1beta2_test.py b/samples/snippets/batch_parse_table_v1beta2_test.py deleted file mode 100644 index 0818d8c0..00000000 --- a/samples/snippets/batch_parse_table_v1beta2_test.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os -import uuid - -from google.cloud import storage - -import pytest - -from samples.snippets import batch_parse_table_v1beta2 - - -BUCKET = "document-ai-{}".format(uuid.uuid4()) -OUTPUT_PREFIX = "TEST_OUTPUT_{}".format(uuid.uuid4()) -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" -BATCH_OUTPUT_URI = "gs://{}/{}/".format(BUCKET, OUTPUT_PREFIX) - - -@pytest.fixture(autouse=True) -def setup_teardown(): - """Create a temporary bucket to store annotation output.""" - storage_client = storage.Client() - bucket = storage_client.create_bucket(BUCKET) - - yield - - bucket.delete(force=True) - - -def test_batch_parse_table(capsys): - batch_parse_table_v1beta2.batch_parse_table( - PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120 - ) - out, _ = capsys.readouterr() - assert "Output files:" in out diff --git a/samples/snippets/batch_process_documents_sample.py b/samples/snippets/batch_process_documents_sample.py index d85948e7..88217093 100644 --- a/samples/snippets/batch_process_documents_sample.py +++ b/samples/snippets/batch_process_documents_sample.py @@ -63,7 +63,9 @@ def batch_process_documents( # Location can be 'us' or 'eu' name = f"projects/{project_id}/locations/{location}/processors/{processor_id}" request = documentai.types.document_processor_service.BatchProcessRequest( - name=name, input_documents=input_config, document_output_config=output_config, + name=name, + input_documents=input_config, + document_output_config=output_config, ) operation = client.batch_process_documents(request) diff --git a/samples/snippets/batch_process_documents_sample_test.py b/samples/snippets/batch_process_documents_sample_test.py index 7168d5a7..d3018fb6 100644 --- a/samples/snippets/batch_process_documents_sample_test.py +++ b/samples/snippets/batch_process_documents_sample_test.py @@ -18,9 +18,7 @@ from google.cloud import storage from google.cloud.exceptions import NotFound - import pytest - from samples.snippets import batch_process_documents_sample location = "us" diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 85f5836d..3b3ffa5d 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -22,14 +22,14 @@ import nox - # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING # DO NOT EDIT THIS FILE EVER! # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -168,12 +168,33 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) +# +# format = isort + black +# + + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # @@ -253,7 +274,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/samples/snippets/parse_form_v1beta2.py b/samples/snippets/parse_form_v1beta2.py deleted file mode 100644 index 27c99811..00000000 --- a/samples/snippets/parse_form_v1beta2.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the 'License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START documentai_parse_form_beta] -from google.cloud import documentai_v1beta2 as documentai - - -def parse_form( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/form.pdf", -): - """Parse a form""" - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # Improve form parsing results by providing key-value pair hints. - # For each key hint, key is text that is likely to appear in the - # document as a form field name (i.e. "DOB"). - # Value types are optional, but can be one or more of: - # ADDRESS, LOCATION, ORGANIZATION, PERSON, PHONE_NUMBER, ID, - # NUMBER, EMAIL, PRICE, TERMS, DATE, NAME - key_value_pair_hints = [ - documentai.types.KeyValuePairHint( - key="Emergency Contact", value_types=["NAME"] - ), - documentai.types.KeyValuePairHint(key="Referred By"), - ] - - # Setting enabled=True enables form extraction - form_extraction_params = documentai.types.FormExtractionParams( - enabled=True, key_value_pair_hints=key_value_pair_hints - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - parent=parent, - input_config=input_config, - form_extraction_params=form_extraction_params, - ) - - document = client.process_document(request=request) - - def _get_text(el): - """Doc AI identifies form fields by their offsets - in document text. This function converts offsets - to text snippets. - """ - response = "" - # If a text segment spans several lines, it will - # be stored in different text segments. - for segment in el.text_anchor.text_segments: - start_index = segment.start_index - end_index = segment.end_index - response += document.text[start_index:end_index] - return response - - for page in document.pages: - print("Page number: {}".format(page.page_number)) - for form_field in page.form_fields: - print( - "Field Name: {}\tConfidence: {}".format( - _get_text(form_field.field_name), form_field.field_name.confidence - ) - ) - print( - "Field Value: {}\tConfidence: {}".format( - _get_text(form_field.field_value), form_field.field_value.confidence - ) - ) - - -# [END documentai_parse_form_beta] diff --git a/samples/snippets/parse_form_v1beta2_test.py b/samples/snippets/parse_form_v1beta2_test.py deleted file mode 100644 index 6987612a..00000000 --- a/samples/snippets/parse_form_v1beta2_test.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os - -from samples.snippets import parse_form_v1beta2 - - -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/form.pdf" - - -def test_parse_form(capsys): - parse_form_v1beta2.parse_form(PROJECT_ID, INPUT_URI) - out, _ = capsys.readouterr() - assert "Field Name" in out - assert "Field Value" in out diff --git a/samples/snippets/parse_table_v1beta2.py b/samples/snippets/parse_table_v1beta2.py deleted file mode 100644 index ac8f5d11..00000000 --- a/samples/snippets/parse_table_v1beta2.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START documentai_parse_table_beta] -from google.cloud import documentai_v1beta2 as documentai - - -def parse_table( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/invoice.pdf", -): - """Parse a form""" - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # Improve table parsing results by providing bounding boxes - # specifying where the box appears in the document (optional) - table_bound_hints = [ - documentai.types.TableBoundHint( - page_number=1, - bounding_box=documentai.types.BoundingPoly( - # Define a polygon around tables to detect - # Each vertice coordinate must be a number between 0 and 1 - normalized_vertices=[ - # Top left - documentai.types.geometry.NormalizedVertex(x=0, y=0), - # Top right - documentai.types.geometry.NormalizedVertex(x=1, y=0), - # Bottom right - documentai.types.geometry.NormalizedVertex(x=1, y=1), - # Bottom left - documentai.types.geometry.NormalizedVertex(x=0, y=1), - ] - ), - ) - ] - - # Setting enabled=True enables form extraction - table_extraction_params = documentai.types.TableExtractionParams( - enabled=True, table_bound_hints=table_bound_hints - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - parent=parent, - input_config=input_config, - table_extraction_params=table_extraction_params, - ) - - document = client.process_document(request=request) - - def _get_text(el): - """Convert text offset indexes into text snippets.""" - response = "" - # If a text segment spans several lines, it will - # be stored in different text segments. - for segment in el.text_anchor.text_segments: - start_index = segment.start_index - end_index = segment.end_index - response += document.text[start_index:end_index] - return response - - for page in document.pages: - print("Page number: {}".format(page.page_number)) - for table_num, table in enumerate(page.tables): - print("Table {}: ".format(table_num)) - for row_num, row in enumerate(table.header_rows): - cells = "\t".join([_get_text(cell.layout) for cell in row.cells]) - print("Header Row {}: {}".format(row_num, cells)) - for row_num, row in enumerate(table.body_rows): - cells = "\t".join([_get_text(cell.layout) for cell in row.cells]) - print("Row {}: {}".format(row_num, cells)) - - -# [END documentai_parse_table_beta] diff --git a/samples/snippets/parse_table_v1beta2_test.py b/samples/snippets/parse_table_v1beta2_test.py deleted file mode 100644 index 4102c926..00000000 --- a/samples/snippets/parse_table_v1beta2_test.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os - -from samples.snippets import parse_table_v1beta2 - - -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" - - -def test_parse_table(capsys): - parse_table_v1beta2.parse_table(PROJECT_ID, INPUT_URI) - out, _ = capsys.readouterr() - assert "Table" in out - assert "Header Row" in out diff --git a/samples/snippets/parse_with_model_v1beta2.py b/samples/snippets/parse_with_model_v1beta2.py deleted file mode 100644 index 59265c4f..00000000 --- a/samples/snippets/parse_with_model_v1beta2.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# [START documentai_parse_with_model_beta] -from google.cloud import documentai_v1beta2 as documentai - - -def parse_with_model( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/invoice.pdf", - automl_model_name="YOUR_AUTOML_MODEL_NAME", -): - """Process a single document with the Document AI API. - - Args: - project_id: your Google Cloud project id - input_uri: the Cloud Storage URI of your input PDF - automl_model_name: the AutoML model name formatted as: - `projects/[PROJECT_ID]/locations/[LOCATION]/models/[MODEL_ID] - where LOCATION is a Compute Engine region, e.g. `us-central1` - """ - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - automl_params = documentai.types.AutoMlParams(model=automl_model_name) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - parent=parent, input_config=input_config, automl_params=automl_params - ) - - document = client.process_document(request=request) - - for label in document.labels: - print("Label detected: {}".format(label.name)) - print("Confidence: {}".format(label.confidence)) - - -# [END documentai_parse_with_model_beta] diff --git a/samples/snippets/parse_with_model_v1beta2_test.py b/samples/snippets/parse_with_model_v1beta2_test.py deleted file mode 100644 index 4b5d3ca5..00000000 --- a/samples/snippets/parse_with_model_v1beta2_test.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os - -from samples.snippets import parse_with_model_v1beta2 - - -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" -AUTOML_NL_MODEL_ID = "TCN3472481026502981088" - -if "AUTOML_NL_MODEL_ID" in os.environ: - AUTOML_NL_MODEL_ID = os.environ["AUTOML_NL_MODEL_ID"] - -MODEL_NAME = "projects/{}/locations/us-central1/models/{}".format( - PROJECT_ID, AUTOML_NL_MODEL_ID -) - - -def test_parse_with_model(capsys): - parse_with_model_v1beta2.parse_with_model(PROJECT_ID, INPUT_URI, MODEL_NAME) - out, _ = capsys.readouterr() - assert "Label detected" in out - assert "Confidence" in out diff --git a/samples/snippets/process_document_form_sample_test.py b/samples/snippets/process_document_form_sample_test.py index da76d6d0..38f722de 100644 --- a/samples/snippets/process_document_form_sample_test.py +++ b/samples/snippets/process_document_form_sample_test.py @@ -17,7 +17,6 @@ from samples.snippets import process_document_form_sample - location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] processor_id = "90484cfdedb024f6" diff --git a/samples/snippets/process_document_quality_sample_test.py b/samples/snippets/process_document_quality_sample_test.py index b025756e..a0dc52cb 100644 --- a/samples/snippets/process_document_quality_sample_test.py +++ b/samples/snippets/process_document_quality_sample_test.py @@ -17,7 +17,6 @@ from samples.snippets import process_document_quality_sample - location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] processor_id = "7fcb597c523721b3" diff --git a/samples/snippets/process_document_sample_test.py b/samples/snippets/process_document_sample_test.py index 8fe188d8..48dce8bb 100644 --- a/samples/snippets/process_document_sample_test.py +++ b/samples/snippets/process_document_sample_test.py @@ -17,7 +17,6 @@ from samples.snippets import process_document_sample - location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] processor_id = "90484cfdedb024f6" diff --git a/samples/snippets/process_document_specialized_sample_test.py b/samples/snippets/process_document_specialized_sample_test.py index 04a7abec..a3156c96 100644 --- a/samples/snippets/process_document_specialized_sample_test.py +++ b/samples/snippets/process_document_specialized_sample_test.py @@ -17,7 +17,6 @@ from samples.snippets import process_document_specialized_sample - location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] processor_id = "feacd98c28866ede" diff --git a/samples/snippets/process_document_splitter_sample.py b/samples/snippets/process_document_splitter_sample.py index 95607854..f80c7b4e 100644 --- a/samples/snippets/process_document_splitter_sample.py +++ b/samples/snippets/process_document_splitter_sample.py @@ -75,7 +75,7 @@ def process_document_splitter_sample( def page_refs_to_string(page_refs: dict) -> str: - """ Converts a page ref to a string describing the page or page range.""" + """Converts a page ref to a string describing the page or page range.""" if len(page_refs) == 1: num = str(int(page_refs[0].page) + 1) return f"page {num} is" diff --git a/samples/snippets/process_document_splitter_sample_test.py b/samples/snippets/process_document_splitter_sample_test.py index df0baf26..575edf60 100644 --- a/samples/snippets/process_document_splitter_sample_test.py +++ b/samples/snippets/process_document_splitter_sample_test.py @@ -17,7 +17,6 @@ from samples.snippets import process_document_splitter_sample - location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] processor_id = "ed55eeb2b276066f" diff --git a/samples/snippets/quickstart_v1beta2.py b/samples/snippets/quickstart_v1beta2.py deleted file mode 100644 index 34f58820..00000000 --- a/samples/snippets/quickstart_v1beta2.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# [START documentai_quickstart_beta] -from google.cloud import documentai_v1beta2 as documentai - - -def main( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/invoice.pdf", -): - """Process a single document with the Document AI API, including - text extraction and entity extraction.""" - - client = documentai.DocumentUnderstandingServiceClient() - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/us".format(project_id) - request = documentai.types.ProcessDocumentRequest( - parent=parent, input_config=input_config - ) - - document = client.process_document(request=request) - - # All text extracted from the document - print("Document Text: {}".format(document.text)) - - def _get_text(el): - """Convert text offset indexes into text snippets.""" - response = "" - # If a text segment spans several lines, it will - # be stored in different text segments. - for segment in el.text_anchor.text_segments: - start_index = segment.start_index - end_index = segment.end_index - response += document.text[start_index:end_index] - return response - - for entity in document.entities: - print("Entity type: {}".format(entity.type_)) - print("Text: {}".format(_get_text(entity))) - print("Mention text: {}\n".format(entity.mention_text)) - - -# [END documentai_quickstart_beta] diff --git a/samples/snippets/quickstart_v1beta2_test.py b/samples/snippets/quickstart_v1beta2_test.py deleted file mode 100644 index 1868788d..00000000 --- a/samples/snippets/quickstart_v1beta2_test.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific ladnguage governing permissions and -# limitations under the License. - -import os - -from samples.snippets import quickstart_v1beta2 - - -PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] -INPUT_URI = "gs://cloud-samples-data/documentai/invoice.pdf" - - -def test_quickstart(capsys): - quickstart_v1beta2.main(PROJECT_ID, INPUT_URI) - out, _ = capsys.readouterr() - assert "Entity type" in out - assert "Mention text" in out diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 4f6bf643..d00689e0 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.1.1 +pytest==7.1.2 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index b9a58c5f..b15c1f31 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-documentai==1.3.0 -google-cloud-storage==2.2.1 +google-cloud-documentai==1.4.0 +google-cloud-storage==2.3.0 diff --git a/samples/snippets/set_endpoint_v1beta2.py b/samples/snippets/set_endpoint_v1beta2.py deleted file mode 100644 index 0fa9921b..00000000 --- a/samples/snippets/set_endpoint_v1beta2.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -def set_endpoint( - project_id="YOUR_PROJECT_ID", - input_uri="gs://cloud-samples-data/documentai/invoice.pdf", -): - """Process a single document with the Document AI API, including - text extraction and entity extraction.""" - - # [START documentai_set_endpoint_beta] - from google.cloud import documentai_v1beta2 as documentai - - client = documentai.DocumentUnderstandingServiceClient( - client_options={"api_endpoint": "eu-documentai.googleapis.com"} - ) - # [END documentai_set_endpoint_beta] - - gcs_source = documentai.types.GcsSource(uri=input_uri) - - # mime_type can be application/pdf, image/tiff, - # and image/gif, or application/json - input_config = documentai.types.InputConfig( - gcs_source=gcs_source, mime_type="application/pdf" - ) - - # Location can be 'us' or 'eu' - parent = "projects/{}/locations/eu".format(project_id) - request = documentai.types.ProcessDocumentRequest( - parent=parent, input_config=input_config - ) - - document = client.process_document(request=request) - - # All text extracted from the document - print("Document Text: {}".format(document.text)) diff --git a/setup.py b/setup.py index 0cb82f8d..6392f42e 100644 --- a/setup.py +++ b/setup.py @@ -17,9 +17,10 @@ import io import os + import setuptools # type: ignore -version = "1.4.0" +version = "1.4.1" package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index f2674284..82d570f2 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -13,39 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os -import mock - -import grpc -from grpc.experimental import aio import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - +import os +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + operations_v1, + path_template, +) from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.cloud.documentai_v1.services.document_processor_service import ( - DocumentProcessorServiceAsyncClient, -) -from google.cloud.documentai_v1.services.document_processor_service import ( - DocumentProcessorServiceClient, -) -from google.cloud.documentai_v1.services.document_processor_service import transports -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 -from google.cloud.documentai_v1.types import geometry from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -58,7 +43,23 @@ from google.type import datetime_pb2 # type: ignore from google.type import money_pb2 # type: ignore from google.type import postal_address_pb2 # type: ignore -import google.auth +import grpc +from grpc.experimental import aio +import mock +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest + +from google.cloud.documentai_v1.services.document_processor_service import ( + DocumentProcessorServiceAsyncClient, + DocumentProcessorServiceClient, + transports, +) +from google.cloud.documentai_v1.types import ( + document, + document_io, + document_processor_service, + geometry, +) def client_cert_source_callback(): @@ -107,21 +108,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", - [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentProcessorServiceClient, "grpc"), + (DocumentProcessorServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_processor_service_client_from_service_account_info(client_class): +def test_document_processor_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") @pytest.mark.parametrize( @@ -150,24 +156,33 @@ def test_document_processor_service_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", - [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentProcessorServiceClient, "grpc"), + (DocumentProcessorServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_processor_service_client_from_service_account_file(client_class): +def test_document_processor_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") def test_document_processor_service_client_get_transport_class(): @@ -540,7 +555,9 @@ def test_document_processor_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + 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, transport=transport_name) @@ -681,11 +698,16 @@ def test_document_processor_service_client_create_channel_credentials_file( @pytest.mark.parametrize( - "request_type", [document_processor_service.ProcessRequest, dict,] + "request_type", + [ + document_processor_service.ProcessRequest, + dict, + ], ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -711,7 +733,8 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -728,7 +751,8 @@ async def test_process_document_async( request_type=document_processor_service.ProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -766,7 +790,7 @@ def test_process_document_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.ProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -780,7 +804,10 @@ def test_process_document_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -793,7 +820,7 @@ async def test_process_document_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.ProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -809,7 +836,10 @@ async def test_process_document_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_process_document_flattened(): @@ -823,7 +853,9 @@ def test_process_document_flattened(): call.return_value = document_processor_service.ProcessResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.process_document(name="name_value",) + client.process_document( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -843,7 +875,8 @@ def test_process_document_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.process_document( - document_processor_service.ProcessRequest(), name="name_value", + document_processor_service.ProcessRequest(), + name="name_value", ) @@ -863,7 +896,9 @@ async def test_process_document_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.process_document(name="name_value",) + response = await client.process_document( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -884,16 +919,22 @@ async def test_process_document_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.process_document( - document_processor_service.ProcessRequest(), name="name_value", + document_processor_service.ProcessRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [document_processor_service.BatchProcessRequest, dict,] + "request_type", + [ + document_processor_service.BatchProcessRequest, + dict, + ], ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -921,7 +962,8 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +982,8 @@ async def test_batch_process_documents_async( request_type=document_processor_service.BatchProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -980,7 +1023,7 @@ def test_batch_process_documents_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.BatchProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -996,7 +1039,10 @@ def test_batch_process_documents_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1009,7 +1055,7 @@ async def test_batch_process_documents_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.BatchProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1027,7 +1073,10 @@ async def test_batch_process_documents_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_batch_process_documents_flattened(): @@ -1043,7 +1092,9 @@ def test_batch_process_documents_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.batch_process_documents(name="name_value",) + client.batch_process_documents( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1063,7 +1114,8 @@ def test_batch_process_documents_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.batch_process_documents( - document_processor_service.BatchProcessRequest(), name="name_value", + document_processor_service.BatchProcessRequest(), + name="name_value", ) @@ -1085,7 +1137,9 @@ async def test_batch_process_documents_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.batch_process_documents(name="name_value",) + response = await client.batch_process_documents( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1106,16 +1160,22 @@ async def test_batch_process_documents_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.batch_process_documents( - document_processor_service.BatchProcessRequest(), name="name_value", + document_processor_service.BatchProcessRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [document_processor_service.ReviewDocumentRequest, dict,] + "request_type", + [ + document_processor_service.ReviewDocumentRequest, + dict, + ], ) def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1141,7 +1201,8 @@ def test_review_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1158,7 +1219,8 @@ async def test_review_document_async( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1196,7 +1258,7 @@ def test_review_document_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.ReviewDocumentRequest() - request.human_review_config = "human_review_config/value" + request.human_review_config = "human_review_config_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.review_document), "__call__") as call: @@ -1212,7 +1274,7 @@ def test_review_document_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "human_review_config=human_review_config/value", + "human_review_config=human_review_config_value", ) in kw["metadata"] @@ -1226,7 +1288,7 @@ async def test_review_document_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.ReviewDocumentRequest() - request.human_review_config = "human_review_config/value" + request.human_review_config = "human_review_config_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.review_document), "__call__") as call: @@ -1244,7 +1306,7 @@ async def test_review_document_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "human_review_config=human_review_config/value", + "human_review_config=human_review_config_value", ) in kw["metadata"] @@ -1259,7 +1321,9 @@ def test_review_document_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.review_document(human_review_config="human_review_config_value",) + client.review_document( + human_review_config="human_review_config_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1335,7 +1399,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1356,7 +1421,8 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - client_options=options, transport=transport, + client_options=options, + transport=transport, ) # It is an error to provide an api_key and a credential. @@ -1373,7 +1439,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1416,13 +1483,27 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DocumentProcessorServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( - client.transport, transports.DocumentProcessorServiceGrpcTransport, + client.transport, + transports.DocumentProcessorServiceGrpcTransport, ) @@ -1464,6 +1545,14 @@ def test_document_processor_service_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -1475,7 +1564,8 @@ def test_document_processor_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1612,24 +1702,40 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( ) -def test_document_processor_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_processor_service_host_no_port(transport_name): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") -def test_document_processor_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_processor_service_host_with_port(transport_name): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:8000" + assert client.transport._host == ("documentai.googleapis.com:8000") def test_document_processor_service_grpc_transport_channel(): @@ -1637,7 +1743,8 @@ def test_document_processor_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentProcessorServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1649,7 +1756,8 @@ def test_document_processor_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1758,12 +1866,16 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl def test_document_processor_service_grpc_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1771,12 +1883,16 @@ def test_document_processor_service_grpc_lro_client(): def test_document_processor_service_grpc_lro_async_client(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1787,7 +1903,9 @@ def test_human_review_config_path(): location = "clam" processor = "whelk" expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) actual = DocumentProcessorServiceClient.human_review_config_path( project, location, processor @@ -1813,7 +1931,9 @@ def test_processor_path(): location = "mussel" processor = "winkle" expected = "projects/{project}/locations/{location}/processors/{processor}".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) actual = DocumentProcessorServiceClient.processor_path(project, location, processor) assert expected == actual @@ -1854,7 +1974,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DocumentProcessorServiceClient.common_folder_path(folder) assert expected == actual @@ -1872,7 +1994,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DocumentProcessorServiceClient.common_organization_path(organization) assert expected == actual @@ -1890,7 +2014,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DocumentProcessorServiceClient.common_project_path(project) assert expected == actual @@ -1910,7 +2036,8 @@ def test_common_location_path(): project = "winkle" location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DocumentProcessorServiceClient.common_location_path(project, location) assert expected == actual @@ -1935,7 +2062,8 @@ def test_client_with_default_client_info(): transports.DocumentProcessorServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1944,7 +2072,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentProcessorServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1952,7 +2081,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 8f31ff05..3acba2d8 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -13,44 +13,43 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os -import mock - -import grpc -from grpc.experimental import aio import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - +import os +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + operations_v1, + path_template, +) from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.rpc import status_pb2 # type: ignore +import grpc +from grpc.experimental import aio +import mock +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest + from google.cloud.documentai_v1beta2.services.document_understanding_service import ( DocumentUnderstandingServiceAsyncClient, -) -from google.cloud.documentai_v1beta2.services.document_understanding_service import ( DocumentUnderstandingServiceClient, -) -from google.cloud.documentai_v1beta2.services.document_understanding_service import ( transports, ) -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 -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.rpc import status_pb2 # type: ignore -import google.auth +from google.cloud.documentai_v1beta2.types import ( + document, + document_understanding, + geometry, +) def client_cert_source_callback(): @@ -101,21 +100,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", - [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentUnderstandingServiceClient, "grpc"), + (DocumentUnderstandingServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_understanding_service_client_from_service_account_info(client_class): +def test_document_understanding_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") @pytest.mark.parametrize( @@ -144,24 +148,33 @@ def test_document_understanding_service_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", - [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentUnderstandingServiceClient, "grpc"), + (DocumentUnderstandingServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_understanding_service_client_from_service_account_file(client_class): +def test_document_understanding_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") def test_document_understanding_service_client_get_transport_class(): @@ -534,7 +547,9 @@ def test_document_understanding_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + 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, transport=transport_name) @@ -675,11 +690,16 @@ def test_document_understanding_service_client_create_channel_credentials_file( @pytest.mark.parametrize( - "request_type", [document_understanding.BatchProcessDocumentsRequest, dict,] + "request_type", + [ + document_understanding.BatchProcessDocumentsRequest, + dict, + ], ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -707,7 +727,8 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -726,7 +747,8 @@ async def test_batch_process_documents_async( request_type=document_understanding.BatchProcessDocumentsRequest, ): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -766,7 +788,7 @@ def test_batch_process_documents_field_headers(): # a field header. Set these to a non-empty value. request = document_understanding.BatchProcessDocumentsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -782,7 +804,10 @@ def test_batch_process_documents_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -795,7 +820,7 @@ async def test_batch_process_documents_field_headers_async(): # a field header. Set these to a non-empty value. request = document_understanding.BatchProcessDocumentsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -813,7 +838,10 @@ async def test_batch_process_documents_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_batch_process_documents_flattened(): @@ -915,11 +943,16 @@ async def test_batch_process_documents_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [document_understanding.ProcessDocumentRequest, dict,] + "request_type", + [ + document_understanding.ProcessDocumentRequest, + dict, + ], ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -930,7 +963,9 @@ def test_process_document(request_type, transport: str = "grpc"): with mock.patch.object(type(client.transport.process_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = document.Document( - mime_type="mime_type_value", text="text_value", uri="uri_value", + mime_type="mime_type_value", + text="text_value", + uri="uri_value", ) response = client.process_document(request) @@ -949,7 +984,8 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -966,7 +1002,8 @@ async def test_process_document_async( request_type=document_understanding.ProcessDocumentRequest, ): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -977,7 +1014,10 @@ async def test_process_document_async( with mock.patch.object(type(client.transport.process_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - document.Document(mime_type="mime_type_value", text="text_value",) + document.Document( + mime_type="mime_type_value", + text="text_value", + ) ) response = await client.process_document(request) @@ -1006,7 +1046,7 @@ def test_process_document_field_headers(): # a field header. Set these to a non-empty value. request = document_understanding.ProcessDocumentRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -1020,7 +1060,10 @@ def test_process_document_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1033,7 +1076,7 @@ async def test_process_document_field_headers_async(): # a field header. Set these to a non-empty value. request = document_understanding.ProcessDocumentRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -1047,7 +1090,10 @@ async def test_process_document_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_credentials_transport_error(): @@ -1057,7 +1103,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1078,7 +1125,8 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( - client_options=options, transport=transport, + client_options=options, + transport=transport, ) # It is an error to provide an api_key and a credential. @@ -1095,7 +1143,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1138,13 +1187,27 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DocumentUnderstandingServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( - client.transport, transports.DocumentUnderstandingServiceGrpcTransport, + client.transport, + transports.DocumentUnderstandingServiceGrpcTransport, ) @@ -1185,6 +1248,14 @@ def test_document_understanding_service_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_document_understanding_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -1196,7 +1267,8 @@ def test_document_understanding_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentUnderstandingServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1336,24 +1408,40 @@ def test_document_understanding_service_grpc_transport_client_cert_source_for_mt ) -def test_document_understanding_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_understanding_service_host_no_port(transport_name): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") -def test_document_understanding_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_understanding_service_host_with_port(transport_name): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:8000" + assert client.transport._host == ("documentai.googleapis.com:8000") def test_document_understanding_service_grpc_transport_channel(): @@ -1361,7 +1449,8 @@ def test_document_understanding_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentUnderstandingServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1373,7 +1462,8 @@ def test_document_understanding_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1484,12 +1574,16 @@ def test_document_understanding_service_transport_channel_mtls_with_adc( def test_document_understanding_service_grpc_lro_client(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1497,12 +1591,16 @@ def test_document_understanding_service_grpc_lro_client(): def test_document_understanding_service_grpc_lro_async_client(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1532,7 +1630,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DocumentUnderstandingServiceClient.common_folder_path(folder) assert expected == actual @@ -1550,7 +1650,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DocumentUnderstandingServiceClient.common_organization_path(organization) assert expected == actual @@ -1568,7 +1670,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DocumentUnderstandingServiceClient.common_project_path(project) assert expected == actual @@ -1588,7 +1692,8 @@ def test_common_location_path(): project = "winkle" location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DocumentUnderstandingServiceClient.common_location_path(project, location) assert expected == actual @@ -1613,7 +1718,8 @@ def test_client_with_default_client_info(): transports.DocumentUnderstandingServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1622,7 +1728,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentUnderstandingServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1630,7 +1737,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 39bcd6a2..458fc7a9 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -13,45 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os -import mock - -import grpc -from grpc.experimental import aio import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - +import os +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + operations_v1, + path_template, +) from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.cloud.documentai_v1beta3.services.document_processor_service import ( - DocumentProcessorServiceAsyncClient, -) -from google.cloud.documentai_v1beta3.services.document_processor_service import ( - DocumentProcessorServiceClient, -) -from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.services.document_processor_service import ( - transports, -) -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 -from google.cloud.documentai_v1beta3.types import geometry -from google.cloud.documentai_v1beta3.types import processor -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.cloud.documentai_v1beta3.types import processor_type from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -64,7 +43,27 @@ from google.type import datetime_pb2 # type: ignore from google.type import money_pb2 # type: ignore from google.type import postal_address_pb2 # type: ignore -import google.auth +import grpc +from grpc.experimental import aio +import mock +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest + +from google.cloud.documentai_v1beta3.services.document_processor_service import ( + DocumentProcessorServiceAsyncClient, + DocumentProcessorServiceClient, + pagers, + transports, +) +from google.cloud.documentai_v1beta3.types import ( + document, + document_io, + document_processor_service, + geometry, +) +from google.cloud.documentai_v1beta3.types import processor +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.types import processor_type def client_cert_source_callback(): @@ -113,21 +112,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", - [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentProcessorServiceClient, "grpc"), + (DocumentProcessorServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_processor_service_client_from_service_account_info(client_class): +def test_document_processor_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") @pytest.mark.parametrize( @@ -156,24 +160,33 @@ def test_document_processor_service_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", - [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], + "client_class,transport_name", + [ + (DocumentProcessorServiceClient, "grpc"), + (DocumentProcessorServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_document_processor_service_client_from_service_account_file(client_class): +def test_document_processor_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") def test_document_processor_service_client_get_transport_class(): @@ -546,7 +559,9 @@ def test_document_processor_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + 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, transport=transport_name) @@ -687,11 +702,16 @@ def test_document_processor_service_client_create_channel_credentials_file( @pytest.mark.parametrize( - "request_type", [document_processor_service.ProcessRequest, dict,] + "request_type", + [ + document_processor_service.ProcessRequest, + dict, + ], ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -720,7 +740,8 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -737,7 +758,8 @@ async def test_process_document_async( request_type=document_processor_service.ProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -778,7 +800,7 @@ def test_process_document_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.ProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -792,7 +814,10 @@ def test_process_document_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -805,7 +830,7 @@ async def test_process_document_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.ProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.process_document), "__call__") as call: @@ -821,7 +846,10 @@ async def test_process_document_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_process_document_flattened(): @@ -835,7 +863,9 @@ def test_process_document_flattened(): call.return_value = document_processor_service.ProcessResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.process_document(name="name_value",) + client.process_document( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -855,7 +885,8 @@ def test_process_document_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.process_document( - document_processor_service.ProcessRequest(), name="name_value", + document_processor_service.ProcessRequest(), + name="name_value", ) @@ -875,7 +906,9 @@ async def test_process_document_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.process_document(name="name_value",) + response = await client.process_document( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -896,16 +929,22 @@ async def test_process_document_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.process_document( - document_processor_service.ProcessRequest(), name="name_value", + document_processor_service.ProcessRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [document_processor_service.BatchProcessRequest, dict,] + "request_type", + [ + document_processor_service.BatchProcessRequest, + dict, + ], ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -933,7 +972,8 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -952,7 +992,8 @@ async def test_batch_process_documents_async( request_type=document_processor_service.BatchProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -992,7 +1033,7 @@ def test_batch_process_documents_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.BatchProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1008,7 +1049,10 @@ def test_batch_process_documents_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1021,7 +1065,7 @@ async def test_batch_process_documents_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.BatchProcessRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1039,7 +1083,10 @@ async def test_batch_process_documents_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_batch_process_documents_flattened(): @@ -1055,7 +1102,9 @@ def test_batch_process_documents_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.batch_process_documents(name="name_value",) + client.batch_process_documents( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1075,7 +1124,8 @@ def test_batch_process_documents_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.batch_process_documents( - document_processor_service.BatchProcessRequest(), name="name_value", + document_processor_service.BatchProcessRequest(), + name="name_value", ) @@ -1097,7 +1147,9 @@ async def test_batch_process_documents_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.batch_process_documents(name="name_value",) + response = await client.batch_process_documents( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1118,16 +1170,22 @@ async def test_batch_process_documents_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.batch_process_documents( - document_processor_service.BatchProcessRequest(), name="name_value", + document_processor_service.BatchProcessRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [document_processor_service.FetchProcessorTypesRequest, dict,] + "request_type", + [ + document_processor_service.FetchProcessorTypesRequest, + dict, + ], ) def test_fetch_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1155,7 +1213,8 @@ def test_fetch_processor_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1174,7 +1233,8 @@ async def test_fetch_processor_types_async( request_type=document_processor_service.FetchProcessorTypesRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1214,7 +1274,7 @@ def test_fetch_processor_types_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.FetchProcessorTypesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1230,7 +1290,10 @@ def test_fetch_processor_types_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1243,7 +1306,7 @@ async def test_fetch_processor_types_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.FetchProcessorTypesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1261,7 +1324,10 @@ async def test_fetch_processor_types_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_fetch_processor_types_flattened(): @@ -1277,7 +1343,9 @@ def test_fetch_processor_types_flattened(): call.return_value = document_processor_service.FetchProcessorTypesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.fetch_processor_types(parent="parent_value",) + client.fetch_processor_types( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1320,7 +1388,9 @@ async def test_fetch_processor_types_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.fetch_processor_types(parent="parent_value",) + response = await client.fetch_processor_types( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1347,11 +1417,16 @@ async def test_fetch_processor_types_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [document_processor_service.ListProcessorsRequest, dict,] + "request_type", + [ + document_processor_service.ListProcessorsRequest, + dict, + ], ) def test_list_processors(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1380,7 +1455,8 @@ def test_list_processors_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1397,7 +1473,8 @@ async def test_list_processors_async( request_type=document_processor_service.ListProcessorsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1438,7 +1515,7 @@ def test_list_processors_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.ListProcessorsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_processors), "__call__") as call: @@ -1452,7 +1529,10 @@ def test_list_processors_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1465,7 +1545,7 @@ async def test_list_processors_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.ListProcessorsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_processors), "__call__") as call: @@ -1481,7 +1561,10 @@ async def test_list_processors_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_processors_flattened(): @@ -1495,7 +1578,9 @@ def test_list_processors_flattened(): call.return_value = document_processor_service.ListProcessorsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_processors(parent="parent_value",) + client.list_processors( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1515,7 +1600,8 @@ def test_list_processors_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_processors( - document_processor_service.ListProcessorsRequest(), parent="parent_value", + document_processor_service.ListProcessorsRequest(), + parent="parent_value", ) @@ -1535,7 +1621,9 @@ async def test_list_processors_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_processors(parent="parent_value",) + response = await client.list_processors( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1556,13 +1644,15 @@ async def test_list_processors_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_processors( - document_processor_service.ListProcessorsRequest(), parent="parent_value", + document_processor_service.ListProcessorsRequest(), + parent="parent_value", ) def test_list_processors_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1578,13 +1668,20 @@ def test_list_processors_pager(transport_name: str = "grpc"): next_page_token="abc", ), document_processor_service.ListProcessorsResponse( - processors=[], next_page_token="def", + processors=[], + next_page_token="def", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(),], next_page_token="ghi", + processors=[ + processor.Processor(), + ], + next_page_token="ghi", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(), processor.Processor(),], + processors=[ + processor.Processor(), + processor.Processor(), + ], ), RuntimeError, ) @@ -1597,14 +1694,15 @@ def test_list_processors_pager(transport_name: str = "grpc"): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, processor.Processor) for i in results) def test_list_processors_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1620,13 +1718,20 @@ def test_list_processors_pages(transport_name: str = "grpc"): next_page_token="abc", ), document_processor_service.ListProcessorsResponse( - processors=[], next_page_token="def", + processors=[], + next_page_token="def", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(),], next_page_token="ghi", + processors=[ + processor.Processor(), + ], + next_page_token="ghi", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(), processor.Processor(),], + processors=[ + processor.Processor(), + processor.Processor(), + ], ), RuntimeError, ) @@ -1656,20 +1761,29 @@ async def test_list_processors_async_pager(): next_page_token="abc", ), document_processor_service.ListProcessorsResponse( - processors=[], next_page_token="def", + processors=[], + next_page_token="def", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(),], next_page_token="ghi", + processors=[ + processor.Processor(), + ], + next_page_token="ghi", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(), processor.Processor(),], + processors=[ + processor.Processor(), + processor.Processor(), + ], ), RuntimeError, ) - async_pager = await client.list_processors(request={},) + async_pager = await client.list_processors( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1697,29 +1811,43 @@ async def test_list_processors_async_pages(): next_page_token="abc", ), document_processor_service.ListProcessorsResponse( - processors=[], next_page_token="def", + processors=[], + next_page_token="def", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(),], next_page_token="ghi", + processors=[ + processor.Processor(), + ], + next_page_token="ghi", ), document_processor_service.ListProcessorsResponse( - processors=[processor.Processor(), processor.Processor(),], + processors=[ + processor.Processor(), + processor.Processor(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_processors(request={})).pages: + async for page_ in ( + await client.list_processors(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( - "request_type", [document_processor_service.CreateProcessorRequest, dict,] + "request_type", + [ + document_processor_service.CreateProcessorRequest, + dict, + ], ) def test_create_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1760,7 +1888,8 @@ def test_create_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1777,7 +1906,8 @@ async def test_create_processor_async( request_type=document_processor_service.CreateProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1830,7 +1960,7 @@ def test_create_processor_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.CreateProcessorRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_processor), "__call__") as call: @@ -1844,7 +1974,10 @@ def test_create_processor_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1857,7 +1990,7 @@ async def test_create_processor_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.CreateProcessorRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_processor), "__call__") as call: @@ -1873,7 +2006,10 @@ async def test_create_processor_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_processor_flattened(): @@ -1888,7 +2024,8 @@ def test_create_processor_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_processor( - parent="parent_value", processor=gcd_processor.Processor(name="name_value"), + parent="parent_value", + processor=gcd_processor.Processor(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -1935,7 +2072,8 @@ async def test_create_processor_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_processor( - parent="parent_value", processor=gcd_processor.Processor(name="name_value"), + parent="parent_value", + processor=gcd_processor.Processor(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -1967,11 +2105,16 @@ async def test_create_processor_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [document_processor_service.DeleteProcessorRequest, dict,] + "request_type", + [ + document_processor_service.DeleteProcessorRequest, + dict, + ], ) def test_delete_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1997,7 +2140,8 @@ def test_delete_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2014,7 +2158,8 @@ async def test_delete_processor_async( request_type=document_processor_service.DeleteProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2052,7 +2197,7 @@ def test_delete_processor_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.DeleteProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_processor), "__call__") as call: @@ -2066,7 +2211,10 @@ def test_delete_processor_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2079,7 +2227,7 @@ async def test_delete_processor_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.DeleteProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_processor), "__call__") as call: @@ -2095,7 +2243,10 @@ async def test_delete_processor_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_processor_flattened(): @@ -2109,7 +2260,9 @@ def test_delete_processor_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_processor(name="name_value",) + client.delete_processor( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2129,7 +2282,8 @@ def test_delete_processor_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_processor( - document_processor_service.DeleteProcessorRequest(), name="name_value", + document_processor_service.DeleteProcessorRequest(), + name="name_value", ) @@ -2149,7 +2303,9 @@ async def test_delete_processor_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_processor(name="name_value",) + response = await client.delete_processor( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2170,16 +2326,22 @@ async def test_delete_processor_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_processor( - document_processor_service.DeleteProcessorRequest(), name="name_value", + document_processor_service.DeleteProcessorRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [document_processor_service.EnableProcessorRequest, dict,] + "request_type", + [ + document_processor_service.EnableProcessorRequest, + dict, + ], ) def test_enable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2205,7 +2367,8 @@ def test_enable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2222,7 +2385,8 @@ async def test_enable_processor_async( request_type=document_processor_service.EnableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2260,7 +2424,7 @@ def test_enable_processor_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.EnableProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.enable_processor), "__call__") as call: @@ -2274,7 +2438,10 @@ def test_enable_processor_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2287,7 +2454,7 @@ async def test_enable_processor_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.EnableProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.enable_processor), "__call__") as call: @@ -2303,15 +2470,23 @@ async def test_enable_processor_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.parametrize( - "request_type", [document_processor_service.DisableProcessorRequest, dict,] + "request_type", + [ + document_processor_service.DisableProcessorRequest, + dict, + ], ) def test_disable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2339,7 +2514,8 @@ def test_disable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2358,7 +2534,8 @@ async def test_disable_processor_async( request_type=document_processor_service.DisableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2398,7 +2575,7 @@ def test_disable_processor_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.DisableProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2414,7 +2591,10 @@ def test_disable_processor_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2427,7 +2607,7 @@ async def test_disable_processor_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.DisableProcessorRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2445,15 +2625,23 @@ async def test_disable_processor_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.parametrize( - "request_type", [document_processor_service.ReviewDocumentRequest, dict,] + "request_type", + [ + document_processor_service.ReviewDocumentRequest, + dict, + ], ) def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2479,7 +2667,8 @@ def test_review_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2496,7 +2685,8 @@ async def test_review_document_async( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2534,7 +2724,7 @@ def test_review_document_field_headers(): # a field header. Set these to a non-empty value. request = document_processor_service.ReviewDocumentRequest() - request.human_review_config = "human_review_config/value" + request.human_review_config = "human_review_config_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.review_document), "__call__") as call: @@ -2550,7 +2740,7 @@ def test_review_document_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "human_review_config=human_review_config/value", + "human_review_config=human_review_config_value", ) in kw["metadata"] @@ -2564,7 +2754,7 @@ async def test_review_document_field_headers_async(): # a field header. Set these to a non-empty value. request = document_processor_service.ReviewDocumentRequest() - request.human_review_config = "human_review_config/value" + request.human_review_config = "human_review_config_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.review_document), "__call__") as call: @@ -2582,7 +2772,7 @@ async def test_review_document_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "human_review_config=human_review_config/value", + "human_review_config=human_review_config_value", ) in kw["metadata"] @@ -2597,7 +2787,9 @@ def test_review_document_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.review_document(human_review_config="human_review_config_value",) + client.review_document( + human_review_config="human_review_config_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2673,7 +2865,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -2694,7 +2887,8 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - client_options=options, transport=transport, + client_options=options, + transport=transport, ) # It is an error to provide an api_key and a credential. @@ -2711,7 +2905,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -2754,13 +2949,27 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DocumentProcessorServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( - client.transport, transports.DocumentProcessorServiceGrpcTransport, + client.transport, + transports.DocumentProcessorServiceGrpcTransport, ) @@ -2808,6 +3017,14 @@ def test_document_processor_service_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -2819,7 +3036,8 @@ def test_document_processor_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -2956,24 +3174,40 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( ) -def test_document_processor_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_processor_service_host_no_port(transport_name): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:443" + assert client.transport._host == ("documentai.googleapis.com:443") -def test_document_processor_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_document_processor_service_host_with_port(transport_name): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "documentai.googleapis.com:8000" + assert client.transport._host == ("documentai.googleapis.com:8000") def test_document_processor_service_grpc_transport_channel(): @@ -2981,7 +3215,8 @@ def test_document_processor_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentProcessorServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2993,7 +3228,8 @@ def test_document_processor_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3102,12 +3338,16 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl def test_document_processor_service_grpc_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3115,12 +3355,16 @@ def test_document_processor_service_grpc_lro_client(): def test_document_processor_service_grpc_lro_async_client(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3131,7 +3375,9 @@ def test_human_review_config_path(): location = "clam" processor = "whelk" expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) actual = DocumentProcessorServiceClient.human_review_config_path( project, location, processor @@ -3157,7 +3403,9 @@ def test_processor_path(): location = "mussel" processor = "winkle" expected = "projects/{project}/locations/{location}/processors/{processor}".format( - project=project, location=location, processor=processor, + project=project, + location=location, + processor=processor, ) actual = DocumentProcessorServiceClient.processor_path(project, location, processor) assert expected == actual @@ -3181,7 +3429,9 @@ def test_processor_type_path(): location = "clam" processor_type = "whelk" expected = "projects/{project}/locations/{location}/processorTypes/{processor_type}".format( - project=project, location=location, processor_type=processor_type, + project=project, + location=location, + processor_type=processor_type, ) actual = DocumentProcessorServiceClient.processor_type_path( project, location, processor_type @@ -3224,7 +3474,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DocumentProcessorServiceClient.common_folder_path(folder) assert expected == actual @@ -3242,7 +3494,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DocumentProcessorServiceClient.common_organization_path(organization) assert expected == actual @@ -3260,7 +3514,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DocumentProcessorServiceClient.common_project_path(project) assert expected == actual @@ -3280,7 +3536,8 @@ def test_common_location_path(): project = "whelk" location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DocumentProcessorServiceClient.common_location_path(project, location) assert expected == actual @@ -3305,7 +3562,8 @@ def test_client_with_default_client_info(): transports.DocumentProcessorServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3314,7 +3572,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentProcessorServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3322,7 +3581,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close"
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: