@autorest/python 5.13.0 → 5.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/ChangeLog.md +67 -0
  2. package/autorest/__init__.py +1 -2
  3. package/autorest/black/__init__.py +12 -5
  4. package/autorest/codegen/__init__.py +239 -105
  5. package/autorest/codegen/models/__init__.py +29 -18
  6. package/autorest/codegen/models/base_builder.py +48 -11
  7. package/autorest/codegen/models/base_model.py +6 -4
  8. package/autorest/codegen/models/base_schema.py +21 -24
  9. package/autorest/codegen/models/client.py +70 -20
  10. package/autorest/codegen/models/code_model.py +144 -129
  11. package/autorest/codegen/models/constant_schema.py +32 -16
  12. package/autorest/codegen/models/credential_model.py +55 -0
  13. package/autorest/codegen/models/credential_schema.py +21 -16
  14. package/autorest/codegen/models/credential_schema_policy.py +11 -15
  15. package/autorest/codegen/models/dictionary_schema.py +27 -24
  16. package/autorest/codegen/models/enum_schema.py +41 -62
  17. package/autorest/codegen/models/imports.py +72 -41
  18. package/autorest/codegen/models/list_schema.py +40 -18
  19. package/autorest/codegen/models/lro_operation.py +61 -25
  20. package/autorest/codegen/models/lro_paging_operation.py +5 -6
  21. package/autorest/codegen/models/object_schema.py +113 -59
  22. package/autorest/codegen/models/operation.py +251 -111
  23. package/autorest/codegen/models/operation_group.py +67 -32
  24. package/autorest/codegen/models/paging_operation.py +48 -21
  25. package/autorest/codegen/models/parameter.py +182 -90
  26. package/autorest/codegen/models/parameter_list.py +184 -163
  27. package/autorest/codegen/models/primitive_schemas.py +89 -70
  28. package/autorest/codegen/models/property.py +49 -31
  29. package/autorest/codegen/models/request_builder.py +67 -32
  30. package/autorest/codegen/models/request_builder_parameter.py +54 -23
  31. package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
  32. package/autorest/codegen/models/schema_request.py +16 -6
  33. package/autorest/codegen/models/schema_response.py +35 -17
  34. package/autorest/codegen/models/utils.py +24 -1
  35. package/autorest/codegen/serializers/__init__.py +273 -89
  36. package/autorest/codegen/serializers/builder_serializer.py +711 -333
  37. package/autorest/codegen/serializers/client_serializer.py +114 -43
  38. package/autorest/codegen/serializers/general_serializer.py +84 -25
  39. package/autorest/codegen/serializers/import_serializer.py +93 -31
  40. package/autorest/codegen/serializers/metadata_serializer.py +73 -24
  41. package/autorest/codegen/serializers/model_base_serializer.py +42 -14
  42. package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
  43. package/autorest/codegen/serializers/model_init_serializer.py +5 -1
  44. package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
  45. package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
  46. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  47. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  48. package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
  49. package/autorest/codegen/serializers/utils.py +60 -21
  50. package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
  51. package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
  52. package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
  53. package/autorest/codegen/templates/README.md.jinja2 +105 -0
  54. package/autorest/codegen/templates/config.py.jinja2 +4 -4
  55. package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
  56. package/autorest/codegen/templates/enum.py.jinja2 +1 -1
  57. package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
  58. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  59. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  60. package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
  61. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
  62. package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
  63. package/autorest/codegen/templates/model.py.jinja2 +1 -6
  64. package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
  65. package/autorest/codegen/templates/operation.py.jinja2 +8 -11
  66. package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
  67. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  68. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  69. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  70. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  71. package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
  72. package/autorest/codegen/templates/setup.py.jinja2 +79 -20
  73. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  74. package/autorest/jsonrpc/__init__.py +7 -12
  75. package/autorest/jsonrpc/localapi.py +4 -3
  76. package/autorest/jsonrpc/server.py +13 -6
  77. package/autorest/jsonrpc/stdstream.py +13 -6
  78. package/autorest/m2r/__init__.py +5 -8
  79. package/autorest/multiapi/__init__.py +24 -14
  80. package/autorest/multiapi/models/client.py +21 -11
  81. package/autorest/multiapi/models/code_model.py +23 -10
  82. package/autorest/multiapi/models/config.py +4 -1
  83. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  84. package/autorest/multiapi/models/global_parameter.py +2 -1
  85. package/autorest/multiapi/models/global_parameters.py +14 -8
  86. package/autorest/multiapi/models/imports.py +35 -18
  87. package/autorest/multiapi/models/mixin_operation.py +5 -5
  88. package/autorest/multiapi/models/operation_group.py +2 -1
  89. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  90. package/autorest/multiapi/serializers/__init__.py +18 -23
  91. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  92. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  93. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
  94. package/autorest/multiapi/utils.py +3 -3
  95. package/autorest/namer/__init__.py +2 -4
  96. package/autorest/namer/name_converter.py +200 -103
  97. package/autorest/namer/python_mappings.py +10 -22
  98. package/package.json +3 -3
  99. package/run-python3.js +2 -3
  100. package/venvtools.py +1 -1
  101. package/autorest/codegen/models/rest.py +0 -42
