Skip to content

Commit f24a2a6

Browse files
[translation] release prep (Azure#19139)
* fix type hint * run black formatting * docs sweep * update changelog date * update date again
1 parent 2df1266 commit f24a2a6

16 files changed

+421
-293
lines changed

sdk/translation/azure-ai-translation-document/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 1.0.0b2 (Unreleased)
3+
## 1.0.0b2 (2021-06-08)
44

55
This version of the SDK defaults to the latest supported service version, which currently is v1.0
66

sdk/translation/azure-ai-translation-document/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ The client provides operations for:
137137

138138
### Translation Input
139139

140-
To begin translating your documents, pass a list of `DocumentTranslationInput` into the `begin_translation` client method.
141-
Constructing a `DocumentTranslationInput` requires that you pass the SAS URLs to your source and target containers (or files)
142-
and the target language(s) for translation.
140+
Input to the `begin_translation` client method can be provided in two different ways:
143141

144-
A single source container with documents can be translated to a different language:
142+
1) A single source container with documents can be translated to a different language:
145143

146144
```python
147145
from azure.core.credentials import AzureKeyCredential
@@ -151,7 +149,7 @@ document_translation_client = DocumentTranslationClient("<endpoint>", AzureKeyCr
151149
poller = document_translation_client.begin_translation("<sas_url_to_source>", "<sas_url_to_target>", "<target_language_code>")
152150
```
153151

154-
Or multiple different sources can be provided each with their own targets.
152+
2) Or multiple different sources can be provided each with their own targets.
155153

156154
```python
157155
from azure.core.credentials import AzureKeyCredential
@@ -240,7 +238,7 @@ for document in result:
240238
if document.status == "Succeeded":
241239
print("Source document location: {}".format(document.source_document_url))
242240
print("Translated document location: {}".format(document.translated_document_url))
243-
print("Translated to language: {}\n".format(document.translate_to))
241+
print("Translated to language: {}\n".format(document.translated_to))
244242
else:
245243
print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message))
246244
```
@@ -308,7 +306,7 @@ document_translation_client = DocumentTranslationClient(endpoint, credential)
308306
operations = document_translation_client.list_all_translation_statuses() # type: ItemPaged[TranslationStatusResult]
309307

310308
for operation in operations:
311-
print("ID: {}".format(operation.id))
309+
print("\nID: {}".format(operation.id))
312310
print("Status: {}".format(operation.status))
313311
print("Created on: {}".format(operation.created_on))
314312
print("Last updated on: {}".format(operation.last_updated_on))

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
DocumentTranslationError,
1919
TranslationGlossary,
2020
DocumentTranslationInput,
21-
FileFormat
21+
FileFormat,
2222
)
2323

2424
__VERSION__ = VERSION
@@ -35,5 +35,5 @@
3535
"TranslationStatusResult",
3636
"DocumentStatusResult",
3737
"DocumentTranslationError",
38-
"DocumentTranslationLROPoller"
38+
"DocumentTranslationLROPoller",
3939
]

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_api_version.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ def validate_api_version(api_version):
2424
except ValueError:
2525
raise ValueError(
2626
"Unsupported API version '{}'. Please select from:\n{}".format(
27-
api_version, ", ".join(v.value for v in DocumentTranslationApiVersion))
27+
api_version, ", ".join(v.value for v in DocumentTranslationApiVersion)
28+
)
2829
)

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import json
88
from typing import Any, TYPE_CHECKING, List, Union, overload
99
from azure.core.tracing.decorator import distributed_trace
10-
from ._generated import BatchDocumentTranslationClient as _BatchDocumentTranslationClient
10+
from ._generated import (
11+
BatchDocumentTranslationClient as _BatchDocumentTranslationClient,
12+
)
1113
from ._models import (
1214
TranslationStatusResult,
1315
DocumentStatusResult,
1416
DocumentTranslationInput,
15-
FileFormat
17+
FileFormat,
1618
)
1719
from ._user_agent import USER_AGENT
1820
from ._polling import TranslationPolling, DocumentTranslationLROPollingMethod
@@ -21,16 +23,16 @@
2123
convert_datetime,
2224
get_authentication_policy,
2325
get_translation_input,
24-
POLLING_INTERVAL
26+
POLLING_INTERVAL,
2527
)
28+
2629
if TYPE_CHECKING:
2730
from azure.core.paging import ItemPaged
2831
from azure.core.credentials import TokenCredential, AzureKeyCredential
2932
from ._polling import DocumentTranslationLROPoller
3033

