@autorest/python 5.16.0 → 5.19.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.
- package/ChangeLog.md +79 -4
- package/README.md +30 -4
- package/autorest/__init__.py +1 -1
- package/autorest/codegen/__init__.py +55 -211
- package/autorest/codegen/models/__init__.py +116 -83
- package/autorest/codegen/models/base_builder.py +49 -88
- package/autorest/codegen/models/base_model.py +1 -1
- package/autorest/codegen/models/{base_schema.py → base_type.py} +61 -39
- package/autorest/codegen/models/client.py +165 -53
- package/autorest/codegen/models/code_model.py +122 -257
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +80 -2
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +79 -156
- package/autorest/codegen/models/lro_paging_operation.py +28 -11
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +331 -298
- package/autorest/codegen/models/operation_group.py +54 -91
- package/autorest/codegen/models/paging_operation.py +82 -123
- package/autorest/codegen/models/parameter.py +289 -396
- package/autorest/codegen/models/parameter_list.py +355 -360
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +123 -139
- package/autorest/codegen/models/request_builder.py +130 -102
- package/autorest/codegen/models/request_builder_parameter.py +112 -100
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +12 -19
- package/autorest/codegen/serializers/__init__.py +55 -37
- package/autorest/codegen/serializers/builder_serializer.py +695 -1144
- package/autorest/codegen/serializers/client_serializer.py +92 -89
- package/autorest/codegen/serializers/general_serializer.py +15 -69
- package/autorest/codegen/serializers/import_serializer.py +7 -4
- package/autorest/codegen/serializers/metadata_serializer.py +15 -104
- package/autorest/codegen/serializers/model_base_serializer.py +49 -36
- package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
- package/autorest/codegen/serializers/model_init_serializer.py +2 -4
- package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
- package/autorest/codegen/serializers/operation_groups_serializer.py +7 -13
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/request_builders_serializer.py +13 -30
- package/autorest/codegen/serializers/utils.py +0 -140
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +10 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +6 -8
- package/autorest/codegen/templates/operation_group.py.jinja2 +21 -8
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_tools.jinja2 +11 -3
- package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +10 -15
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
- package/autorest/codegen/templates/setup.py.jinja2 +13 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +11 -1
- package/autorest/jsonrpc/server.py +15 -3
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/models/client.py +12 -2
- package/autorest/multiapi/models/code_model.py +1 -1
- package/autorest/multiapi/serializers/__init__.py +18 -4
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +21 -16
- package/package.json +2 -2
- package/autorest/codegen/models/credential_model.py +0 -55
- package/autorest/codegen/models/credential_schema.py +0 -95
- package/autorest/codegen/models/credential_schema_policy.py +0 -73
- package/autorest/codegen/models/dictionary_schema.py +0 -106
- package/autorest/codegen/models/enum_schema.py +0 -225
- package/autorest/codegen/models/list_schema.py +0 -135
- package/autorest/codegen/models/object_schema.py +0 -303
- package/autorest/codegen/models/primitive_schemas.py +0 -495
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
- package/autorest/codegen/models/schema_request.py +0 -55
- package/autorest/codegen/models/schema_response.py +0 -141
- package/autorest/namer/__init__.py +0 -23
- package/autorest/namer/name_converter.py +0 -509
|
@@ -3,26 +3,48 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import
|
|
7
|
-
|
|
8
|
-
from .
|
|
6
|
+
from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union
|
|
7
|
+
|
|
8
|
+
from .base_model import BaseModel
|
|
9
|
+
from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
|
|
10
|
+
from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
11
|
+
from .utils import add_to_pylint_disable
|
|
12
|
+
|
|
13
|
+
ParameterListType = TypeVar(
|
|
14
|
+
"ParameterListType",
|
|
15
|
+
bound=Union[ClientGlobalParameterList, ConfigGlobalParameterList],
|
|
16
|
+
)
|
|
9
17
|
|
|
10
18
|
if TYPE_CHECKING:
|
|
11
19
|
from .code_model import CodeModel
|
|
12
20
|
|
|
13
21
|
|
|
14
|
-
class
|
|
15
|
-
"""
|
|
22
|
+
class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
23
|
+
"""The service client base. Shared across our Client and Config type"""
|
|
16
24
|
|
|
17
|
-
def __init__(
|
|
18
|
-
self
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
yaml_data: Dict[str, Any],
|
|
28
|
+
code_model: "CodeModel",
|
|
29
|
+
parameters: ParameterListType,
|
|
30
|
+
):
|
|
31
|
+
super().__init__(yaml_data, code_model)
|
|
19
32
|
self.parameters = parameters
|
|
20
|
-
self.
|
|
21
|
-
|
|
33
|
+
self.url: str = self.yaml_data[
|
|
34
|
+
"url"
|
|
35
|
+
] # the base endpoint of the client. Can be parameterized or not
|
|
22
36
|
|
|
23
37
|
@property
|
|
24
|
-
def
|
|
25
|
-
return
|
|
38
|
+
def description(self) -> str:
|
|
39
|
+
return self.yaml_data["description"]
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def name(self) -> str:
|
|
43
|
+
return self.yaml_data["name"]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
47
|
+
"""Model representing our service client"""
|
|
26
48
|
|
|
27
49
|
def pipeline_class(self, async_mode: bool) -> str:
|
|
28
50
|
if self.code_model.options["azure_arm"]:
|
|
@@ -33,31 +55,43 @@ class Client:
|
|
|
33
55
|
return "AsyncPipelineClient"
|
|
34
56
|
return "PipelineClient"
|
|
35
57
|
|
|
58
|
+
@property
|
|
59
|
+
def send_request_name(self) -> str:
|
|
60
|
+
"""Name of the send request function"""
|
|
61
|
+
return (
|
|
62
|
+
"send_request"
|
|
63
|
+
if self.code_model.options["show_send_request"]
|
|
64
|
+
else "_send_request"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def has_parameterized_host(self) -> bool:
|
|
69
|
+
"""Whether the base url is parameterized or not"""
|
|
70
|
+
return not any(p for p in self.parameters if p.is_host)
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def pylint_disable(self) -> str:
|
|
74
|
+
retval = add_to_pylint_disable("", "client-accepts-api-version-keyword")
|
|
75
|
+
if len(self.code_model.operation_groups) > 6:
|
|
76
|
+
retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
|
|
77
|
+
return retval
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def filename(self) -> str:
|
|
81
|
+
"""Name of the file for the client"""
|
|
82
|
+
if (
|
|
83
|
+
self.code_model.options["version_tolerant"]
|
|
84
|
+
or self.code_model.options["low_level_client"]
|
|
85
|
+
):
|
|
86
|
+
return "_client"
|
|
87
|
+
return f"_{self.code_model.module_name}"
|
|
88
|
+
|
|
36
89
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
37
90
|
file_import = FileImport()
|
|
38
91
|
|
|
39
|
-
file_import.add_submodule_import("msrest", "Serializer", ImportType.THIRDPARTY)
|
|
40
|
-
file_import.add_submodule_import(
|
|
41
|
-
"msrest", "Deserializer", ImportType.THIRDPARTY
|
|
42
|
-
)
|
|
43
92
|
file_import.add_submodule_import(
|
|
44
93
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
45
94
|
)
|
|
46
|
-
|
|
47
|
-
any_optional_gp = any(not gp.required for gp in self.parameters)
|
|
48
|
-
|
|
49
|
-
legacy = not any(
|
|
50
|
-
g
|
|
51
|
-
for g in ["low_level_client", "version_tolerant"]
|
|
52
|
-
if g in self.code_model.options
|
|
53
|
-
)
|
|
54
|
-
if any_optional_gp or (
|
|
55
|
-
legacy and self.code_model.service_client.parameters.host
|
|
56
|
-
):
|
|
57
|
-
file_import.add_submodule_import(
|
|
58
|
-
"typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
59
|
-
)
|
|
60
|
-
|
|
61
95
|
if self.code_model.options["azure_arm"]:
|
|
62
96
|
file_import.add_submodule_import(
|
|
63
97
|
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.AZURECORE
|
|
@@ -67,14 +101,21 @@ class Client:
|
|
|
67
101
|
"azure.core", self.pipeline_class(async_mode), ImportType.AZURECORE
|
|
68
102
|
)
|
|
69
103
|
|
|
70
|
-
for gp in self.
|
|
71
|
-
file_import.merge(gp.imports())
|
|
104
|
+
for gp in self.parameters:
|
|
105
|
+
file_import.merge(gp.imports(async_mode))
|
|
72
106
|
file_import.add_submodule_import(
|
|
73
107
|
"._configuration",
|
|
74
|
-
f"{self.code_model.
|
|
108
|
+
f"{self.code_model.client.name}Configuration",
|
|
75
109
|
ImportType.LOCAL,
|
|
76
110
|
)
|
|
77
111
|
|
|
112
|
+
file_import.add_msrest_import(
|
|
113
|
+
self.code_model,
|
|
114
|
+
".." if async_mode else ".",
|
|
115
|
+
MsrestImportType.SerializerDeserializer,
|
|
116
|
+
TypingSection.REGULAR,
|
|
117
|
+
)
|
|
118
|
+
|
|
78
119
|
return file_import
|
|
79
120
|
|
|
80
121
|
def imports(self, async_mode: bool) -> FileImport:
|
|
@@ -107,9 +148,25 @@ class Client:
|
|
|
107
148
|
ImportType.LOCAL,
|
|
108
149
|
)
|
|
109
150
|
|
|
110
|
-
if self.code_model.
|
|
151
|
+
if self.code_model.model_types and self.code_model.options["models_mode"]:
|
|
111
152
|
path_to_models = ".." if async_mode else "."
|
|
112
|
-
|
|
153
|
+
if len(self.code_model.model_types) != len(
|
|
154
|
+
self.code_model.public_model_types
|
|
155
|
+
):
|
|
156
|
+
# this means we have hidden models. In that case, we import directly from the models
|
|
157
|
+
# file, not the module, bc we don't expose the hidden models in the models module
|
|
158
|
+
|
|
159
|
+
# Also in this case, we're in version tolerant, so python3 only is true
|
|
160
|
+
file_import.add_submodule_import(
|
|
161
|
+
f"{path_to_models}models",
|
|
162
|
+
f"{self.code_model.get_models_filename(is_python3_file=True)}",
|
|
163
|
+
ImportType.LOCAL,
|
|
164
|
+
alias="models",
|
|
165
|
+
)
|
|
166
|
+
else:
|
|
167
|
+
file_import.add_submodule_import(
|
|
168
|
+
path_to_models, "models", ImportType.LOCAL
|
|
169
|
+
)
|
|
113
170
|
else:
|
|
114
171
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
115
172
|
# this import will always be commented, so will always add it to the typing section
|
|
@@ -121,34 +178,89 @@ class Client:
|
|
|
121
178
|
|
|
122
179
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
123
180
|
file_import = self._imports_shared(async_mode)
|
|
181
|
+
file_import.add_submodule_import(
|
|
182
|
+
"typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
183
|
+
)
|
|
124
184
|
try:
|
|
125
185
|
mixin_operation = next(
|
|
126
|
-
og
|
|
127
|
-
for og in self.code_model.operation_groups
|
|
128
|
-
if og.is_empty_operation_group
|
|
186
|
+
og for og in self.code_model.operation_groups if og.is_mixin
|
|
129
187
|
)
|
|
130
188
|
file_import.add_submodule_import(
|
|
131
189
|
"._operations_mixin", mixin_operation.class_name, ImportType.LOCAL
|
|
132
190
|
)
|
|
133
191
|
except StopIteration:
|
|
134
192
|
pass
|
|
193
|
+
file_import.add_submodule_import(
|
|
194
|
+
"azure.profiles", "KnownProfiles", import_type=ImportType.AZURECORE
|
|
195
|
+
)
|
|
196
|
+
file_import.add_submodule_import(
|
|
197
|
+
"azure.profiles", "ProfileDefinition", import_type=ImportType.AZURECORE
|
|
198
|
+
)
|
|
199
|
+
file_import.add_submodule_import(
|
|
200
|
+
"azure.profiles.multiapiclient",
|
|
201
|
+
"MultiApiClientMixin",
|
|
202
|
+
import_type=ImportType.AZURECORE,
|
|
203
|
+
)
|
|
135
204
|
return file_import
|
|
136
205
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return request_signature + self.parameters.method_signature_kwargs(
|
|
144
|
-
is_python3_file
|
|
206
|
+
@classmethod
|
|
207
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Client":
|
|
208
|
+
return cls(
|
|
209
|
+
yaml_data=yaml_data,
|
|
210
|
+
code_model=code_model,
|
|
211
|
+
parameters=ClientGlobalParameterList.from_yaml(yaml_data, code_model),
|
|
145
212
|
)
|
|
146
213
|
|
|
214
|
+
|
|
215
|
+
class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
216
|
+
"""Model representing our Config type."""
|
|
217
|
+
|
|
147
218
|
@property
|
|
148
|
-
def
|
|
149
|
-
|
|
150
|
-
self.
|
|
151
|
-
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
219
|
+
def description(self) -> str:
|
|
220
|
+
return (
|
|
221
|
+
f"Configuration for {self.yaml_data['name']}.\n\n."
|
|
222
|
+
"Note that all parameters used to create this instance are saved as instance attributes."
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def name(self) -> str:
|
|
227
|
+
return f"{super().name}Configuration"
|
|
228
|
+
|
|
229
|
+
def imports(self, async_mode: bool) -> FileImport:
|
|
230
|
+
file_import = FileImport()
|
|
231
|
+
file_import.add_submodule_import(
|
|
232
|
+
"azure.core.configuration", "Configuration", ImportType.AZURECORE
|
|
233
|
+
)
|
|
234
|
+
file_import.add_submodule_import(
|
|
235
|
+
"azure.core.pipeline", "policies", ImportType.AZURECORE
|
|
236
|
+
)
|
|
237
|
+
file_import.add_submodule_import(
|
|
238
|
+
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
239
|
+
)
|
|
240
|
+
if self.code_model.options["package_version"]:
|
|
241
|
+
file_import.add_submodule_import(
|
|
242
|
+
".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL
|
|
243
|
+
)
|
|
244
|
+
for gp in self.parameters:
|
|
245
|
+
file_import.merge(gp.imports(async_mode=async_mode))
|
|
246
|
+
if self.code_model.options["azure_arm"]:
|
|
247
|
+
policy = (
|
|
248
|
+
"AsyncARMChallengeAuthenticationPolicy"
|
|
249
|
+
if async_mode
|
|
250
|
+
else "ARMChallengeAuthenticationPolicy"
|
|
251
|
+
)
|
|
252
|
+
file_import.add_submodule_import(
|
|
253
|
+
"azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.AZURECORE
|
|
254
|
+
)
|
|
255
|
+
file_import.add_submodule_import(
|
|
256
|
+
"azure.mgmt.core.policies", policy, ImportType.AZURECORE
|
|
257
|
+
)
|
|
258
|
+
return file_import
|
|
259
|
+
|
|
260
|
+
@classmethod
|
|
261
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Config":
|
|
262
|
+
return cls(
|
|
263
|
+
yaml_data=yaml_data,
|
|
264
|
+
code_model=code_model,
|
|
265
|
+
parameters=ConfigGlobalParameterList.from_yaml(yaml_data, code_model),
|
|
266
|
+
)
|