Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions autorest/codegen/templates/keywords.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set def = "async def" if async_mode else "def" %}
{% set async_prefix = "a" if async_mode else "" %}
{% set await = "await " if async_mode else "" %}
{% set async_class = "Async" if async_mode else "" %}
{% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
2 changes: 1 addition & 1 deletion autorest/codegen/templates/lro_operation.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ response_headers = {
}
{% endmacro %}
{% macro operation_docstring(async_mode) %}
{{ helper.operation_docstring_helper(operation, async_mode) }}
{{ helper.operation_docstring_helper(code_model, operation, async_mode) }}
{{ return_docstring(async_mode) }}
:raises ~azure.core.exceptions.HttpResponseError:
"""{% endmacro %}
Expand Down
20 changes: 11 additions & 9 deletions autorest/codegen/templates/lro_operation_helper.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

{% macro param_documentation_string(parameter) %}:param {{ parameter.serialized_name }}: {{ parameter.description }}{% endmacro %}

{% macro operation_docstring_helper(operation, async_mode) %}
{% macro operation_docstring_helper(code_model, operation, async_mode) %}
{% import 'keywords.jinja2' as keywords with context %}
"""{{ operation.summary if operation.summary else operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }}
{% if operation.summary and operation.description %}

Expand All @@ -25,16 +26,17 @@
{% endif %}
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:paramtype polling: bool or ~azure.core.polling.{{ "Async" if async_mode else "" }}PollingMethod
{% set default_polling_method = "ARMPolling"if code_model.options['azure_arm'] else "LROBasePolling" %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main point of this PR (sorry there's a lot of fluff where I add a keyword to dedup code in the LRO world). Before, we would always generate ARMPolling as the default polling method, even when arm flag wasn't set

:keyword polling: Pass in True if you'd like the {{ keywords.async_class }}{{ default_polling_method }} polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.{{ keywords.async_class }}PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
{%- endmacro -%}


{% macro lro_operation(code_model, operation, async_mode) %}
{% import 'keywords.jinja2' as keywords with context %}
polling = kwargs.pop('polling', {{ "True" if code_model.options['azure_arm'] else "False" }}) # type: Union[bool, {{ "Async" if async_mode else "" }}PollingMethod]
polling = kwargs.pop('polling', {{ "True" if code_model.options['azure_arm'] else "False" }}) # type: Union[bool, {{ keywords.async_class }}PollingMethod]
cls = kwargs.pop('cls', None) # type: ClsType[{{ op_tools.return_type_annotation(operation) }}]
lro_delay = kwargs.pop(
'polling_interval',
Expand All @@ -55,7 +57,7 @@
{%- endmacro -%}

{% macro lro_operation_return(code_model, operation, async_mode) %}
{% set async_prefix = "Async" if async_mode else "" %}
{% import 'keywords.jinja2' as keywords with context %}
{% set path_format_arguments = "" %}
{% set lro_options = (", lro_options={'final-state-via': '"+ operation.lro_options['final-state-via'] + "'}") if operation.lro_options else "" %}
{% set operation_name = "begin_"+operation.python_name %}
Expand All @@ -69,11 +71,11 @@

{% endif %}
{% if code_model.options['azure_arm'] %}
if polling is True: polling_method = {{ async_prefix }}ARMPolling(lro_delay{{ lro_options }}{{ path_format_arguments }}, **kwargs)
if polling is True: polling_method = {{ keywords.async_class }}ARMPolling(lro_delay{{ lro_options }}{{ path_format_arguments }}, **kwargs)
{% else %}
if polling is True: polling_method = {{ async_prefix }}LROBasePolling(lro_delay{{ lro_options }}{{ path_format_arguments }}, **kwargs)
if polling is True: polling_method = {{ keywords.async_class }}LROBasePolling(lro_delay{{ lro_options }}{{ path_format_arguments }}, **kwargs)
{% endif %}
elif polling is False: polling_method = {{ async_prefix }}NoPolling()
elif polling is False: polling_method = {{ keywords.async_class }}NoPolling()
else: polling_method = polling
if cont_token:
return {{ operation.get_poller(async_mode) }}.from_continuation_token(
Expand Down
2 changes: 1 addition & 1 deletion autorest/codegen/templates/lro_paging_operation.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:return: An instance of {{ operation.get_poller(async_mode) }} that returns an iterator like instance of either {{ operation.responses[0].docstring_text }} or the result of cls(response)
:rtype: ~{{ operation.get_poller_path(async_mode) }}[~{{ operation.get_pager_path(async_mode) }}[{{ operation.responses[0].docstring_type }}]]{% endmacro %}
{% macro operation_docstring(async_mode) %}
{{ lro_helper.operation_docstring_helper(operation, async_mode) }}
{{ lro_helper.operation_docstring_helper(code_model, operation, async_mode) }}
{{ return_docstring(async_mode) }}
:raises ~azure.core.exceptions.HttpResponseError:
"""{% endmacro %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ async def begin_get_multiple_pages_lro(
:type paging_get_multiple_pages_lro_options: ~custompollerpager.models.PagingGetMultiplePagesLroOptions
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncCustomPoller that returns an iterator like instance of either ProductResult or the result of cls(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,8 @@ def begin_get_multiple_pages_lro(
:type paging_get_multiple_pages_lro_options: ~custompollerpager.models.PagingGetMultiplePagesLroOptions
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the ARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of CustomPoller that returns an iterator like instance of either ProductResult or the result of cls(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ async def begin_put_async_retry_succeeded(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)
Expand Down Expand Up @@ -224,8 +224,8 @@ async def begin_put201_creating_succeeded200(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)
Expand Down Expand Up @@ -331,8 +331,8 @@ async def begin_post202_retry200(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down Expand Up @@ -437,8 +437,8 @@ async def begin_post_async_retry_succeeded(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ async def begin_put201_creating_succeeded200(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)
Expand Down Expand Up @@ -217,8 +217,8 @@ async def begin_put_async_relative_retry_succeeded(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)
Expand Down Expand Up @@ -323,8 +323,8 @@ async def begin_delete_provisioning202_accepted200_succeeded(

:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)
Expand Down Expand Up @@ -416,8 +416,8 @@ async def begin_delete202_retry200(

:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down Expand Up @@ -507,8 +507,8 @@ async def begin_delete_async_relative_retry_succeeded(

:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down Expand Up @@ -609,8 +609,8 @@ async def begin_post202_retry200(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down Expand Up @@ -714,8 +714,8 @@ async def begin_post_async_relative_retry_succeeded(
:type product: ~lro.models.Product
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:keyword polling: Pass in True if you'd like the AsyncARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of AsyncLROPoller that returns either None or the result of cls(response)
Expand Down
Loading