3134

3235
class DocumentTranslationClient(object): # pylint: disable=r0205
33-
3436
def __init__(self, endpoint, credential, **kwargs):
3537
# type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None
3638
"""DocumentTranslationClient is your interface to the Document Translation service.
@@ -67,7 +69,7 @@ def __init__(self, endpoint, credential, **kwargs):
6769
"""
6870
self._endpoint = endpoint
6971
self._credential = credential
70-
self._api_version = kwargs.pop('api_version', None)
72+
self._api_version = kwargs.pop("api_version", None)
7173

7274
authentication_policy = get_authentication_policy(credential)
7375
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
@@ -98,19 +100,22 @@ def close(self):
98100

99101
@overload
100102
def begin_translation(self, source_url, target_url, target_language_code, **kwargs):
101-
# type: (str, str, str, **Any) -> DocumentTranslationPoller[ItemPaged[DocumentStatusResult]]
103+
# type: (str, str, str, **Any) -> DocumentTranslationLROPoller[ItemPaged[DocumentStatusResult]]
102104
pass
103105

104106
@overload
105107
def begin_translation(self, inputs, **kwargs):
106108
# type: (List[DocumentTranslationInput], **Any) -> DocumentTranslationLROPoller[ItemPaged[DocumentStatusResult]]
107109
pass
108110

109-
def begin_translation(self, *args, **kwargs): # pylint: disable=client-method-missing-type-annotations
111+
def begin_translation(
112+
self, *args, **kwargs
113+
): # pylint: disable=client-method-missing-type-annotations
110114
"""Begin translating the document(s) in your source container to your target container
111115
in the given language. To perform a single translation from source to target, pass the `source_url`,
112116
`target_url`, and `target_language_code` parameters. To pass multiple inputs for translation, including
113-
other translation options, pass the `inputs` parameter as a list of DocumentTranslationInput.
117+
other translation options, pass the `inputs` parameter as a list of
118+
:class:`~azure.ai.translation.document.DocumentTranslationInput`.
114119
115120
For supported languages and document formats, see the service documentation:
116121
https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview
@@ -153,7 +158,8 @@ def deserialization_callback(
153158
return self.list_all_document_statuses(translation_status["id"])
154159

155160
polling_interval = kwargs.pop(
156-
"polling_interval", self._client._config.polling_interval # pylint: disable=protected-access
161+
"polling_interval",
162+
self._client._config.polling_interval, # pylint: disable=protected-access
157163
)
158164

159165
pipeline_response = None
@@ -168,11 +174,10 @@ def deserialization_callback(
168174
inputs=inputs if not continuation_token else None,
169175
polling=DocumentTranslationLROPollingMethod(
170176
timeout=polling_interval,
171-
lro_algorithms=[
172-
TranslationPolling()
173-
],
177+
lro_algorithms=[TranslationPolling()],
174178
cont_token_response=pipeline_response,
175-
**kwargs),
179+
**kwargs
180+
),
176181
cls=callback,
177182
continuation_token=continuation_token,
178183
**kwargs
@@ -192,8 +197,12 @@ def get_translation_status(self, translation_id, **kwargs):
192197
:raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError:
193198
"""
194199

195-
translation_status = self._client.document_translation.get_translation_status(translation_id, **kwargs)
196-
return TranslationStatusResult._from_generated(translation_status) # pylint: disable=protected-access
200+
translation_status = self._client.document_translation.get_translation_status(
201+
translation_id, **kwargs
202+
)
203+
return TranslationStatusResult._from_generated( # pylint: disable=protected-access
204+
translation_status
205+
)
197206