@@ -3,8 +3,9 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ from enum import Enum, auto
6
7
  from typing import List
7
- from ..models import ParameterStyle, ListSchema, Parameter
8
+ from ..models import ParameterStyle, ListSchema, Parameter, ParameterLocation
8
9
 
9
10
 
10
11
  def serialize_method(
@@ -22,13 +23,11 @@ def serialize_method(
22
23
  lines.append(first_line)
23
24
  if is_in_class:
24
25
  lines.append(" self,")
25
- lines.extend([
26
- (" " + line)
27
- for line in method_param_signatures
28
- ])
26
+ lines.extend([(" " + line) for line in method_param_signatures])
29
27
  lines.append(")")
30
28
  return "\n".join(lines)
31
29
 
30
+
32
31
  def build_serialize_data_call(
33
32
  parameter: Parameter, function_name: str, serializer_name: str
34
33
  ) -> str:
@@ -68,30 +67,32 @@ def build_serialize_data_call(
68
67
  f'"{origin_name.lstrip("_")}"',
69
68
  "q" if parameter.explode else origin_name,
70
69
  f"'{serialization_schema.serialization_type}'",
71
- *optional_parameters
70
+ *optional_parameters,
72
71
  ]
73
- parameters_line = ', '.join(parameters)
72
+ parameters_line = ", ".join(parameters)
74
73
 
75
- serialize_line = f'{serializer_name}.{function_name}({parameters_line})'
74
+ serialize_line = f"{serializer_name}.{function_name}({parameters_line})"
76
75
 
77
76
  if parameter.explode:
78
77
  return f"[{serialize_line} if q is not None else '' for q in {origin_name}]"
79
78
  return serialize_line
80
79
 
81
- def serialize_path(
82
- parameters: List[Parameter], serializer_name: str
83
- ) -> List[str]:
80
+
81
+ def serialize_path(parameters: List[Parameter], serializer_name: str) -> List[str]:
84
82
  retval = ["path_format_arguments = {"]
85
- retval.extend([
86
- " \"{}\": {},".format(
87
- path_parameter.rest_api_name,
88
- build_serialize_data_call(path_parameter, "url", serializer_name)
89
- )
90
- for path_parameter in parameters
91
- ])
83
+ retval.extend(
84
+ [
85
+ ' "{}": {},'.format(
86
+ path_parameter.rest_api_name,
87
+ build_serialize_data_call(path_parameter, "url", serializer_name),
88
+ )
89
+ for path_parameter in parameters
90
+ ]
91
+ )
92
92
  retval.append("}")
93
93
  return retval
94
94
 
95
+
95
96
  def method_signature_and_response_type_annotation_template(
96
97
  *,
97
98
  is_python3_file: bool,
@@ -102,16 +103,54 @@ def method_signature_and_response_type_annotation_template(
102
103
  return f"{method_signature} -> {response_type_annotation}:"
103
104
  return f"{method_signature}:\n # type: (...) -> {response_type_annotation}"
104
105
 
105
- def pop_kwargs_from_signature(kwargs_to_pop: List[Parameter]) -> List[str]:
106
+
107
+ class PopKwargType(Enum):
108
+ NO = auto()
109
+ SIMPLE = auto()
110
+ CASE_INSENSITIVE = auto()
111
+
112
+
113
+ def pop_kwargs_from_signature(
114
+ kwargs_to_pop: List[Parameter],
115
+ check_kwarg_dict: bool,
116
+ pop_headers_kwarg: PopKwargType,
117
+ pop_params_kwarg: PopKwargType,
118
+ ) -> List[str]:
106
119
  retval = []
120
+
121
+ def append_pop_kwarg(key: str, pop_type: PopKwargType) -> None:
122
+ if PopKwargType.CASE_INSENSITIVE == pop_type:
123
+ retval.append(
124
+ f'_{key} = case_insensitive_dict(kwargs.pop("{key}", {{}}) or {{}})'
125
+ )
126
+ elif PopKwargType.SIMPLE == pop_type:
127
+ retval.append(f'_{key} = kwargs.pop("{key}", {{}}) or {{}}')
128
+
129
+ append_pop_kwarg("headers", pop_headers_kwarg)
130
+ append_pop_kwarg("params", pop_params_kwarg)
131
+ if pop_headers_kwarg != PopKwargType.NO or pop_params_kwarg != PopKwargType.NO:
132
+ retval.append("")
107
133
  for kwarg in kwargs_to_pop:
108
134
  if kwarg.has_default_value:
135
+ default_value = kwarg.default_value_declaration
136
+ if check_kwarg_dict and (
137
+ kwarg.location in [ParameterLocation.Header, ParameterLocation.Query]
138
+ ):
139
+ kwarg_dict = (
140
+ "headers"
141
+ if kwarg.location == ParameterLocation.Header
142
+ else "params"
143
+ )
144
+ default_value = (
145
+ f"_{kwarg_dict}.pop('{kwarg.rest_api_name}', {default_value})"
146
+ )
109
147
  retval.append(
110
148
  f"{kwarg.serialized_name} = kwargs.pop('{kwarg.serialized_name}', "
111
- + f"{kwarg.default_value_declaration}) # type: {kwarg.type_annotation}"
149
+ + f"{default_value}) # type: {kwarg.type_annotation(is_operation_file=True)}"
112
150
  )
113
151
  else:
152
+ type_annot = kwarg.type_annotation(is_operation_file=True)
114
153
  retval.append(
115
- f"{kwarg.serialized_name} = kwargs.pop('{kwarg.serialized_name}') # type: {kwarg.type_annotation}"
154
+ f"{kwarg.serialized_name} = kwargs.pop('{kwarg.serialized_name}') # type: {type_annot}"
116
155
  )
117
156
  return retval
@@ -0,0 +1,6 @@
1
+ # Release History
2
+
3
+ ## 1.0.0b1 (1970-01-01)
4
+
5
+ - Initial version
6
+
@@ -0,0 +1,21 @@
1
+ Copyright (c) Microsoft Corporation.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ include *.md
2
+ include LICENSE
3
+ recursive-include tests *.py
4
+ recursive-include samples *.py *.md
5
+ {%- for init_name in init_names %}
6
+ include {{ init_name }}
7
+ {%- endfor %}
@@ -0,0 +1,105 @@
1
+ {% if package_mode == "mgmtplane" -%}
2
+ # Microsoft Azure SDK for Python
3
+
4
+ This is the Microsoft {{package_pprint_name}} Client Library.
5
+ This package has been tested with Python 3.6+.
6
+ For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
7
+
8
+ # Usage
9
+
10
+ To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt)
11
+
12
+ For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure)
13
+ Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com.
14
+ Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples)
15
+
16
+ # Provide Feedback
17
+
18
+ If you encounter any bugs or have suggestions, please file an issue in the
19
+ [Issues](https://github.com/Azure/azure-sdk-for-python/issues)
20
+ section of the project.
21
+
22
+
23
+ ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2F{{package_name}}%2FREADME.png)
24
+ {% else %}
25
+ # {{ package_pprint_name }} client library for Python
26
+ <!-- write necessary description of service -->
27
+
28
+ ## Getting started
29
+
30
+ ### Installating the package
31
+
32
+ ```bash
33
+ python -m pip install {{ package_name }}
34
+ ```
35
+
36
+ #### Prequisites
37
+
38
+ - Python 3.6 or later is required to use this package.
39
+ - You need an [Azure subscription][azure_sub] to use this package.
40
+ - An existing {{ package_pprint_name }} instance.
41
+
42
+ {%- if token_credential %}
43
+ #### Create with an Azure Active Directory Credential
44
+ To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
45
+ provide an instance of the desired credential type obtained from the
46
+ [azure-identity][azure_identity_credentials] library.
47
+
48
+ To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]
49
+
50
+ After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
51
+ As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:
52
+
53
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
54
+ `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`
55
+
56
+ Use the returned token credential to authenticate the client:
57
+
58
+ ```python
59
+ >>> from {{ namespace }} import {{ client_name }}
60
+ >>> from azure.identity import DefaultAzureCredential
61
+ >>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
62
+ ```
63
+
64
+ ## Examples
65
+
66
+ ```python
67
+ >>> from {{ namespace }} import {{ client_name }}
68
+ >>> from azure.identity import DefaultAzureCredential
69
+ >>> from azure.core.exceptions import HttpResponseError
70
+
71
+ >>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
72
+ >>> try:
73
+ <!-- write test code here -->
74
+ except HttpResponseError as e:
75
+ print('service responds error: {}'.format(e.response.json()))
76
+
77
+ ```
78
+ {%- endif %}
79
+
80
+ ## Contributing
81
+
82
+ This project welcomes contributions and suggestions. Most contributions require
83
+ you to agree to a Contributor License Agreement (CLA) declaring that you have
84
+ the right to, and actually do, grant us the rights to use your contribution.
85
+ For details, visit https://cla.microsoft.com.
86
+
87
+ When you submit a pull request, a CLA-bot will automatically determine whether
88
+ you need to provide a CLA and decorate the PR appropriately (e.g., label,
89
+ comment). Simply follow the instructions provided by the bot. You will only
90
+ need to do this once across all repos using our CLA.
91
+
92
+ This project has adopted the
93
+ [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
94
+ see the Code of Conduct FAQ or contact opencode@microsoft.com with any
95
+ additional questions or comments.
96
+
97
+ <!-- LINKS -->
98
+ [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
99
+ [authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
100
+ [azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
101
+ [azure_identity_pip]: https://pypi.org/project/azure-identity/
102
+ [default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
103
+ [pip]: https://pypi.org/project/pip/
104
+ [azure_sub]: https://azure.microsoft.com/free/
105
+ {% endif %}
@@ -35,8 +35,8 @@ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disabl
35
35
  {% if serializer.set_constants() %}
36
36
  {{ op_tools.serialize(serializer.set_constants()) | indent(8) -}}
37
37
  {% endif %}
38
- {% if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined %}
39
- self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential_schema_policy.credential_scopes }})
38
+ {% if code_model.options['credential'] and code_model.credential_model.credential_schema_policy.credential_scopes is defined %}
39
+ self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential_model.credential_schema_policy.credential_scopes }})
40
40
  {% endif %}
