Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add from_service_account_info factory and fix sphinx identifiers (
#80)

feat: add 'from_service_account_info' factory to clients
fix: fix sphinx identifiers
PiperOrigin-RevId: 350246057

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Jan 5 16:44:11 2021 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 520682435235d9c503983a360a2090025aa47cd1
Source-Link: googleapis/googleapis@5206824
  • Loading branch information
yoshi-automation committed Jan 6, 2021
1 parent 33dc258 commit d6f183a
Show file tree
Hide file tree
Showing 20 changed files with 319 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Expand Up @@ -15,4 +15,4 @@ exclude_lines =
# This is added at the module level as a safeguard for if someone
# generates the code and tries to run it without pip installing. This
# makes it virtually impossible to test properly.
except pkg_resources.DistributionNotFound
except pkg_resources.DistributionNotFound
6 changes: 6 additions & 0 deletions docs/documentai_v1beta2/document_understanding_service.rst
@@ -0,0 +1,6 @@
DocumentUnderstandingService
----------------------------------------------

.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service
:members:
:inherited-members:
6 changes: 3 additions & 3 deletions docs/documentai_v1beta2/services.rst
@@ -1,6 +1,6 @@
Services for Google Cloud Documentai v1beta2 API
================================================
.. toctree::
:maxdepth: 2

.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service
:members:
:inherited-members:
document_understanding_service
1 change: 1 addition & 0 deletions docs/documentai_v1beta2/types.rst
Expand Up @@ -3,4 +3,5 @@ Types for Google Cloud Documentai v1beta2 API

.. automodule:: google.cloud.documentai_v1beta2.types
:members:
:undoc-members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/documentai_v1beta3/document_processor_service.rst
@@ -0,0 +1,6 @@
DocumentProcessorService
------------------------------------------

.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service
:members:
:inherited-members:
6 changes: 3 additions & 3 deletions docs/documentai_v1beta3/services.rst
@@ -1,6 +1,6 @@
Services for Google Cloud Documentai v1beta3 API
================================================
.. toctree::
:maxdepth: 2

.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service
:members:
:inherited-members:
document_processor_service
1 change: 1 addition & 0 deletions docs/documentai_v1beta3/types.rst
Expand Up @@ -3,4 +3,5 @@ Types for Google Cloud Documentai v1beta3 API

.. automodule:: google.cloud.documentai_v1beta3.types
:members:
:undoc-members:
:show-inheritance:
Expand Up @@ -85,6 +85,9 @@ class DocumentUnderstandingServiceAsyncClient:
DocumentUnderstandingServiceClient.parse_common_location_path
)

from_service_account_info = (
DocumentUnderstandingServiceClient.from_service_account_info
)
from_service_account_file = (
DocumentUnderstandingServiceClient.from_service_account_file
)
Expand Down Expand Up @@ -165,13 +168,14 @@ async def batch_process_documents(
written to Cloud Storage as JSON in the [Document] format.
Args:
request (:class:`~.document_understanding.BatchProcessDocumentsRequest`):
request (:class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest`):
The request object. Request to batch process documents
as an asynchronous operation. The output is written to
Cloud Storage as JSON in the [Document] format.
requests (:class:`Sequence[~.document_understanding.ProcessDocumentRequest]`):
requests (:class:`Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]`):
Required. Individual requests for
each document.
This corresponds to the ``requests`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
Expand All @@ -183,14 +187,11 @@ async def batch_process_documents(
sent along with the request as metadata.
Returns:
~.operation_async.AsyncOperation:
google.api_core.operation_async.AsyncOperation:
An object representing a long-running operation.
The result type for the operation will be
:class:``~.document_understanding.BatchProcessDocumentsResponse``:
Response to an batch document processing request. This
is returned in the LRO Operation after the operation is
complete.
The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in
the LRO Operation after the operation is complete.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -258,7 +259,7 @@ async def process_document(
r"""Processes a single document.
Args:
request (:class:`~.document_understanding.ProcessDocumentRequest`):
request (:class:`google.cloud.documentai_v1beta2.types.ProcessDocumentRequest`):
The request object. Request to process one document.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
Expand All @@ -268,7 +269,7 @@ async def process_document(
sent along with the request as metadata.
Returns:
~.document.Document:
google.cloud.documentai_v1beta2.types.Document:
Document represents the canonical
document resource in Document
Understanding AI. It is an interchange
Expand Down
Expand Up @@ -122,6 +122,22 @@ def _get_default_mtls_endpoint(api_endpoint):
DEFAULT_ENDPOINT
)

@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials info.
Args:
info (dict): The service account private key info.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
DocumentUnderstandingServiceClient: The constructed client.
"""
credentials = service_account.Credentials.from_service_account_info(info)
kwargs["credentials"] = credentials
return cls(*args, **kwargs)

@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
Expand All @@ -134,7 +150,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
kwargs: Additional arguments to pass to the constructor.
Returns:
{@api.name}: The constructed client.
DocumentUnderstandingServiceClient: The constructed client.
"""
credentials = service_account.Credentials.from_service_account_file(filename)
kwargs["credentials"] = credentials
Expand Down Expand Up @@ -226,10 +242,10 @@ def __init__(
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
transport (Union[str, ~.DocumentUnderstandingServiceTransport]): The
transport (Union[str, DocumentUnderstandingServiceTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
client_options (client_options_lib.ClientOptions): Custom options for the
client_options (google.api_core.client_options.ClientOptions): Custom options for the
client. It won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
Expand Down Expand Up @@ -340,13 +356,14 @@ def batch_process_documents(
written to Cloud Storage as JSON in the [Document] format.
Args:
request (:class:`~.document_understanding.BatchProcessDocumentsRequest`):
request (google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest):
The request object. Request to batch process documents
as an asynchronous operation. The output is written to
Cloud Storage as JSON in the [Document] format.
requests (:class:`Sequence[~.document_understanding.ProcessDocumentRequest]`):
requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]):
Required. Individual requests for
each document.
This corresponds to the ``requests`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
Expand All @@ -358,14 +375,11 @@ def batch_process_documents(
sent along with the request as metadata.
Returns:
~.operation.Operation:
google.api_core.operation.Operation:
An object representing a long-running operation.
The result type for the operation will be
:class:``~.document_understanding.BatchProcessDocumentsResponse``:
Response to an batch document processing request. This
is returned in the LRO Operation after the operation is
complete.
The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in
the LRO Operation after the operation is complete.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -426,7 +440,7 @@ def process_document(
r"""Processes a single document.
Args:
request (:class:`~.document_understanding.ProcessDocumentRequest`):
request (google.cloud.documentai_v1beta2.types.ProcessDocumentRequest):
The request object. Request to process one document.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
Expand All @@ -436,7 +450,7 @@ def process_document(
sent along with the request as metadata.
Returns:
~.document.Document:
google.cloud.documentai_v1beta2.types.Document:
Document represents the canonical
document resource in Document
Understanding AI. It is an interchange
Expand Down

0 comments on commit d6f183a

Please sign in to comment.