198207
@distributed_trace
199208
def cancel_translation(self, translation_id, **kwargs):
@@ -223,13 +232,15 @@ def list_all_translation_statuses(self, **kwargs):
223232
:keyword int results_per_page: is the number of operations returned per page.
224233
:keyword list[str] translation_ids: translation operations ids to filter by.
225234
:keyword list[str] statuses: translation operation statuses to filter by.
226-
:keyword Union[str, datetime.datetime] created_after: get operations created after certain datetime.
227-
:keyword Union[str, datetime.datetime] created_before: get operations created before certain datetime.
235+
:keyword created_after: get operations created after certain datetime.
236+
:paramtype created_after: Union[str, datetime.datetime]
237+
:keyword created_before: get operations created before certain datetime.
238+
:paramtype created_before: Union[str, datetime.datetime]
228239
:keyword list[str] order_by: the sorting query for the operations returned.
229240
format: ["parm1 asc/desc", "parm2 asc/desc", ...]
230241
(ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc').
231-
:return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`]
232-
:rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.TranslationStatusResult`]
242+
:return: A pageable of TranslationStatusResult.
243+
:rtype: ~azure.core.paging.ItemPaged[TranslationStatusResult]
233244
:raises ~azure.core.exceptions.HttpResponseError:
234245
235246
.. admonition:: Example:
@@ -248,14 +259,19 @@ def list_all_translation_statuses(self, **kwargs):
248259
results_per_page = kwargs.pop("results_per_page", None)
249260
translation_ids = kwargs.pop("translation_ids", None)
250261

251-
def _convert_from_generated_model(generated_model): # pylint: disable=protected-access
252-
return TranslationStatusResult._from_generated(generated_model) # pylint: disable=protected-access
262+
def _convert_from_generated_model(
263+
generated_model,
264+
): # pylint: disable=protected-access
265+
return TranslationStatusResult._from_generated(
266+
generated_model
267+
) # pylint: disable=protected-access
253268

254269
model_conversion_function = kwargs.pop(
255270
"cls",
256271
lambda translation_statuses: [
257272
_convert_from_generated_model(status) for status in translation_statuses
258-
])
273+
],
274+
)
259275

260276
return self._client.document_translation.get_translations_status(
261277
cls=model_conversion_function,
@@ -278,13 +294,15 @@ def list_all_document_statuses(self, translation_id, **kwargs):
278294
:keyword int results_per_page: is the number of documents returned per page.
279295
:keyword list[str] document_ids: document IDs to filter by.
280296
:keyword list[str] statuses: document statuses to filter by.
281-
:keyword Union[str, datetime.datetime] translated_after: get document translated after certain datetime.
282-
:keyword Union[str, datetime.datetime] translated_before: get document translated before certain datetime.
297+
:keyword translated_after: get document translated after certain datetime.
298+
:paramtype translated_after: Union[str, datetime.datetime]
299+
:keyword translated_before: get document translated before certain datetime.
300+
:paramtype translated_before: Union[str, datetime.datetime]
283301
:keyword list[str] order_by: the sorting query for the documents.
284302
format: ["parm1 asc/desc", "parm2 asc/desc", ...]
285303
(ex: 'createdDateTimeUtc asc', 'createdDateTimeUtc desc').
286-
:return: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`]
287-
:rtype: ~azure.core.paging.ItemPaged[:class:`~azure.ai.translation.document.DocumentStatusResult`]
304+
:return: A pageable of DocumentStatusResult.
305+
:rtype: ~azure.core.paging.ItemPaged[DocumentStatusResult]
288306
:raises ~azure.core.exceptions.HttpResponseError:
289307
290308
.. admonition:: Example:
@@ -298,20 +316,26 @@ def list_all_document_statuses(self, translation_id, **kwargs):
298316
"""
299317
translated_after = kwargs.pop("translated_after", None)
300318
translated_before = kwargs.pop("translated_before", None)
301-
translated_after = convert_datetime(translated_after) if translated_after else None
302-
translated_before = convert_datetime(translated_before) if translated_before else None
319+
translated_after = (
320+
convert_datetime(translated_after) if translated_after else None
321+
)
322+
translated_before = (
323+
convert_datetime(translated_before) if translated_before else None
324+
)
303325
results_per_page = kwargs.pop("results_per_page", None)
304326
document_ids = kwargs.pop("document_ids", None)
305327

306-
307328
def _convert_from_generated_model(generated_model):
308-
return DocumentStatusResult._from_generated(generated_model) # pylint: disable=protected-access
329+
return DocumentStatusResult._from_generated( # pylint: disable=protected-access
330+
generated_model
331+
)
309332

310333
model_conversion_function = kwargs.pop(
311334
"cls",
312335
lambda doc_statuses: [
313336
_convert_from_generated_model(doc_status) for doc_status in doc_statuses
314-
])
337+
],
338+
)
315339

316340
return self._client.document_translation.get_documents_status(
317341
id=translation_id,
@@ -336,10 +360,11 @@ def get_document_status(self, translation_id, document_id, **kwargs):
336360
"""
337361

338362
document_status = self._client.document_translation.get_document_status(
339-
translation_id,
340-
document_id,
341-
**kwargs)
342-
return DocumentStatusResult._from_generated(document_status) # pylint: disable=protected-access
363+
translation_id, document_id, **kwargs
364+
)
365+
return DocumentStatusResult._from_generated( # pylint: disable=protected-access
366+
document_status
367+
)
343368

344369
@distributed_trace
345370
def get_glossary_formats(self, **kwargs):
@@ -351,8 +376,12 @@ def get_glossary_formats(self, **kwargs):
351376
:raises ~azure.core.exceptions.HttpResponseError:
352377
"""
353378

354-
glossary_formats = self._client.document_translation.get_supported_glossary_formats(**kwargs)
355-
return FileFormat._from_generated_list(glossary_formats.value) # pylint: disable=protected-access
379+
glossary_formats = (
380+
self._client.document_translation.get_supported_glossary_formats(**kwargs)
381+
)
382+
return FileFormat._from_generated_list( # pylint: disable=protected-access
383+
glossary_formats.value
384+
)
356385

357386
@distributed_trace
358387
def get_document_formats(self, **kwargs):
@@ -364,5 +393,9 @@ def get_document_formats(self, **kwargs):
364393
:raises ~azure.core.exceptions.HttpResponseError:
365394
"""
366395

367-
document_formats = self._client.document_translation.get_supported_document_formats(**kwargs)
368-
return FileFormat._from_generated_list(document_formats.value) # pylint: disable=protected-access
396+
document_formats = (
397+
self._client.document_translation.get_supported_document_formats(**kwargs)
398+
)
399+
return FileFormat._from_generated_list( # pylint: disable=protected-access
400+
document_formats.value
401+
)

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@
1616
TargetInput as _TargetInput,
1717
)
1818
from ._models import DocumentTranslationInput
19+
1920
COGNITIVE_KEY_HEADER = "Ocp-Apim-Subscription-Key"
2021
POLLING_INTERVAL = 1
2122

2223

2324
def get_translation_input(args, kwargs, continuation_token):
2425
try:
25-
inputs = kwargs.pop('inputs', None)
26+
inputs = kwargs.pop("inputs", None)
2627
if not inputs:
2728
inputs = args[0]
28-
request = DocumentTranslationInput._to_generated_list(inputs) \
29-
if not continuation_token else None # pylint: disable=protected-access
29+
request = (
30+
DocumentTranslationInput._to_generated_list(inputs) # pylint: disable=protected-access
31+
if not continuation_token
32+
else None
33+
)
3034
except (AttributeError, TypeError, IndexError):
3135
try:
32-
source_url = kwargs.pop('source_url', None)
36+
source_url = kwargs.pop("source_url", None)
3337
if not source_url:
3438
source_url = args[0]
3539
target_url = kwargs.pop("target_url", None)
@@ -40,18 +44,19 @@ def get_translation_input(args, kwargs, continuation_token):
4044
target_language_code = args[2]
4145
request = [
4246
_BatchRequest(
43-
source=_SourceInput(
44-
source_url=source_url
45-
),
46-
targets=[_TargetInput(
47-
target_url=target_url,
48-
language=target_language_code
49-
)]
47+
source=_SourceInput(source_url=source_url),
48+
targets=[
49+
_TargetInput(
50+
target_url=target_url, language=target_language_code
51+
)
52+
],
5053
)
5154
]
5255
except (AttributeError, TypeError, IndexError):
53-
raise ValueError("Pass 'inputs' for multiple inputs or 'source_url', 'target_url', "
54-
"and 'target_language_code' for a single input.")
56+
raise ValueError(
57+
"Pass 'inputs' for multiple inputs or 'source_url', 'target_url', "
58+
"and 'target_language_code' for a single input."
59+
)
5560

5661
return request
5762

@@ -85,7 +90,7 @@ def get_http_logging_policy(**kwargs):
8590
"Set-Cookie",
8691
"X-Powered-By",
8792
"Strict-Transport-Security",
88-
"x-content-type-options"
93+
"x-content-type-options",
8994
}
9095
)
9196
http_logging_policy.allowed_query_params.update(
@@ -97,7 +102,7 @@ def get_http_logging_policy(**kwargs):
97102
"statuses",
98103
"createdDateTimeUtcStart",
99104
"createdDateTimeUtcEnd",
100-
"$orderBy"
105+
"$orderBy",
101106
}
102107
)
103108
return http_logging_policy

0 commit comments

Comments
 (0)