41
41
  kwargs.setdefault('sdk_moniker', '{{ sdk_moniker }}/{}'.format(VERSION))
42
42
  self._configure(**kwargs)
@@ -59,10 +59,10 @@ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disabl
59
59
  self.authentication_policy = kwargs.get('authentication_policy')
60
60
  {% if code_model.options['credential'] %}
61
61
  {# only adding this if credential_scopes is not passed during code generation #}
62
- {% if code_model.credential_schema_policy.credential_scopes is defined and code_model.credential_schema_policy.credential_scopes|length == 0 %}
62
+ {% if code_model.credential_model.credential_schema_policy.credential_scopes is defined and code_model.credential_model.credential_schema_policy.credential_scopes|length == 0 %}
63
63
  if not self.credential_scopes and not self.authentication_policy:
64
64
  raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
65
65
  {% endif %}
66
66
  if self.credential and not self.authentication_policy:
67
- self.authentication_policy = {{ code_model.credential_schema_policy.call(async_mode) }}
67
+ self.authentication_policy = {{ code_model.credential_model.credential_schema_policy.call(async_mode) }}
68
68
  {% endif %}
@@ -0,0 +1,10 @@
1
+ -e ../../../tools/azure-devtools
2
+ -e ../../../tools/azure-sdk-tools
3
+ ../../core/azure-core
4
+ {% if token_credential -%}
5
+ ../../identity/azure-identity
6
+ {% endif -%}
7
+ {% if azure_arm -%}
8
+ ../../core/azure-mgmt-core
9
+ {% endif -%}
10
+ aiohttp
@@ -1,5 +1,5 @@
1
1
 
2
- class {{ enum.name }}(with_metaclass(CaseInsensitiveEnumMeta, {{ enum.enum_type.type_annotation }}, Enum)):
2
+ class {{ enum.name }}({{ enum.enum_type.type_annotation() }}, Enum, metaclass=CaseInsensitiveEnumMeta):
3
3
  {% if enum.description %}
4
4
  """{{ enum.description | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
5
5
  """
@@ -2,7 +2,6 @@
2
2
  {{ code_model.options['license_header'] }}
3
3
 
4
4
  from enum import Enum
5
- from six import with_metaclass
6
5
  from azure.core import CaseInsensitiveEnumMeta
7
6
 
8
7
  {% for enum in code_model.enums.values() | sort %}
@@ -1,15 +1,18 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
 
4
- from ._{{ code_model.module_name }} import {{ code_model.class_name }}
5
+ {% if code_model.request_builders %}
6
+ from .{{ code_model.service_client.filename }} import {{ code_model.class_name }}
7
+ {% endif %}
5
8
  {% if not async_mode and code_model.options['package_version']%}
6
9
  from ._version import VERSION
7
10
 
8
11
  __version__ = VERSION
9
12
  {% endif %}
10
- __all__ = ['{{ code_model.class_name }}']
11
13
 
12
- # `._patch.py` is used for handwritten extensions to the generated code
13
- # Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
14
- from ._patch import patch_sdk
15
- patch_sdk()
14
+ {{ keywords.patch_imports(try_except=True) }}
15
+ __all__ = [{{("'" + code_model.class_name + "'") if code_model.request_builders else ""}}]
16
+ {{ keywords.extend_all }}
17
+
18
+ _patch_sdk()
@@ -3,4 +3,17 @@
3
3
  {% set await = "await " if async_mode else "" %}
4
4
  {% set async_class = "Async" if async_mode else "" %}
5
5
  {% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
6
- {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
6
+ {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
7
+ {% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__])" %}
8
+ {% macro patch_imports(try_except=False) %}
9
+ {% set indentation = " " if try_except else "" %}
10
+ {% if try_except %}
11
+ try:
12
+ {% endif %}
13
+ {{ indentation }}from ._patch import __all__ as _patch_all
14
+ {{ indentation }}from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
15
+ {% if try_except %}
16
+ except ImportError:
17
+ _patch_all = []
18
+ {% endif %}
19
+ from ._patch import patch_sdk as _patch_sdk{% endmacro %}
@@ -1,18 +1,16 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
3
2
  {# actual template starts here #}
4
- {% if code_model.options['tracing'] %}
5
- {{ trace_decorator }}
6
- {% endif %}
7
- {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
3
+ {{ operation_serializer.method_signature_and_response_type_annotation(operation, async_mode) }}
8
4
  {{ op_tools.description(operation, operation_serializer) | indent -}}
9
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
5
+ {% if not operation.abstract %}
6
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
10
7
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
11
- {%- endif %}
8
+ {%- endif %}
12
9
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
13
10
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
14
11
 
15
12
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
13
+ {% endif %}
16
14
  {% if not code_model.options["version_tolerant"] %}
17
15
  {{ operation_serializer.get_metadata_url(operation) -}}
18
16
  {% endif %}
@@ -1,20 +1,18 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
2
  {% import 'keywords.jinja2' as keywords with context %}
3
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
4
3
  {# actual template starts here #}
5
- {% if code_model.options['tracing'] %}
6
- {{ trace_decorator }}
7
- {% endif %}
8
- {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
4
+ {{ operation_serializer.method_signature_and_response_type_annotation(operation, async_mode) }}
9
5
  {{ op_tools.description(operation, operation_serializer) | indent }}
10
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
6
+ {% if not operation.abstract %}
7
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
11
8
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
12
- {% endif %}
9
+ {% endif %}
13
10
  {{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
14
11
 
15
12
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
16
13
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
17
14
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
15
+ {% endif %}
18
16
  {% if not code_model.options["version_tolerant"] %}
19
17
  {{ operation_serializer.get_metadata_url(operation) }}
20
18
  {% endif %}
@@ -92,9 +92,9 @@
92
92
  },
93
93
  "config": {
94
94
  "credential": {{ code_model.options['credential'] | tojson }},
95
- "credential_scopes": {{ (code_model.credential_schema_policy.credential_scopes if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined else None)| tojson}},
96
- "credential_call_sync": {{ (code_model.credential_schema_policy.call(async_mode=False) if code_model.options['credential'] else None) | tojson }},
97
- "credential_call_async": {{ (code_model.credential_schema_policy.call(async_mode=True) if code_model.options['credential'] else None) | tojson }},
95
+ "credential_scopes": {{ (code_model.credential_model.credential_schema_policy.credential_scopes if code_model.options['credential'] and code_model.credential_model.credential_schema_policy.credential_scopes is defined else None)| tojson}},
96
+ "credential_call_sync": {{ (code_model.credential_model.credential_schema_policy.call(async_mode=False) if code_model.options['credential'] else None) | tojson }},
97
+ "credential_call_async": {{ (code_model.credential_model.credential_schema_policy.call(async_mode=True) if code_model.options['credential'] else None) | tojson }},
98
98
  "sync_imports": {{ sync_config_imports | tojson }},
99
99
  "async_imports": {{ async_config_imports | tojson }}
100
100
  },
@@ -126,8 +126,9 @@
126
126
  {% from "operation.py.jinja2" import operation_docstring with context %}
127
127
  {% set sync_return_type_wrapper = "" %}
128
128
  {% endif %}
129
- "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation) + "\n") | tojson }},
130
- "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }}
129
+ "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, False, want_decorators=False) + "\n") | tojson }},
130
+ "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
131
+ "call": {{ operation.parameters.call(is_python3_file=False) | join(', ') | tojson }}
131
132
  },
132
133
  "async": {
133
134
  {% set coroutine = False if (is_paging(operation) and not is_lro(operation)) else True %}
@@ -146,10 +147,10 @@
146
147
  {% from "operation.py.jinja2" import operation_docstring with context %}
147
148
  {% set async_return_type_wrapper = "" %}
148
149
  {% endif %}
149
- "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation) + "\n") | tojson }},
150
- "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }}
151
- },
152
- "call": {{ operation.parameters.method | rejectattr("is_kwarg") | map(attribute="serialized_name") | rejectattr("is_kwarg") | join(', ') | tojson }}
150
+ "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, True, want_decorators=False) + "\n") | tojson }},
151
+ "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
152
+ "call": {{ operation.parameters.call(is_python3_file=True) | join(', ') | tojson }}
153
+ }
153
154
  }{{ "," if not loop.last else "" }}
154
155
  {% endfor %}
155
156
  }
@@ -1,12 +1,7 @@
1
- {% set basename = model.base_models | join(', ', attribute='name') if model.base_models else "" %}
2
1
  {# actual template starts here #}
3
2
 
4
3
 
5
- {% if basename %}
6
- class {{ model.name }}({{ basename }}):
7
- {% else %}
8
- class {{ model.name }}(msrest.serialization.Model):
9
- {% endif %}
4
+ {{ declare_model(model) }}
10
5
  """{{ model.description }}
11
6
  {% if model.discriminator_name %}
12
7
 
@@ -1,8 +1,9 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
  {% macro iterate_models_py3() %}
4
5
  {% for schema in schemas %}
5
- from ._models_py3 import {{ schema }}
6
+ from .{{ code_model.get_models_filename(is_python3_file=True) }} import {{ schema }}
6
7
  {% endfor %}
7
8
  {% endmacro %}
8
9
 
@@ -14,19 +15,19 @@ try:
14
15
  {{ iterate_models_py3() | indent-}}
15
16
  except (SyntaxError, ImportError):
16
17
  {% for schema in schemas %}
17
- from ._models import {{ schema }} # type: ignore
18
+ from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
18
19
  {% endfor %}
19
20
  {% endif %}
20
21
  {% endif %}
21
22
  {% if enums %}
22
23
 
23
- from ._{{ code_model.module_name }}_enums import (
24
+ from .{{ code_model.enums_filename }} import (
24
25
  {% for enum in enums %}
25
26
  {{ enum }},
26
27
  {% endfor %}
27
28
  )
28
29
  {% endif %}
29
-
30
+ {{ keywords.patch_imports() }}
30
31
  __all__ = [
31
32
  {% for schema in schemas %}
32
33
  '{{ schema }}',
@@ -37,3 +38,5 @@ __all__ = [
37
38
  {% endfor %}
38
39
  {% endif %}
39
40
  ]
41
+ {{ keywords.extend_all }}
42
+ _patch_sdk()
@@ -1,29 +1,26 @@
1
1
  {% import 'keywords.jinja2' as keywords with context %}
2
2
  {% import 'operation_tools.jinja2' as op_tools %}
3
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
4
3
  {% set stream_request_parameter = "stream=" ~ ("True" if operation.is_stream_response else "False") %}
5
4
  {# actual template starts here #}
6
- {%- if code_model.options['tracing'] and operation.want_tracing -%}
7
- {{ trace_decorator }}
8
- {% endif %}
9
- {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
5
+ {{ operation_serializer.method_signature_and_response_type_annotation(operation, async_mode) }}
10
6
  {% if operation.want_description_docstring %}
11
7
  {{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
12
- cls = kwargs.pop('cls', None) {{ operation_serializer.cls_type_annotation(operation) }}
13
- {% if operation.deprecated %}
8
+ {% if not operation.abstract %}
9
+ {% if operation.deprecated %}
14
10
  warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
15
- {% endif %}
11
+ {% endif %}
16
12
  {{ op_tools.serialize(operation_serializer.error_map(operation)) | indent }}
17
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
13
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
18
14
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
19
- {% endif %}
15
+ {% endif %}
20
16
  {{ op_tools.serialize(operation_serializer.call_request_builder(operation)) | indent }}
21
- pipeline_response = {{ keywords.await }}self._client._pipeline.run( # pylint: disable=protected-access
17
+ pipeline_response = {{ keywords.await }}self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
22
18
  request,
23
19
  {{ stream_request_parameter }},
24
20
  **kwargs
25
21
  )
26
22
  {{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
23
+ {% endif %}
27
24
  {% if not code_model.options["version_tolerant"] %}
28
25
  {{ operation_serializer.get_metadata_url(operation) }}
29
26
  {% endif %}
@@ -1,30 +1,27 @@
1
1
  {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
- class {{ operation_group.class_name }}{{ object_base_class }}:{{ disable }}
2
+ {% set base_class = ("(" + operation_group.base_class(async_mode) + ")") if operation_group.base_class(async_mode) else "" %}
3
+ class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
3
4
  {% if not operation_group.is_empty_operation_group %}
4
- """{{ operation_group.class_name }} {{ operations_description }}.
5
-
6
- You should not instantiate this class directly. Instead, you should create a Client instance that
7
- instantiates it for you and attaches it as an attribute.
5
+ """
6
+ .. warning::
7
+ **DO NOT** instantiate this class directly.
8
8
 
9
- {% if code_model.schemas and code_model.options["models_mode"] %}
10
- :ivar models: Alias to model classes used in this operation group.
11
- :type models: ~{{ code_model.namespace }}.models
12
- {% endif %}
13
- :param client: Client for service requests.
14
- :param config: Configuration of service client.
15
- :param serializer: An object model serializer.
16
- :param deserializer: An object model deserializer.
9
+ Instead, you should access the following operations through
10
+ :class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + code_model.class_name }}`'s
11
+ :attr:`{{ operation_group.name }}` attribute.
17
12
  """
18
13
 
19
14
  {% if code_model.schemas and code_model.options["models_mode"] %}
20
15
  models = _models
21
16
 
22
17
  {% endif %}
23
- def __init__(self, client, config, serializer, deserializer){{ return_none_type_annotation }}:
24
- self._client = client
25
- self._serialize = serializer
26
- self._deserialize = deserializer
27
- self._config = config
18
+ def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
19
+ input_args = list(args)
20
+ self._client = input_args.pop(0) if input_args else kwargs.pop("client")
21
+ self._config = input_args.pop(0) if input_args else kwargs.pop("config")
22
+ self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
23
+ self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
24
+
28
25
  {% endif %}
29
26
  {% for operation in operation_group.operations %}
30
27
 
@@ -1,5 +1,4 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
- {% set object_base_class = "" if async_mode else "(object)" %}
3
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
4
3
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
5
4
  # pylint: disable=too-many-lines
@@ -13,7 +12,7 @@
13
12
  # fmt: off
14
13
  {% endif %}
15
14
  {% for operation_group in operation_groups %}
16
- {% for request_builder in code_model.rest.request_builders | selectattr("operation_group_name", "equalto", operation_group.name) %}
15
+ {% for request_builder in code_model.request_builders | selectattr("operation_group_name", "equalto", operation_group.name) %}
17
16
 
18
17
  {% include "request_builder.py.jinja2" %}
19
18
  {% endfor %}
@@ -1,9 +1,11 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
+ {% import 'keywords.jinja2' as keywords %}
2
3
  {# actual template starts here #}
3
4
  # coding=utf-8
4
5
  {{ code_model.options['license_header'] }}
5
6
 
6
7
  {{ op_tools.serialize(operation_group_imports()) }}
8
+ {{ keywords.patch_imports() }}
7
9
  {% if operation_groups %}
8
10
  __all__ = [
9
11
  {% for operation_group in operation_groups %}
@@ -11,3 +13,5 @@ __all__ = [
11
13
  {% endfor %}
12
14
  ]
13
15
  {% endif %}
16
+ {{ keywords.extend_all }}
17
+ _patch_sdk()