Skip to content
Merged
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d9fafb6
initial commit
kristapratico Feb 20, 2021
a4aa5b2
update samples
kristapratico Feb 23, 2021
c6e34f0
updates from feedback
kristapratico Feb 24, 2021
d14fcac
johans feedback
kristapratico Feb 25, 2021
48edd9e
renaming to use job terminology
kristapratico Feb 25, 2021
f418339
update samples - optional src language
kristapratico Mar 2, 2021
7d763ab
samples hero scenarios (#16936)
Mar 3, 2021
4cc75d0
[client] modify the 'create_translation_job()' method
Mar 3, 2021
1f10c77
[models wrapping 'JobStatusDetail'
Mar 4, 2021
2eed715
[models wrapping] update client
Mar 4, 2021
d97b551
[models wrapping] formats mapping [documents, glossaries, storage]
Mar 4, 2021
5ebd7fa
[models wrapping] batch document input
Mar 4, 2021
83e2b9d
[models wrapping] added document status
Mar 7, 2021
4626d7f
[models wrapping] added support for list document status
Mar 7, 2021
3b66c59
[models wrapping] remove unwanted code
Mar 7, 2021
ee18f40
[models wrapping] forgot to add job id
Mar 8, 2021
c55886e
[model wrapping] list all jobs
Mar 8, 2021
990cb65
[pr review] extract job id
Mar 8, 2021
373a6f5
[refactor] some refactoring
Mar 8, 2021
691d703
[pr reviews] refactor
Mar 8, 2021
a68c1ab
[refactor] to_generated in glossary
Mar 8, 2021
432503a
[refactor] to generated in StorageTargets
Mar 8, 2021
0573190
[refactor] to_generated in BatchDocumentInput
Mar 8, 2021
daee063
[refactor] to_generated in Glossary more
Mar 8, 2021
9ec007b
[refactor] make code readable -> storage formats
Mar 8, 2021
ec4c16c
[integration] added support for wait_until_done
Mar 8, 2021
c18bef5
[refactor] spelling error
Mar 8, 2021
4573984
[integrate sdk] updated "wait_until_done" to use azure core poller in…
Mar 10, 2021
0bc6159
[sync client][wait till done] initial poller
Mar 15, 2021
7a27db5
[sync client][wait poller] poller algorithm completed
Mar 15, 2021
866f766
[PR comments] wrap model before returning
Mar 15, 2021
a4fd853
[pr reviews] adjust parameter type to list
Mar 15, 2021
223a363
[pr reviews] some linter checks
Mar 15, 2021
61faadc
[pr reviews] remove static methods, and fix private naming conventio…
Mar 15, 2021
23932aa
[pr reviews] fix return type value
Mar 15, 2021
4c01ceb
[PR reviews] implement unimplemented inherited abstract method
Mar 15, 2021
e9cdb61
[pr reviews] fix python private method naming in client
Mar 15, 2021
53f9208
[pr review] handle case with no error happening
Mar 15, 2021
334cdff
[pr reviews] renaming stuff :)
Mar 15, 2021
38e479b
[pr reviews] renaming more stuff :)
Mar 15, 2021
edba47f
[pr reviews] refactor private functions and linting options
Mar 15, 2021
0a569d4
[bug fix] poller -> handle non-standard status responses
Mar 16, 2021
eb445bc
[#17289] remove supported storage sources method
Mar 16, 2021
93d9cea
[bug fix] private method name
Mar 16, 2021
20c3c1b
Merge branch 'master' into v-moshaban/16880/models_wrapping
kristapratico Mar 16, 2021
e20284a
[linting] _models.py
Mar 16, 2021
ebb407a
[linting] client
Mar 17, 2021
aab715f
[linting] models
Mar 17, 2021
84e1448
[bug fix] wait until done pipeline response
Mar 17, 2021
4bea54e
[linting] more client linting
Mar 17, 2021
ea9482c
[linting] more client
Mar 17, 2021
b161500
[linting] more in models
Mar 17, 2021
8c27992
more linting
Mar 17, 2021
ba16f86
[linting] more linting things
Mar 18, 2021
ea59b05
[linting] client
Mar 18, 2021
1e56b14
[linting] more
Mar 18, 2021
95f7f27
[linting] more
Mar 18, 2021
fe31acb
[linting] for goodness sakes!
Mar 18, 2021
194372b
[bug fix] models -> StorageTarget -> handle when user doesn't pass gl…
Mar 18, 2021
58cf644
[linting] line-too-long
Mar 18, 2021
5911041
[async client] submit translation job
Mar 16, 2021
81ef60b
[async client] job status
Mar 16, 2021
86092aa
[async client] more function support added
Mar 16, 2021
de27008
[async client] added document status
Mar 16, 2021
1415cb3
[async client] add remaining methods
Mar 16, 2021
6456c57
[async client] use async poller
Mar 17, 2021
4f78b77
[linting] asycn client
Mar 18, 2021
8727a00
[linting] more
Mar 18, 2021
8495470
Merge remote-tracking branch 'azureRepo/master' into v-moshaban/17291…
Mar 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
from typing import Union, Any, List, TYPE_CHECKING
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.tracing.decorator import distributed_trace
from azure.core.polling import AsyncLROPoller
from azure.core.polling.async_base_polling import AsyncLROBasePolling
from azure.core.async_paging import AsyncItemPaged
from .._generated.aio import BatchDocumentTranslationClient as _BatchDocumentTranslationClient
from .._user_agent import USER_AGENT
from .._models import JobStatusDetail, DocumentStatusDetail, BatchDocumentInput, FileFormat
from .._generated.models import (
BatchStatusDetail as _BatchStatusDetail,
)
from .._models import (
JobStatusDetail,
BatchDocumentInput,
FileFormat,
DocumentStatusDetail
)
from .._helpers import get_authentication_policy
from .._polling import TranslationPolling
if TYPE_CHECKING:
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.credentials import AzureKeyCredential
Expand Down Expand Up @@ -59,12 +70,27 @@ async def create_translation_job(self, batch, **kwargs):
:rtype: JobStatusDetail
"""

return await self._client.document_translation.begin_submit_batch_request(
inputs=batch,
# submit translation job
response_headers = await self._client.document_translation._submit_batch_request_initial( # pylint: disable=protected-access
# pylint: disable=protected-access
inputs=BatchDocumentInput._to_generated_list(batch),
cls=lambda pipeline_response, _, response_headers: response_headers,
polling=True,
**kwargs
)

def get_job_id(response_headers):
# extract job id.
operation_location_header = response_headers['Operation-Location']
return operation_location_header.split('/')[-1]

# get job id from response header
job_id = get_job_id(response_headers)

# get job status
return await self.get_job_status(job_id)


@distributed_trace_async
async def get_job_status(self, job_id, **kwargs):
# type: (str, **Any) -> JobStatusDetail
Expand All @@ -75,7 +101,9 @@ async def get_job_status(self, job_id, **kwargs):
:rtype: ~azure.ai.documenttranslation.JobStatusDetail
"""

return await self._client.document_translation.get_operation_status(job_id, **kwargs)
job_status = await self._client.document_translation.get_operation_status(job_id, **kwargs)
# pylint: disable=protected-access
return JobStatusDetail._from_generated(job_status)

@distributed_trace_async
async def cancel_job(self, job_id, **kwargs):
Expand All @@ -99,7 +127,26 @@ async def wait_until_done(self, job_id, **kwargs):
:return: JobStatusDetail
:rtype: JobStatusDetail
"""
pass # pylint: disable=unnecessary-pass
pipeline_response = await self._client.document_translation.get_operation_status(
job_id,
cls=lambda pipeline_response, _, response_headers: pipeline_response
)

def callback(raw_response):
detail = self._client._deserialize(_BatchStatusDetail, raw_response) # pylint: disable=protected-access
return JobStatusDetail._from_generated(detail) # pylint: disable=protected-access

poller = AsyncLROPoller(
client=self._client._client, # pylint: disable=protected-access
initial_response=pipeline_response,
deserialization_callback=callback,
polling_method=AsyncLROBasePolling(
timeout=30,
lro_algorithms=[TranslationPolling()],
**kwargs
),
)
return poller.result()

@distributed_trace
def list_submitted_jobs(self, **kwargs):
Expand All @@ -110,7 +157,24 @@ def list_submitted_jobs(self, **kwargs):
:keyword int skip:
:rtype: ~azure.core.polling.AsyncItemPaged[JobStatusDetail]
"""
return self._client.document_translation.get_operations(**kwargs)
skip = kwargs.pop('skip', None)
results_per_page = kwargs.pop('results_per_page', None)

def _convert_from_generated_model(generated_model):
# pylint: disable=protected-access
return JobStatusDetail._from_generated(generated_model)

model_conversion_function = kwargs.pop(
"cls",
lambda job_statuses: [_convert_from_generated_model(job_status) for job_status in job_statuses]
)

return self._client.document_translation.get_operations(
top=results_per_page,
skip=skip,
cls=model_conversion_function,
**kwargs
)

@distributed_trace
def list_documents_statuses(self, job_id, **kwargs):
Expand All @@ -123,8 +187,26 @@ def list_documents_statuses(self, job_id, **kwargs):
:keyword int skip:
:rtype: ~azure.core.paging.AsyncItemPaged[DocumentStatusDetail]
"""
skip = kwargs.pop('skip', None)
results_per_page = kwargs.pop('results_per_page', None)

def _convert_from_generated_model(generated_model):
# pylint: disable=protected-access
return DocumentStatusDetail._from_generated(generated_model)

model_conversion_function = kwargs.pop(
"cls",
lambda doc_statuses: [_convert_from_generated_model(doc_status) for doc_status in doc_statuses]
)

return self._client.document_translation.get_operation_documents_status(
id=job_id,
top=results_per_page,
skip=skip,
cls=model_conversion_function,
**kwargs
)

return self._client.document_translation.get_operation_documents_status(job_id, **kwargs)

@distributed_trace_async
async def get_document_status(self, job_id, document_id, **kwargs):
Expand All @@ -137,16 +219,10 @@ async def get_document_status(self, job_id, document_id, **kwargs):
:type document_id: str
:rtype: ~azure.ai.documenttranslation.DocumentStatusDetail
"""
return await self._client.document_translation.get_document_status(job_id, document_id, **kwargs)
document_status = await self._client.document_translation.get_document_status(job_id, document_id, **kwargs)
# pylint: disable=protected-access
return DocumentStatusDetail._from_generated(document_status)

@distributed_trace_async
async def get_supported_storage_sources(self, **kwargs):
# type: (**Any) -> List[str]
"""

:rtype: list[str]
"""
return await self._client.document_translation.get_document_storage_source(**kwargs)

@distributed_trace_async
async def get_supported_glossary_formats(self, **kwargs):
Expand All @@ -155,8 +231,9 @@ async def get_supported_glossary_formats(self, **kwargs):

:rtype: list[FileFormat]
"""

return await self._client.document_translation.get_glossary_formats(**kwargs)
glossary_formats = await self._client.document_translation.get_glossary_formats(**kwargs)
# pylint: disable=protected-access
return FileFormat._from_generated_list(glossary_formats.value)

@distributed_trace_async
async def get_supported_document_formats(self, **kwargs):
Expand All @@ -165,5 +242,6 @@ async def get_supported_document_formats(self, **kwargs):

:rtype: list[FileFormat]
"""

return await self._client.document_translation.get_document_formats(**kwargs)
document_formats = await self._client.document_translation.get_document_formats(**kwargs)
# pylint: disable=protected-access
return FileFormat._from_generated_list(document_formats.value)