diff --git a/google/cloud/translate_v3/services/translation_service/async_client.py b/google/cloud/translate_v3/services/translation_service/async_client.py index d7a96c9e..834a7e34 100644 --- a/google/cloud/translate_v3/services/translation_service/async_client.py +++ b/google/cloud/translate_v3/services/translation_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.translate_v3.services.translation_service import pagers @@ -167,7 +169,7 @@ def __init__( async def translate_text( self, - request: translation_service.TranslateTextRequest = None, + request: Union[translation_service.TranslateTextRequest, dict] = None, *, parent: str = None, target_language_code: str = None, @@ -175,14 +177,14 @@ async def translate_text( model: str = None, mime_type: str = None, source_language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: r"""Translates input text and returns translated text. Args: - request (:class:`google.cloud.translate_v3.types.TranslateTextRequest`): + request (Union[google.cloud.translate_v3.types.TranslateTextRequest, dict]): The request object. The request message for synchronous translation. parent (:class:`str`): @@ -337,20 +339,20 @@ async def translate_text( async def detect_language( self, - request: translation_service.DetectLanguageRequest = None, + request: Union[translation_service.DetectLanguageRequest, dict] = None, *, parent: str = None, model: str = None, mime_type: str = None, content: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.DetectLanguageResponse: r"""Detects the language of text within a request. Args: - request (:class:`google.cloud.translate_v3.types.DetectLanguageRequest`): + request (Union[google.cloud.translate_v3.types.DetectLanguageRequest, dict]): The request object. The request message for language detection. parent (:class:`str`): @@ -460,12 +462,12 @@ async def detect_language( async def get_supported_languages( self, - request: translation_service.GetSupportedLanguagesRequest = None, + request: Union[translation_service.GetSupportedLanguagesRequest, dict] = None, *, parent: str = None, model: str = None, display_language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.SupportedLanguages: @@ -473,7 +475,7 @@ async def get_supported_languages( translation. Args: - request (:class:`google.cloud.translate_v3.types.GetSupportedLanguagesRequest`): + request (Union[google.cloud.translate_v3.types.GetSupportedLanguagesRequest, dict]): The request object. The request message for discovering supported languages. parent (:class:`str`): @@ -589,16 +591,16 @@ async def get_supported_languages( async def translate_document( self, - request: translation_service.TranslateDocumentRequest = None, + request: Union[translation_service.TranslateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateDocumentResponse: r"""Translates documents in synchronous mode. Args: - request (:class:`google.cloud.translate_v3.types.TranslateDocumentRequest`): + request (Union[google.cloud.translate_v3.types.TranslateDocumentRequest, dict]): The request object. A document translation request. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -637,9 +639,9 @@ async def translate_document( async def batch_translate_text( self, - request: translation_service.BatchTranslateTextRequest = None, + request: Union[translation_service.BatchTranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -654,7 +656,7 @@ async def batch_translate_text( of the call. Args: - request (:class:`google.cloud.translate_v3.types.BatchTranslateTextRequest`): + request (Union[google.cloud.translate_v3.types.BatchTranslateTextRequest, dict]): The request object. The batch translation request. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -705,14 +707,14 @@ async def batch_translate_text( async def batch_translate_document( self, - request: translation_service.BatchTranslateDocumentRequest = None, + request: Union[translation_service.BatchTranslateDocumentRequest, dict] = None, *, parent: str = None, source_language_code: str = None, target_language_codes: Sequence[str] = None, input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, output_config: translation_service.BatchDocumentOutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -727,7 +729,7 @@ async def batch_translate_document( the call. Args: - request (:class:`google.cloud.translate_v3.types.BatchTranslateDocumentRequest`): + request (Union[google.cloud.translate_v3.types.BatchTranslateDocumentRequest, dict]): The request object. The BatchTranslateDocument request. parent (:class:`str`): Required. Location to make a regional call. @@ -865,11 +867,11 @@ async def batch_translate_document( async def create_glossary( self, - request: translation_service.CreateGlossaryRequest = None, + request: Union[translation_service.CreateGlossaryRequest, dict] = None, *, parent: str = None, glossary: translation_service.Glossary = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -877,7 +879,7 @@ async def create_glossary( Returns NOT_FOUND, if the project doesn't exist. Args: - request (:class:`google.cloud.translate_v3.types.CreateGlossaryRequest`): + request (Union[google.cloud.translate_v3.types.CreateGlossaryRequest, dict]): The request object. Request message for CreateGlossary. parent (:class:`str`): Required. The project name. @@ -953,10 +955,10 @@ async def create_glossary( async def list_glossaries( self, - request: translation_service.ListGlossariesRequest = None, + request: Union[translation_service.ListGlossariesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListGlossariesAsyncPager: @@ -964,7 +966,7 @@ async def list_glossaries( doesn't exist. Args: - request (:class:`google.cloud.translate_v3.types.ListGlossariesRequest`): + request (Union[google.cloud.translate_v3.types.ListGlossariesRequest, dict]): The request object. Request message for ListGlossaries. parent (:class:`str`): Required. The name of the project @@ -1043,10 +1045,10 @@ async def list_glossaries( async def get_glossary( self, - request: translation_service.GetGlossaryRequest = None, + request: Union[translation_service.GetGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.Glossary: @@ -1054,7 +1056,7 @@ async def get_glossary( exist. Args: - request (:class:`google.cloud.translate_v3.types.GetGlossaryRequest`): + request (Union[google.cloud.translate_v3.types.GetGlossaryRequest, dict]): The request object. Request message for GetGlossary. name (:class:`str`): Required. The name of the glossary to @@ -1124,10 +1126,10 @@ async def get_glossary( async def delete_glossary( self, - request: translation_service.DeleteGlossaryRequest = None, + request: Union[translation_service.DeleteGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1136,7 +1138,7 @@ async def delete_glossary( doesn't exist. Args: - request (:class:`google.cloud.translate_v3.types.DeleteGlossaryRequest`): + request (Union[google.cloud.translate_v3.types.DeleteGlossaryRequest, dict]): The request object. Request message for DeleteGlossary. name (:class:`str`): Required. The name of the glossary to diff --git a/google/cloud/translate_v3/services/translation_service/client.py b/google/cloud/translate_v3/services/translation_service/client.py index 2562b63a..625b4ea0 100644 --- a/google/cloud/translate_v3/services/translation_service/client.py +++ b/google/cloud/translate_v3/services/translation_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.translate_v3.services.translation_service import pagers @@ -362,7 +364,7 @@ def translate_text( model: str = None, mime_type: str = None, source_language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: @@ -530,7 +532,7 @@ def detect_language( model: str = None, mime_type: str = None, content: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.DetectLanguageResponse: @@ -652,7 +654,7 @@ def get_supported_languages( parent: str = None, model: str = None, display_language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.SupportedLanguages: @@ -768,7 +770,7 @@ def translate_document( self, request: Union[translation_service.TranslateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateDocumentResponse: @@ -817,7 +819,7 @@ def batch_translate_text( self, request: Union[translation_service.BatchTranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -891,7 +893,7 @@ def batch_translate_document( target_language_codes: Sequence[str] = None, input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, output_config: translation_service.BatchDocumentOutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1048,7 +1050,7 @@ def create_glossary( *, parent: str = None, glossary: translation_service.Glossary = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1135,7 +1137,7 @@ def list_glossaries( request: Union[translation_service.ListGlossariesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListGlossariesPager: @@ -1215,7 +1217,7 @@ def get_glossary( request: Union[translation_service.GetGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.Glossary: @@ -1286,7 +1288,7 @@ def delete_glossary( request: Union[translation_service.DeleteGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/translate_v3/services/translation_service/transports/base.py b/google/cloud/translate_v3/services/translation_service/transports/base.py index c4ade0c9..759772df 100644 --- a/google/cloud/translate_v3/services/translation_service/transports/base.py +++ b/google/cloud/translate_v3/services/translation_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -37,15 +36,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class TranslationServiceTransport(abc.ABC): """Abstract transport class for TranslationService.""" @@ -98,7 +88,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -131,29 +121,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -251,7 +218,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/translate_v3/services/translation_service/transports/grpc.py b/google/cloud/translate_v3/services/translation_service/transports/grpc.py index 57e64267..15d9988f 100644 --- a/google/cloud/translate_v3/services/translation_service/transports/grpc.py +++ b/google/cloud/translate_v3/services/translation_service/transports/grpc.py @@ -112,7 +112,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/translate_v3/services/translation_service/transports/grpc_asyncio.py b/google/cloud/translate_v3/services/translation_service/transports/grpc_asyncio.py index b0153f6a..5f418f68 100644 --- a/google/cloud/translate_v3/services/translation_service/transports/grpc_asyncio.py +++ b/google/cloud/translate_v3/services/translation_service/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -159,7 +158,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/translate_v3/types/translation_service.py b/google/cloud/translate_v3/types/translation_service.py index eb582334..4e97c94f 100644 --- a/google/cloud/translate_v3/types/translation_service.py +++ b/google/cloud/translate_v3/types/translation_service.py @@ -236,6 +236,8 @@ class Translation(proto.Message): class DetectLanguageRequest(proto.Message): r"""The request message for language detection. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. Project or location to make a call. Must refer to @@ -264,6 +266,8 @@ class DetectLanguageRequest(proto.Message): If not specified, the default model is used. content (str): The content of the input stored as a string. + + This field is a member of `oneof`_ ``source``. mime_type (str): Optional. The format of the source text, for example, "text/html", "text/plain". If left @@ -424,6 +428,8 @@ class GcsSource(proto.Message): class InputConfig(proto.Message): r"""Input configuration for BatchTranslateText request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: mime_type (str): Optional. Can be "text/plain" or "text/html". For ``.tsv``, @@ -450,6 +456,8 @@ class InputConfig(proto.Message): The other supported file extensions are ``.txt`` or ``.html``, which is treated as a single large chunk of text. + + This field is a member of `oneof`_ ``source``. """ mime_type = proto.Field(proto.STRING, number=1,) @@ -477,6 +485,8 @@ class GcsDestination(proto.Message): class OutputConfig(proto.Message): r"""Output configuration for BatchTranslateText request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3.types.GcsDestination): Google Cloud Storage destination for output content. For @@ -555,6 +565,7 @@ class OutputConfig(proto.Message): glossary_error_file will be generated that contains error details. glossary_error_file has format of gs://translation_test/a_b_c\_'trg'_glossary_errors.[extension] + This field is a member of `oneof`_ ``destination``. """ gcs_destination = proto.Field( @@ -565,13 +576,23 @@ class OutputConfig(proto.Message): class DocumentInputConfig(proto.Message): r"""A document translation request input config. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: content (bytes): Document's content represented as a stream of bytes. + + This field is a member of `oneof`_ ``source``. gcs_source (google.cloud.translate_v3.types.GcsSource): Google Cloud Storage location. This must be a single file. For example: gs://example_bucket/example_file.pdf + This field is a member of `oneof`_ ``source``. mime_type (str): Specifies the input document's mime_type. @@ -596,6 +617,8 @@ class DocumentInputConfig(proto.Message): class DocumentOutputConfig(proto.Message): r"""A document translation request output config. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3.types.GcsDestination): Optional. Google Cloud Storage destination for the @@ -647,6 +670,8 @@ class DocumentOutputConfig(proto.Message): Callers should expect no partial outputs. If there is any error during document translation, no output will be stored in the Cloud Storage bucket. + + This field is a member of `oneof`_ ``destination``. mime_type (str): Optional. Specifies the translated document's mime_type. If not specified, the translated file's mime type will be the @@ -968,6 +993,8 @@ class BatchTranslateResponse(proto.Message): class GlossaryInputConfig(proto.Message): r"""Input configuration for glossaries. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.translate_v3.types.GcsSource): Required. Google Cloud Storage location of glossary data. @@ -994,6 +1021,8 @@ class GlossaryInputConfig(proto.Message): glossary terms in multiple languages. See documentation for more information - `glossaries `__. + + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -1004,6 +1033,13 @@ class GlossaryInputConfig(proto.Message): class Glossary(proto.Message): r"""Represents a glossary built from user provided data. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The resource name of the glossary. Glossary names @@ -1011,8 +1047,12 @@ class Glossary(proto.Message): ``projects/{project-number-or-id}/locations/{location-id}/glossaries/{glossary-id}``. language_pair (google.cloud.translate_v3.types.Glossary.LanguageCodePair): Used with unidirectional glossaries. + + This field is a member of `oneof`_ ``languages``. language_codes_set (google.cloud.translate_v3.types.Glossary.LanguageCodesSet): Used with equivalent term set glossaries. + + This field is a member of `oneof`_ ``languages``. input_config (google.cloud.translate_v3.types.GlossaryInputConfig): Required. Provides examples to build the glossary from. Total glossary must not exceed @@ -1356,6 +1396,8 @@ class BatchTranslateDocumentRequest(proto.Message): class BatchDocumentInputConfig(proto.Message): r"""Input configuration for BatchTranslateDocument request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.translate_v3.types.GcsSource): Google Cloud Storage location for the source input. This can @@ -1378,6 +1420,8 @@ class BatchDocumentInputConfig(proto.Message): ``.xlsx`` is 100MB. The max file size to support for ``.pdf`` is 1GB and the max page limit is 1000 pages. The max file size to support for all input documents is 1GB. + + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -1388,6 +1432,8 @@ class BatchDocumentInputConfig(proto.Message): class BatchDocumentOutputConfig(proto.Message): r"""Output configuration for BatchTranslateDocument request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3.types.GcsDestination): Google Cloud Storage destination for output content. For @@ -1442,6 +1488,8 @@ class BatchDocumentOutputConfig(proto.Message): ``glossary_error_output``: gs://translation_test/a_b_c*\ [trg]_glossary_translation.txt The error output is a txt file containing error details. + + This field is a member of `oneof`_ ``destination``. """ gcs_destination = proto.Field( diff --git a/google/cloud/translate_v3beta1/services/translation_service/async_client.py b/google/cloud/translate_v3beta1/services/translation_service/async_client.py index 95f27964..dcd1cc69 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/async_client.py +++ b/google/cloud/translate_v3beta1/services/translation_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.translate_v3beta1.services.translation_service import pagers @@ -167,16 +169,16 @@ def __init__( async def translate_text( self, - request: translation_service.TranslateTextRequest = None, + request: Union[translation_service.TranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: r"""Translates input text and returns translated text. Args: - request (:class:`google.cloud.translate_v3beta1.types.TranslateTextRequest`): + request (Union[google.cloud.translate_v3beta1.types.TranslateTextRequest, dict]): The request object. The request message for synchronous translation. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -214,19 +216,19 @@ async def translate_text( async def detect_language( self, - request: translation_service.DetectLanguageRequest = None, + request: Union[translation_service.DetectLanguageRequest, dict] = None, *, parent: str = None, model: str = None, mime_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.DetectLanguageResponse: r"""Detects the language of text within a request. Args: - request (:class:`google.cloud.translate_v3beta1.types.DetectLanguageRequest`): + request (Union[google.cloud.translate_v3beta1.types.DetectLanguageRequest, dict]): The request object. The request message for language detection. parent (:class:`str`): @@ -327,12 +329,12 @@ async def detect_language( async def get_supported_languages( self, - request: translation_service.GetSupportedLanguagesRequest = None, + request: Union[translation_service.GetSupportedLanguagesRequest, dict] = None, *, parent: str = None, display_language_code: str = None, model: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.SupportedLanguages: @@ -340,7 +342,7 @@ async def get_supported_languages( translation. Args: - request (:class:`google.cloud.translate_v3beta1.types.GetSupportedLanguagesRequest`): + request (Union[google.cloud.translate_v3beta1.types.GetSupportedLanguagesRequest, dict]): The request object. The request message for discovering supported languages. parent (:class:`str`): @@ -456,16 +458,16 @@ async def get_supported_languages( async def translate_document( self, - request: translation_service.TranslateDocumentRequest = None, + request: Union[translation_service.TranslateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateDocumentResponse: r"""Translates documents in synchronous mode. Args: - request (:class:`google.cloud.translate_v3beta1.types.TranslateDocumentRequest`): + request (Union[google.cloud.translate_v3beta1.types.TranslateDocumentRequest, dict]): The request object. A document translation request. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -504,9 +506,9 @@ async def translate_document( async def batch_translate_text( self, - request: translation_service.BatchTranslateTextRequest = None, + request: Union[translation_service.BatchTranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -521,7 +523,7 @@ async def batch_translate_text( of the call. Args: - request (:class:`google.cloud.translate_v3beta1.types.BatchTranslateTextRequest`): + request (Union[google.cloud.translate_v3beta1.types.BatchTranslateTextRequest, dict]): The request object. The batch translation request. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -572,14 +574,14 @@ async def batch_translate_text( async def batch_translate_document( self, - request: translation_service.BatchTranslateDocumentRequest = None, + request: Union[translation_service.BatchTranslateDocumentRequest, dict] = None, *, parent: str = None, source_language_code: str = None, target_language_codes: Sequence[str] = None, input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, output_config: translation_service.BatchDocumentOutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -594,7 +596,7 @@ async def batch_translate_document( the call. Args: - request (:class:`google.cloud.translate_v3beta1.types.BatchTranslateDocumentRequest`): + request (Union[google.cloud.translate_v3beta1.types.BatchTranslateDocumentRequest, dict]): The request object. The BatchTranslateDocument request. parent (:class:`str`): Required. Location to make a regional call. @@ -732,11 +734,11 @@ async def batch_translate_document( async def create_glossary( self, - request: translation_service.CreateGlossaryRequest = None, + request: Union[translation_service.CreateGlossaryRequest, dict] = None, *, parent: str = None, glossary: translation_service.Glossary = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -744,7 +746,7 @@ async def create_glossary( Returns NOT_FOUND, if the project doesn't exist. Args: - request (:class:`google.cloud.translate_v3beta1.types.CreateGlossaryRequest`): + request (Union[google.cloud.translate_v3beta1.types.CreateGlossaryRequest, dict]): The request object. Request message for CreateGlossary. parent (:class:`str`): Required. The project name. @@ -820,11 +822,11 @@ async def create_glossary( async def list_glossaries( self, - request: translation_service.ListGlossariesRequest = None, + request: Union[translation_service.ListGlossariesRequest, dict] = None, *, parent: str = None, filter: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListGlossariesAsyncPager: @@ -832,7 +834,7 @@ async def list_glossaries( doesn't exist. Args: - request (:class:`google.cloud.translate_v3beta1.types.ListGlossariesRequest`): + request (Union[google.cloud.translate_v3beta1.types.ListGlossariesRequest, dict]): The request object. Request message for ListGlossaries. parent (:class:`str`): Required. The name of the project @@ -947,10 +949,10 @@ async def list_glossaries( async def get_glossary( self, - request: translation_service.GetGlossaryRequest = None, + request: Union[translation_service.GetGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.Glossary: @@ -958,7 +960,7 @@ async def get_glossary( exist. Args: - request (:class:`google.cloud.translate_v3beta1.types.GetGlossaryRequest`): + request (Union[google.cloud.translate_v3beta1.types.GetGlossaryRequest, dict]): The request object. Request message for GetGlossary. name (:class:`str`): Required. The name of the glossary to @@ -1028,10 +1030,10 @@ async def get_glossary( async def delete_glossary( self, - request: translation_service.DeleteGlossaryRequest = None, + request: Union[translation_service.DeleteGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1040,7 +1042,7 @@ async def delete_glossary( doesn't exist. Args: - request (:class:`google.cloud.translate_v3beta1.types.DeleteGlossaryRequest`): + request (Union[google.cloud.translate_v3beta1.types.DeleteGlossaryRequest, dict]): The request object. Request message for DeleteGlossary. name (:class:`str`): Required. The name of the glossary to diff --git a/google/cloud/translate_v3beta1/services/translation_service/client.py b/google/cloud/translate_v3beta1/services/translation_service/client.py index 0fc5bb4e..fd17473e 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/client.py +++ b/google/cloud/translate_v3beta1/services/translation_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.translate_v3beta1.services.translation_service import pagers @@ -356,7 +358,7 @@ def translate_text( self, request: Union[translation_service.TranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: @@ -407,7 +409,7 @@ def detect_language( parent: str = None, model: str = None, mime_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.DetectLanguageResponse: @@ -520,7 +522,7 @@ def get_supported_languages( parent: str = None, display_language_code: str = None, model: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.SupportedLanguages: @@ -636,7 +638,7 @@ def translate_document( self, request: Union[translation_service.TranslateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateDocumentResponse: @@ -685,7 +687,7 @@ def batch_translate_text( self, request: Union[translation_service.BatchTranslateTextRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -759,7 +761,7 @@ def batch_translate_document( target_language_codes: Sequence[str] = None, input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, output_config: translation_service.BatchDocumentOutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -916,7 +918,7 @@ def create_glossary( *, parent: str = None, glossary: translation_service.Glossary = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1004,7 +1006,7 @@ def list_glossaries( *, parent: str = None, filter: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListGlossariesPager: @@ -1120,7 +1122,7 @@ def get_glossary( request: Union[translation_service.GetGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.Glossary: @@ -1191,7 +1193,7 @@ def delete_glossary( request: Union[translation_service.DeleteGlossaryRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/translate_v3beta1/services/translation_service/transports/base.py b/google/cloud/translate_v3beta1/services/translation_service/transports/base.py index b52d6efb..60c51f39 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/transports/base.py +++ b/google/cloud/translate_v3beta1/services/translation_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -37,15 +36,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class TranslationServiceTransport(abc.ABC): """Abstract transport class for TranslationService.""" @@ -98,7 +88,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -131,29 +121,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -251,7 +218,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/translate_v3beta1/services/translation_service/transports/grpc.py b/google/cloud/translate_v3beta1/services/translation_service/transports/grpc.py index 7149d6c1..f1c5b4bf 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/transports/grpc.py +++ b/google/cloud/translate_v3beta1/services/translation_service/transports/grpc.py @@ -112,7 +112,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/translate_v3beta1/services/translation_service/transports/grpc_asyncio.py b/google/cloud/translate_v3beta1/services/translation_service/transports/grpc_asyncio.py index dd50985a..b5b4feb9 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/transports/grpc_asyncio.py +++ b/google/cloud/translate_v3beta1/services/translation_service/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -159,7 +158,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/translate_v3beta1/types/translation_service.py b/google/cloud/translate_v3beta1/types/translation_service.py index 4ef2cee5..272b82a6 100644 --- a/google/cloud/translate_v3beta1/types/translation_service.py +++ b/google/cloud/translate_v3beta1/types/translation_service.py @@ -230,6 +230,8 @@ class Translation(proto.Message): class DetectLanguageRequest(proto.Message): r"""The request message for language detection. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. Project or location to make a call. Must refer to @@ -258,6 +260,8 @@ class DetectLanguageRequest(proto.Message): If not specified, the default model is used. content (str): The content of the input stored as a string. + + This field is a member of `oneof`_ ``source``. mime_type (str): Optional. The format of the source text, for example, "text/html", "text/plain". If left @@ -417,6 +421,8 @@ class GcsSource(proto.Message): class InputConfig(proto.Message): r"""Input configuration for BatchTranslateText request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: mime_type (str): Optional. Can be "text/plain" or "text/html". For ``.tsv``, @@ -443,6 +449,8 @@ class InputConfig(proto.Message): The other supported file extensions are ``.txt`` or ``.html``, which is treated as a single large chunk of text. + + This field is a member of `oneof`_ ``source``. """ mime_type = proto.Field(proto.STRING, number=1,) @@ -468,6 +476,8 @@ class GcsDestination(proto.Message): class OutputConfig(proto.Message): r"""Output configuration for BatchTranslateText request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3beta1.types.GcsDestination): Google Cloud Storage destination for output content. For @@ -546,6 +556,7 @@ class OutputConfig(proto.Message): glossary_error_file will be generated that contains error details. glossary_error_file has format of gs://translation_test/a_b_c\_'trg'_glossary_errors.[extension] + This field is a member of `oneof`_ ``destination``. """ gcs_destination = proto.Field( @@ -556,13 +567,23 @@ class OutputConfig(proto.Message): class DocumentInputConfig(proto.Message): r"""A document translation request input config. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: content (bytes): Document's content represented as a stream of bytes. + + This field is a member of `oneof`_ ``source``. gcs_source (google.cloud.translate_v3beta1.types.GcsSource): Google Cloud Storage location. This must be a single file. For example: gs://example_bucket/example_file.pdf + This field is a member of `oneof`_ ``source``. mime_type (str): Specifies the input document's mime_type. @@ -587,6 +608,8 @@ class DocumentInputConfig(proto.Message): class DocumentOutputConfig(proto.Message): r"""A document translation request output config. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3beta1.types.GcsDestination): Optional. Google Cloud Storage destination for the @@ -638,6 +661,8 @@ class DocumentOutputConfig(proto.Message): Callers should expect no partial outputs. If there is any error during document translation, no output will be stored in the Cloud Storage bucket. + + This field is a member of `oneof`_ ``destination``. mime_type (str): Optional. Specifies the translated document's mime_type. If not specified, the translated file's mime type will be the @@ -958,6 +983,8 @@ class BatchTranslateResponse(proto.Message): class GlossaryInputConfig(proto.Message): r"""Input configuration for glossaries. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.translate_v3beta1.types.GcsSource): Required. Google Cloud Storage location of glossary data. @@ -985,6 +1012,8 @@ class GlossaryInputConfig(proto.Message): defined for Google Translation Toolkit and documented in `Use a glossary `__. + + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -995,6 +1024,13 @@ class GlossaryInputConfig(proto.Message): class Glossary(proto.Message): r"""Represents a glossary built from user provided data. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The resource name of the glossary. Glossary names @@ -1002,8 +1038,12 @@ class Glossary(proto.Message): ``projects/{project-number-or-id}/locations/{location-id}/glossaries/{glossary-id}``. language_pair (google.cloud.translate_v3beta1.types.Glossary.LanguageCodePair): Used with unidirectional glossaries. + + This field is a member of `oneof`_ ``languages``. language_codes_set (google.cloud.translate_v3beta1.types.Glossary.LanguageCodesSet): Used with equivalent term set glossaries. + + This field is a member of `oneof`_ ``languages``. input_config (google.cloud.translate_v3beta1.types.GlossaryInputConfig): Required. Provides examples to build the glossary from. Total glossary must not exceed @@ -1347,6 +1387,8 @@ class BatchTranslateDocumentRequest(proto.Message): class BatchDocumentInputConfig(proto.Message): r"""Input configuration for BatchTranslateDocument request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.translate_v3beta1.types.GcsSource): Google Cloud Storage location for the source input. This can @@ -1369,6 +1411,8 @@ class BatchDocumentInputConfig(proto.Message): ``.xlsx`` is 100MB. The max file size to support for ``.pdf`` is 1GB and the max page limit is 1000 pages. The max file size to support for all input documents is 1GB. + + This field is a member of `oneof`_ ``source``. """ gcs_source = proto.Field( @@ -1379,6 +1423,8 @@ class BatchDocumentInputConfig(proto.Message): class BatchDocumentOutputConfig(proto.Message): r"""Output configuration for BatchTranslateDocument request. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.translate_v3beta1.types.GcsDestination): Google Cloud Storage destination for output content. For @@ -1433,6 +1479,8 @@ class BatchDocumentOutputConfig(proto.Message): ``glossary_error_output``: gs://translation_test/a_b_c*\ [trg]_glossary_translation.txt The error output is a txt file containing error details. + + This field is a member of `oneof`_ ``destination``. """ gcs_destination = proto.Field( diff --git a/owlbot.py b/owlbot.py index 6282d06d..d960cf99 100644 --- a/owlbot.py +++ b/owlbot.py @@ -45,6 +45,17 @@ s.remove_staging_dirs() +# work around gapic generator bug +# https://github.com/googleapis/gapic-generator-python/pull/1071 +s.replace( + "google/cloud/**/types/*.py", + """\. + This field is a member of `oneof`_""", + """. + + This field is a member of `oneof`_""" +) + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- diff --git a/setup.py b/setup.py index 58b66d70..b0830447 100644 --- a/setup.py +++ b/setup.py @@ -32,13 +32,12 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-cloud-core >= 1.3.0, <3.0.0dev", "proto-plus >= 0.4.0", - "packaging >= 14.3", ] extras = {} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 1e4834ec..8f3e79a6 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,8 +5,6 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 google-cloud-core==1.3.0 proto-plus==0.4.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-api-core diff --git a/tests/unit/gapic/translate_v3/test_translation_service.py b/tests/unit/gapic/translate_v3/test_translation_service.py index 8b514890..0130b68c 100644 --- a/tests/unit/gapic/translate_v3/test_translation_service.py +++ b/tests/unit/gapic/translate_v3/test_translation_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,9 +42,6 @@ ) from google.cloud.translate_v3.services.translation_service import pagers from google.cloud.translate_v3.services.translation_service import transports -from google.cloud.translate_v3.services.translation_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.translate_v3.types import translation_service from google.longrunning import operations_pb2 from google.oauth2 import service_account @@ -53,20 +49,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -224,7 +206,7 @@ def test_translation_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -241,7 +223,7 @@ def test_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,7 +240,7 @@ def test_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -287,7 +269,7 @@ def test_translation_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -356,7 +338,7 @@ def test_translation_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -398,7 +380,7 @@ def test_translation_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,7 +402,7 @@ def test_translation_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -451,7 +433,7 @@ def test_translation_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -482,7 +464,7 @@ def test_translation_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -2971,7 +2953,6 @@ def test_translation_service_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_translation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2995,29 +2976,6 @@ def test_translation_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_translation_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.translate_v3.services.translation_service.transports.TranslationServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TranslationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id="octopus", - ) - - def test_translation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3029,7 +2987,6 @@ def test_translation_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_translation_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3045,21 +3002,6 @@ def test_translation_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_translation_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - TranslationServiceClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3067,7 +3009,6 @@ def test_translation_service_auth_adc_old_google_auth(): transports.TranslationServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_translation_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3084,29 +3025,6 @@ def test_translation_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.TranslationServiceGrpcTransport, - transports.TranslationServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_translation_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/translate_v3beta1/test_translation_service.py b/tests/unit/gapic/translate_v3beta1/test_translation_service.py index 1be623ab..7f70bd91 100644 --- a/tests/unit/gapic/translate_v3beta1/test_translation_service.py +++ b/tests/unit/gapic/translate_v3beta1/test_translation_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,9 +42,6 @@ ) from google.cloud.translate_v3beta1.services.translation_service import pagers from google.cloud.translate_v3beta1.services.translation_service import transports -from google.cloud.translate_v3beta1.services.translation_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.translate_v3beta1.types import translation_service from google.longrunning import operations_pb2 from google.oauth2 import service_account @@ -53,20 +49,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -224,7 +206,7 @@ def test_translation_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -241,7 +223,7 @@ def test_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,7 +240,7 @@ def test_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -287,7 +269,7 @@ def test_translation_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -356,7 +338,7 @@ def test_translation_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -398,7 +380,7 @@ def test_translation_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,7 +402,7 @@ def test_translation_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -451,7 +433,7 @@ def test_translation_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -482,7 +464,7 @@ def test_translation_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -2863,7 +2845,6 @@ def test_translation_service_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_translation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2887,29 +2868,6 @@ def test_translation_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_translation_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.translate_v3beta1.services.translation_service.transports.TranslationServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TranslationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id="octopus", - ) - - def test_translation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2921,7 +2879,6 @@ def test_translation_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_translation_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2937,21 +2894,6 @@ def test_translation_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_translation_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - TranslationServiceClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2959,7 +2901,6 @@ def test_translation_service_auth_adc_old_google_auth(): transports.TranslationServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_translation_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2976,29 +2917,6 @@ def test_translation_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.TranslationServiceGrpcTransport, - transports.TranslationServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_translation_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/cloud-translation", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [