@autorest/python 6.13.16 → 6.13.18
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/autorest/__init__.py +4 -12
- package/autorest/_utils.py +5 -20
- package/autorest/black/__init__.py +1 -3
- package/autorest/codegen/__init__.py +29 -96
- package/autorest/codegen/models/__init__.py +1 -3
- package/autorest/codegen/models/base.py +2 -6
- package/autorest/codegen/models/base_builder.py +2 -6
- package/autorest/codegen/models/client.py +24 -86
- package/autorest/codegen/models/code_model.py +13 -53
- package/autorest/codegen/models/combined_type.py +3 -9
- package/autorest/codegen/models/constant_type.py +4 -14
- package/autorest/codegen/models/credential_types.py +11 -35
- package/autorest/codegen/models/dictionary_type.py +4 -12
- package/autorest/codegen/models/enum_type.py +10 -31
- package/autorest/codegen/models/imports.py +15 -41
- package/autorest/codegen/models/list_type.py +7 -23
- package/autorest/codegen/models/lro_operation.py +6 -18
- package/autorest/codegen/models/lro_paging_operation.py +1 -3
- package/autorest/codegen/models/model_type.py +21 -73
- package/autorest/codegen/models/operation.py +41 -139
- package/autorest/codegen/models/operation_group.py +21 -60
- package/autorest/codegen/models/paging_operation.py +13 -43
- package/autorest/codegen/models/parameter.py +16 -54
- package/autorest/codegen/models/parameter_list.py +27 -103
- package/autorest/codegen/models/primitive_types.py +15 -49
- package/autorest/codegen/models/property.py +8 -28
- package/autorest/codegen/models/request_builder.py +11 -39
- package/autorest/codegen/models/request_builder_parameter.py +4 -13
- package/autorest/codegen/models/response.py +16 -57
- package/autorest/codegen/serializers/__init__.py +46 -150
- package/autorest/codegen/serializers/builder_serializer.py +113 -402
- package/autorest/codegen/serializers/client_serializer.py +25 -78
- package/autorest/codegen/serializers/enum_serializer.py +1 -3
- package/autorest/codegen/serializers/general_serializer.py +6 -22
- package/autorest/codegen/serializers/import_serializer.py +13 -40
- package/autorest/codegen/serializers/metadata_serializer.py +7 -21
- package/autorest/codegen/serializers/model_init_serializer.py +1 -5
- package/autorest/codegen/serializers/model_serializer.py +13 -51
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -3
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -8
- package/autorest/codegen/serializers/parameter_serializer.py +8 -26
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -3
- package/autorest/codegen/serializers/sample_serializer.py +13 -39
- package/autorest/codegen/serializers/test_serializer.py +10 -30
- package/autorest/codegen/serializers/types_serializer.py +1 -3
- package/autorest/codegen/templates/serialization.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +1 -3
- package/autorest/jsonrpc/server.py +3 -9
- package/autorest/jsonrpc/stdstream.py +4 -12
- package/autorest/m2r/__init__.py +2 -6
- package/autorest/m4reformatter/__init__.py +72 -237
- package/autorest/multiapi/__init__.py +4 -11
- package/autorest/multiapi/models/client.py +7 -21
- package/autorest/multiapi/models/code_model.py +9 -28
- package/autorest/multiapi/models/config.py +1 -3
- package/autorest/multiapi/models/global_parameters.py +6 -16
- package/autorest/multiapi/models/imports.py +5 -9
- package/autorest/multiapi/models/operation_mixin_group.py +5 -17
- package/autorest/multiapi/serializers/__init__.py +10 -31
- package/autorest/multiapi/serializers/import_serializer.py +8 -24
- package/autorest/multiapi/utils.py +2 -6
- package/autorest/multiclient/__init__.py +1 -3
- package/autorest/postprocess/__init__.py +9 -29
- package/autorest/postprocess/get_all.py +1 -3
- package/autorest/postprocess/venvtools.py +1 -3
- package/autorest/preprocess/__init__.py +43 -129
- package/install.py +2 -0
- package/package.json +1 -1
- package/prepare.py +3 -1
- package/requirements.txt +1 -1
- package/run_cadl.py +1 -3
- package/setup.py +25 -25
- package/start.py +2 -0
- package/venvtools.py +15 -10
|
@@ -34,9 +34,7 @@ class ResponseHeader(BaseModel):
|
|
|
34
34
|
return self.type.serialization_type
|
|
35
35
|
|
|
36
36
|
@classmethod
|
|
37
|
-
def from_yaml(
|
|
38
|
-
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
39
|
-
) -> "ResponseHeader":
|
|
37
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "ResponseHeader":
|
|
40
38
|
from . import build_type
|
|
41
39
|
|
|
42
40
|
return cls(
|
|
@@ -141,35 +139,21 @@ class Response(BaseModel):
|
|
|
141
139
|
# helper function to return imports for responses based off
|
|
142
140
|
# of whether we're importing from the core library, or users
|
|
143
141
|
# are customizing responses
|
|
144
|
-
return (
|
|
145
|
-
ImportType.SDKCORE
|
|
146
|
-
if self.code_model.core_library.split(".")[0] in input_path
|
|
147
|
-
else ImportType.THIRDPARTY
|
|
148
|
-
)
|
|
142
|
+
return ImportType.SDKCORE if self.code_model.core_library.split(".")[0] in input_path else ImportType.THIRDPARTY
|
|
149
143
|
|
|
150
144
|
@classmethod
|
|
151
|
-
def from_yaml(
|
|
152
|
-
|
|
153
|
-
) -> "Response":
|
|
154
|
-
type = (
|
|
155
|
-
code_model.lookup_type(id(yaml_data["type"]))
|
|
156
|
-
if yaml_data.get("type")
|
|
157
|
-
else None
|
|
158
|
-
)
|
|
145
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Response":
|
|
146
|
+
type = code_model.lookup_type(id(yaml_data["type"])) if yaml_data.get("type") else None
|
|
159
147
|
# use ByteIteratorType if we are returning a binary type
|
|
160
148
|
default_content_type = yaml_data.get("defaultContentType", "application/json")
|
|
161
149
|
if isinstance(type, BinaryType) or (
|
|
162
|
-
isinstance(type, ByteArraySchema)
|
|
163
|
-
and default_content_type != "application/json"
|
|
150
|
+
isinstance(type, ByteArraySchema) and default_content_type != "application/json"
|
|
164
151
|
):
|
|
165
152
|
type = BinaryIteratorType(type.yaml_data, type.code_model)
|
|
166
153
|
return cls(
|
|
167
154
|
yaml_data=yaml_data,
|
|
168
155
|
code_model=code_model,
|
|
169
|
-
headers=[
|
|
170
|
-
ResponseHeader.from_yaml(header, code_model)
|
|
171
|
-
for header in yaml_data["headers"]
|
|
172
|
-
],
|
|
156
|
+
headers=[ResponseHeader.from_yaml(header, code_model) for header in yaml_data["headers"]],
|
|
173
157
|
type=type,
|
|
174
158
|
)
|
|
175
159
|
|
|
@@ -181,13 +165,8 @@ class PagingResponse(Response):
|
|
|
181
165
|
def __init__(self, *args, **kwargs) -> None:
|
|
182
166
|
super().__init__(*args, **kwargs)
|
|
183
167
|
self.item_type = self.code_model.lookup_type(id(self.yaml_data["itemType"]))
|
|
184
|
-
self.pager_sync: str = (
|
|
185
|
-
|
|
186
|
-
or f"{self.code_model.core_library}.paging.ItemPaged"
|
|
187
|
-
)
|
|
188
|
-
default_paging_submodule = (
|
|
189
|
-
f"{'async_' if self.code_model.is_azure_flavor else ''}paging"
|
|
190
|
-
)
|
|
168
|
+
self.pager_sync: str = self.yaml_data.get("pagerSync") or f"{self.code_model.core_library}.paging.ItemPaged"
|
|
169
|
+
default_paging_submodule = f"{'async_' if self.code_model.is_azure_flavor else ''}paging"
|
|
191
170
|
self.pager_async: str = (
|
|
192
171
|
self.yaml_data.get("pagerAsync")
|
|
193
172
|
or f"{self.code_model.core_library}.{default_paging_submodule}.AsyncItemPaged"
|
|
@@ -227,9 +206,7 @@ class PagingResponse(Response):
|
|
|
227
206
|
pager = self.get_pager(async_mode)
|
|
228
207
|
pager_path = self.get_pager_import_path(async_mode)
|
|
229
208
|
|
|
230
|
-
file_import.add_submodule_import(
|
|
231
|
-
pager_path, pager, self._get_import_type(pager_path)
|
|
232
|
-
)
|
|
209
|
+
file_import.add_submodule_import(pager_path, pager, self._get_import_type(pager_path))
|
|
233
210
|
return file_import
|
|
234
211
|
|
|
235
212
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
@@ -250,11 +227,7 @@ class PagingResponse(Response):
|
|
|
250
227
|
|
|
251
228
|
class LROResponse(Response):
|
|
252
229
|
def get_poller_path(self, async_mode: bool) -> str:
|
|
253
|
-
return
|
|
254
|
-
self.yaml_data["pollerAsync"]
|
|
255
|
-
if async_mode
|
|
256
|
-
else self.yaml_data["pollerSync"]
|
|
257
|
-
)
|
|
230
|
+
return self.yaml_data["pollerAsync"] if async_mode else self.yaml_data["pollerSync"]
|
|
258
231
|
|
|
259
232
|
def get_poller(self, async_mode: bool) -> str:
|
|
260
233
|
"""Get the name of the poller. Default is LROPoller / AsyncLROPoller"""
|
|
@@ -262,11 +235,7 @@ class LROResponse(Response):
|
|
|
262
235
|
|
|
263
236
|
def get_polling_method_path(self, async_mode: bool) -> str:
|
|
264
237
|
"""Get the full name of the poller path. Default are the azure core pollers"""
|
|
265
|
-
return
|
|
266
|
-
self.yaml_data["pollingMethodAsync"]
|
|
267
|
-
if async_mode
|
|
268
|
-
else self.yaml_data["pollingMethodSync"]
|
|
269
|
-
)
|
|
238
|
+
return self.yaml_data["pollingMethodAsync"] if async_mode else self.yaml_data["pollingMethodSync"]
|
|
270
239
|
|
|
271
240
|
def get_polling_method(self, async_mode: bool) -> str:
|
|
272
241
|
"""Get the default pollint method"""
|
|
@@ -308,27 +277,21 @@ class LROResponse(Response):
|
|
|
308
277
|
async_mode = kwargs["async_mode"]
|
|
309
278
|
poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
|
|
310
279
|
poller = self.get_poller(async_mode)
|
|
311
|
-
file_import.add_submodule_import(
|
|
312
|
-
poller_import_path, poller, self._get_import_type(poller_import_path)
|
|
313
|
-
)
|
|
280
|
+
file_import.add_submodule_import(poller_import_path, poller, self._get_import_type(poller_import_path))
|
|
314
281
|
return file_import
|
|
315
282
|
|
|
316
283
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
317
284
|
file_import = self._imports_shared(**kwargs)
|
|
318
285
|
async_mode = kwargs["async_mode"]
|
|
319
286
|
|
|
320
|
-
default_polling_method_import_path = ".".join(
|
|
321
|
-
self.get_polling_method_path(async_mode).split(".")[:-1]
|
|
322
|
-
)
|
|
287
|
+
default_polling_method_import_path = ".".join(self.get_polling_method_path(async_mode).split(".")[:-1])
|
|
323
288
|
default_polling_method = self.get_polling_method(async_mode)
|
|
324
289
|
file_import.add_submodule_import(
|
|
325
290
|
default_polling_method_import_path,
|
|
326
291
|
default_polling_method,
|
|
327
292
|
self._get_import_type(default_polling_method_import_path),
|
|
328
293
|
)
|
|
329
|
-
default_no_polling_method_import_path = ".".join(
|
|
330
|
-
self.get_no_polling_method_path(async_mode).split(".")[:-1]
|
|
331
|
-
)
|
|
294
|
+
default_no_polling_method_import_path = ".".join(self.get_no_polling_method_path(async_mode).split(".")[:-1])
|
|
332
295
|
default_no_polling_method = self.get_no_polling_method(async_mode)
|
|
333
296
|
file_import.add_submodule_import(
|
|
334
297
|
default_no_polling_method_import_path,
|
|
@@ -336,9 +299,7 @@ class LROResponse(Response):
|
|
|
336
299
|
self._get_import_type(default_no_polling_method_import_path),
|
|
337
300
|
)
|
|
338
301
|
|
|
339
|
-
base_polling_method_import_path = ".".join(
|
|
340
|
-
self.get_base_polling_method_path(async_mode).split(".")[:-1]
|
|
341
|
-
)
|
|
302
|
+
base_polling_method_import_path = ".".join(self.get_base_polling_method_path(async_mode).split(".")[:-1])
|
|
342
303
|
base_polling_method = self.get_base_polling_method(async_mode)
|
|
343
304
|
file_import.add_submodule_import(
|
|
344
305
|
base_polling_method_import_path,
|
|
@@ -361,9 +322,7 @@ class LROPagingResponse(LROResponse, PagingResponse):
|
|
|
361
322
|
return f"~{self.get_poller_path(kwargs.get('async_mode', False))}[{paging_docstring_type}]"
|
|
362
323
|
|
|
363
324
|
def docstring_text(self, **kwargs) -> str:
|
|
364
|
-
base_description =
|
|
365
|
-
"An instance of LROPoller that returns an iterator like instance of "
|
|
366
|
-
)
|
|
325
|
+
base_description = "An instance of LROPoller that returns an iterator like instance of "
|
|
367
326
|
if not self.code_model.options["version_tolerant"]:
|
|
368
327
|
base_description += "either "
|
|
369
328
|
return base_description + Response.docstring_text(self)
|
|
@@ -80,19 +80,13 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
80
80
|
|
|
81
81
|
@property
|
|
82
82
|
def has_aio_folder(self) -> bool:
|
|
83
|
-
return not self.code_model.options["no_async"] and bool(
|
|
84
|
-
self.code_model.has_operations
|
|
85
|
-
)
|
|
83
|
+
return not self.code_model.options["no_async"] and bool(self.code_model.has_operations)
|
|
86
84
|
|
|
87
85
|
@property
|
|
88
86
|
def has_operations_folder(self) -> bool:
|
|
89
|
-
return self.code_model.options["show_operations"] and bool(
|
|
90
|
-
self.code_model.has_operations
|
|
91
|
-
)
|
|
87
|
+
return self.code_model.options["show_operations"] and bool(self.code_model.has_operations)
|
|
92
88
|
|
|
93
|
-
def _serialize_namespace_level(
|
|
94
|
-
self, env: Environment, namespace_path: Path, clients: List[Client]
|
|
95
|
-
) -> None:
|
|
89
|
+
def _serialize_namespace_level(self, env: Environment, namespace_path: Path, clients: List[Client]) -> None:
|
|
96
90
|
# if there was a patch file before, we keep it
|
|
97
91
|
self._keep_patch_file(namespace_path / Path("_patch.py"), env)
|
|
98
92
|
if self.has_aio_folder:
|
|
@@ -100,28 +94,19 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
100
94
|
|
|
101
95
|
if self.has_operations_folder:
|
|
102
96
|
self._keep_patch_file(
|
|
103
|
-
namespace_path
|
|
104
|
-
/ Path(self.code_model.operations_folder_name)
|
|
105
|
-
/ Path("_patch.py"),
|
|
97
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path("_patch.py"),
|
|
106
98
|
env,
|
|
107
99
|
)
|
|
108
100
|
if self.has_aio_folder:
|
|
109
101
|
self._keep_patch_file(
|
|
110
|
-
namespace_path
|
|
111
|
-
/ Path("aio")
|
|
112
|
-
/ Path(self.code_model.operations_folder_name)
|
|
113
|
-
/ Path("_patch.py"),
|
|
102
|
+
namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("_patch.py"),
|
|
114
103
|
env,
|
|
115
104
|
)
|
|
116
|
-
self._serialize_and_write_top_level_folder(
|
|
117
|
-
env=env, namespace_path=namespace_path, clients=clients
|
|
118
|
-
)
|
|
105
|
+
self._serialize_and_write_top_level_folder(env=env, namespace_path=namespace_path, clients=clients)
|
|
119
106
|
|
|
120
107
|
if any(c for c in self.code_model.clients if c.operation_groups):
|
|
121
108
|
if self.code_model.options["builders_visibility"] != "embedded":
|
|
122
|
-
self._serialize_and_write_rest_layer(
|
|
123
|
-
env=env, namespace_path=namespace_path
|
|
124
|
-
)
|
|
109
|
+
self._serialize_and_write_rest_layer(env=env, namespace_path=namespace_path)
|
|
125
110
|
if self.has_aio_folder:
|
|
126
111
|
self._serialize_and_write_aio_top_level_folder(
|
|
127
112
|
env=env,
|
|
@@ -130,13 +115,9 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
130
115
|
)
|
|
131
116
|
|
|
132
117
|
if self.has_operations_folder:
|
|
133
|
-
self._serialize_and_write_operations_folder(
|
|
134
|
-
clients, env=env, namespace_path=namespace_path
|
|
135
|
-
)
|
|
118
|
+
self._serialize_and_write_operations_folder(clients, env=env, namespace_path=namespace_path)
|
|
136
119
|
if self.code_model.options["multiapi"]:
|
|
137
|
-
self._serialize_and_write_metadata(
|
|
138
|
-
env=env, namespace_path=namespace_path
|
|
139
|
-
)
|
|
120
|
+
self._serialize_and_write_metadata(env=env, namespace_path=namespace_path)
|
|
140
121
|
if self.code_model.options["package_mode"]:
|
|
141
122
|
self._serialize_and_write_package_files(namespace_path=namespace_path)
|
|
142
123
|
|
|
@@ -166,15 +147,11 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
166
147
|
)
|
|
167
148
|
|
|
168
149
|
namespace_path = (
|
|
169
|
-
Path(".")
|
|
170
|
-
if self.code_model.options["no_namespace_folders"]
|
|
171
|
-
else Path(*self._name_space().split("."))
|
|
150
|
+
Path(".") if self.code_model.options["no_namespace_folders"] else Path(*self._name_space().split("."))
|
|
172
151
|
)
|
|
173
152
|
|
|
174
153
|
p = namespace_path.parent
|
|
175
|
-
general_serializer = GeneralSerializer(
|
|
176
|
-
code_model=self.code_model, env=env, async_mode=False
|
|
177
|
-
)
|
|
154
|
+
general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
178
155
|
while p != Path("."):
|
|
179
156
|
# write pkgutil init file
|
|
180
157
|
self.write_file(
|
|
@@ -195,23 +172,13 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
195
172
|
clients,
|
|
196
173
|
) in self.code_model.subnamespace_to_clients.items():
|
|
197
174
|
subnamespace_path = namespace_path / Path(subnamespace)
|
|
198
|
-
self._serialize_namespace_level(
|
|
199
|
-
env, subnamespace_path, [c for c in clients if c.has_operations]
|
|
200
|
-
)
|
|
175
|
+
self._serialize_namespace_level(env, subnamespace_path, [c for c in clients if c.has_operations])
|
|
201
176
|
|
|
202
|
-
if self.code_model.options["models_mode"] and (
|
|
203
|
-
self.
|
|
204
|
-
):
|
|
205
|
-
self._keep_patch_file(
|
|
206
|
-
namespace_path / Path("models") / Path("_patch.py"), env
|
|
207
|
-
)
|
|
177
|
+
if self.code_model.options["models_mode"] and (self.code_model.model_types or self.code_model.enums):
|
|
178
|
+
self._keep_patch_file(namespace_path / Path("models") / Path("_patch.py"), env)
|
|
208
179
|
|
|
209
|
-
if self.code_model.options["models_mode"] and (
|
|
210
|
-
self.
|
|
211
|
-
):
|
|
212
|
-
self._serialize_and_write_models_folder(
|
|
213
|
-
env=env, namespace_path=namespace_path
|
|
214
|
-
)
|
|
180
|
+
if self.code_model.options["models_mode"] and (self.code_model.model_types or self.code_model.enums):
|
|
181
|
+
self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path)
|
|
215
182
|
if not self.code_model.options["models_mode"]:
|
|
216
183
|
# keep models file if users ended up just writing a models file
|
|
217
184
|
if self.read_file(namespace_path / Path("models.py")):
|
|
@@ -229,18 +196,14 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
229
196
|
root_of_sdk = self._package_root_folder(namespace_path)
|
|
230
197
|
if self.code_model.options["package_mode"] in VALID_PACKAGE_MODE:
|
|
231
198
|
env = Environment(
|
|
232
|
-
loader=PackageLoader(
|
|
233
|
-
"autorest.codegen", "templates/packaging_templates"
|
|
234
|
-
),
|
|
199
|
+
loader=PackageLoader("autorest.codegen", "templates/packaging_templates"),
|
|
235
200
|
undefined=StrictUndefined,
|
|
236
201
|
)
|
|
237
202
|
|
|
238
203
|
package_files = _PACKAGE_FILES
|
|
239
204
|
elif Path(self.code_model.options["package_mode"]).exists():
|
|
240
205
|
env = Environment(
|
|
241
|
-
loader=FileSystemLoader(
|
|
242
|
-
str(Path(self.code_model.options["package_mode"]))
|
|
243
|
-
),
|
|
206
|
+
loader=FileSystemLoader(str(Path(self.code_model.options["package_mode"]))),
|
|
244
207
|
keep_trailing_newline=True,
|
|
245
208
|
undefined=StrictUndefined,
|
|
246
209
|
)
|
|
@@ -250,10 +213,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
250
213
|
serializer = GeneralSerializer(self.code_model, env, async_mode=False)
|
|
251
214
|
params = self.code_model.options["packaging_files_config"] or {}
|
|
252
215
|
for template_name in package_files:
|
|
253
|
-
if
|
|
254
|
-
not self.code_model.is_azure_flavor
|
|
255
|
-
and template_name == "dev_requirements.txt.jinja2"
|
|
256
|
-
):
|
|
216
|
+
if not self.code_model.is_azure_flavor and template_name == "dev_requirements.txt.jinja2":
|
|
257
217
|
continue
|
|
258
218
|
file = template_name.replace(".jinja2", "")
|
|
259
219
|
output_name = root_of_sdk / file
|
|
@@ -272,16 +232,10 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
272
232
|
PatchSerializer(env=env, code_model=self.code_model).serialize(),
|
|
273
233
|
)
|
|
274
234
|
|
|
275
|
-
def _serialize_and_write_models_folder(
|
|
276
|
-
self, env: Environment, namespace_path: Path
|
|
277
|
-
) -> None:
|
|
235
|
+
def _serialize_and_write_models_folder(self, env: Environment, namespace_path: Path) -> None:
|
|
278
236
|
# Write the models folder
|
|
279
237
|
models_path = namespace_path / Path("models")
|
|
280
|
-
serializer =
|
|
281
|
-
DpgModelSerializer
|
|
282
|
-
if self.code_model.options["models_mode"] == "dpg"
|
|
283
|
-
else MsrestModelSerializer
|
|
284
|
-
)
|
|
238
|
+
serializer = DpgModelSerializer if self.code_model.options["models_mode"] == "dpg" else MsrestModelSerializer
|
|
285
239
|
if self.code_model.model_types:
|
|
286
240
|
self.write_file(
|
|
287
241
|
models_path / Path(f"{self.code_model.models_filename}.py"),
|
|
@@ -297,24 +251,15 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
297
251
|
ModelInitSerializer(code_model=self.code_model, env=env).serialize(),
|
|
298
252
|
)
|
|
299
253
|
|
|
300
|
-
def _serialize_and_write_rest_layer(
|
|
301
|
-
self, env: Environment, namespace_path: Path
|
|
302
|
-
) -> None:
|
|
254
|
+
def _serialize_and_write_rest_layer(self, env: Environment, namespace_path: Path) -> None:
|
|
303
255
|
rest_path = namespace_path / Path(self.code_model.rest_layer_name)
|
|
304
|
-
group_names = {
|
|
305
|
-
rb.group_name for c in self.code_model.clients for rb in c.request_builders
|
|
306
|
-
}
|
|
256
|
+
group_names = {rb.group_name for c in self.code_model.clients for rb in c.request_builders}
|
|
307
257
|
|
|
308
258
|
for group_name in group_names:
|
|
309
259
|
request_builders = [
|
|
310
|
-
r
|
|
311
|
-
for c in self.code_model.clients
|
|
312
|
-
for r in c.request_builders
|
|
313
|
-
if r.group_name == group_name
|
|
260
|
+
r for c in self.code_model.clients for r in c.request_builders if r.group_name == group_name
|
|
314
261
|
]
|
|
315
|
-
self._serialize_and_write_single_rest_layer(
|
|
316
|
-
env, rest_path, request_builders
|
|
317
|
-
)
|
|
262
|
+
self._serialize_and_write_single_rest_layer(env, rest_path, request_builders)
|
|
318
263
|
if not "" in group_names:
|
|
319
264
|
self.write_file(
|
|
320
265
|
rest_path / Path("__init__.py"),
|
|
@@ -366,9 +311,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
366
311
|
operation_group=operation_group,
|
|
367
312
|
)
|
|
368
313
|
self.write_file(
|
|
369
|
-
namespace_path
|
|
370
|
-
/ Path(self.code_model.operations_folder_name)
|
|
371
|
-
/ Path(f"{filename}.py"),
|
|
314
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
372
315
|
operation_group_serializer.serialize(),
|
|
373
316
|
)
|
|
374
317
|
|
|
@@ -382,12 +325,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
382
325
|
operation_group=operation_group,
|
|
383
326
|
)
|
|
384
327
|
self.write_file(
|
|
385
|
-
(
|
|
386
|
-
namespace_path
|
|
387
|
-
/ Path("aio")
|
|
388
|
-
/ Path(self.code_model.operations_folder_name)
|
|
389
|
-
/ Path(f"{filename}.py")
|
|
390
|
-
),
|
|
328
|
+
(namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py")),
|
|
391
329
|
operation_group_async_serializer.serialize(),
|
|
392
330
|
)
|
|
393
331
|
|
|
@@ -399,9 +337,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
399
337
|
code_model=self.code_model, clients=clients, env=env, async_mode=False
|
|
400
338
|
)
|
|
401
339
|
self.write_file(
|
|
402
|
-
namespace_path
|
|
403
|
-
/ Path(self.code_model.operations_folder_name)
|
|
404
|
-
/ Path("__init__.py"),
|
|
340
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
405
341
|
operations_init_serializer.serialize(),
|
|
406
342
|
)
|
|
407
343
|
|
|
@@ -411,10 +347,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
411
347
|
code_model=self.code_model, clients=clients, env=env, async_mode=True
|
|
412
348
|
)
|
|
413
349
|
self.write_file(
|
|
414
|
-
namespace_path
|
|
415
|
-
/ Path("aio")
|
|
416
|
-
/ Path(self.code_model.operations_folder_name)
|
|
417
|
-
/ Path("__init__.py"),
|
|
350
|
+
namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
418
351
|
operations_async_init_serializer.serialize(),
|
|
419
352
|
)
|
|
420
353
|
|
|
@@ -425,9 +358,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
425
358
|
clients=clients,
|
|
426
359
|
)
|
|
427
360
|
else:
|
|
428
|
-
for operation_group in get_all_operation_groups_recursively(
|
|
429
|
-
self.code_model.clients
|
|
430
|
-
):
|
|
361
|
+
for operation_group in get_all_operation_groups_recursively(self.code_model.clients):
|
|
431
362
|
self._serialize_and_write_operations_file(
|
|
432
363
|
env=env,
|
|
433
364
|
namespace_path=namespace_path,
|
|
@@ -468,9 +399,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
468
399
|
clients: List[Client],
|
|
469
400
|
) -> None:
|
|
470
401
|
if self.code_model.has_operations:
|
|
471
|
-
namespace_path = (
|
|
472
|
-
namespace_path / Path("aio") if async_mode else namespace_path
|
|
473
|
-
)
|
|
402
|
+
namespace_path = namespace_path / Path("aio") if async_mode else namespace_path
|
|
474
403
|
self.write_file(
|
|
475
404
|
namespace_path / Path(f"{self.code_model.client_filename}.py"),
|
|
476
405
|
general_serializer.serialize_service_client_file(clients),
|
|
@@ -483,9 +412,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
483
412
|
def _serialize_and_write_top_level_folder(
|
|
484
413
|
self, env: Environment, namespace_path: Path, clients: List[Client]
|
|
485
414
|
) -> None:
|
|
486
|
-
general_serializer = GeneralSerializer(
|
|
487
|
-
code_model=self.code_model, env=env, async_mode=False
|
|
488
|
-
)
|
|
415
|
+
general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
489
416
|
|
|
490
417
|
self.write_file(
|
|
491
418
|
namespace_path / Path("__init__.py"),
|
|
@@ -493,9 +420,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
493
420
|
)
|
|
494
421
|
|
|
495
422
|
# Write the service client
|
|
496
|
-
self._serialize_client_and_config_files(
|
|
497
|
-
namespace_path, general_serializer, async_mode=False, clients=clients
|
|
498
|
-
)
|
|
423
|
+
self._serialize_client_and_config_files(namespace_path, general_serializer, async_mode=False, clients=clients)
|
|
499
424
|
if self.code_model.need_vendored_code(async_mode=False):
|
|
500
425
|
self.write_file(
|
|
501
426
|
namespace_path / Path("_vendor.py"),
|
|
@@ -507,10 +432,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
507
432
|
# write the empty py.typed file
|
|
508
433
|
self.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.")
|
|
509
434
|
|
|
510
|
-
if
|
|
511
|
-
not self.code_model.options["client_side_validation"]
|
|
512
|
-
and not self.code_model.options["multiapi"]
|
|
513
|
-
):
|
|
435
|
+
if not self.code_model.options["client_side_validation"] and not self.code_model.options["multiapi"]:
|
|
514
436
|
self.write_file(
|
|
515
437
|
namespace_path / Path("_serialization.py"),
|
|
516
438
|
general_serializer.serialize_serialization_file(),
|
|
@@ -521,12 +443,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
521
443
|
general_serializer.serialize_model_base_file(),
|
|
522
444
|
)
|
|
523
445
|
|
|
524
|
-
if any(
|
|
525
|
-
og
|
|
526
|
-
for client in self.code_model.clients
|
|
527
|
-
for og in client.operation_groups
|
|
528
|
-
if og.need_validation
|
|
529
|
-
):
|
|
446
|
+
if any(og for client in self.code_model.clients for og in client.operation_groups if og.need_validation):
|
|
530
447
|
self.write_file(
|
|
531
448
|
namespace_path / Path("_validation.py"),
|
|
532
449
|
general_serializer.serialize_validation_file(),
|
|
@@ -544,9 +461,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
544
461
|
def _serialize_and_write_aio_top_level_folder(
|
|
545
462
|
self, env: Environment, namespace_path: Path, clients: List[Client]
|
|
546
463
|
) -> None:
|
|
547
|
-
aio_general_serializer = GeneralSerializer(
|
|
548
|
-
code_model=self.code_model, env=env, async_mode=True
|
|
549
|
-
)
|
|
464
|
+
aio_general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=True)
|
|
550
465
|
|
|
551
466
|
aio_path = namespace_path / Path("aio")
|
|
552
467
|
|
|
@@ -566,22 +481,16 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
566
481
|
aio_general_serializer.serialize_vendor_file(clients),
|
|
567
482
|
)
|
|
568
483
|
|
|
569
|
-
def _serialize_and_write_metadata(
|
|
570
|
-
self, env: Environment, namespace_path: Path
|
|
571
|
-
) -> None:
|
|
484
|
+
def _serialize_and_write_metadata(self, env: Environment, namespace_path: Path) -> None:
|
|
572
485
|
metadata_serializer = MetadataSerializer(self.code_model, env)
|
|
573
|
-
self.write_file(
|
|
574
|
-
namespace_path / Path("_metadata.json"), metadata_serializer.serialize()
|
|
575
|
-
)
|
|
486
|
+
self.write_file(namespace_path / Path("_metadata.json"), metadata_serializer.serialize())
|
|
576
487
|
|
|
577
488
|
@property
|
|
578
489
|
def _namespace_from_package_name(self) -> str:
|
|
579
490
|
return get_namespace_from_package_name(self.code_model.options["package_name"])
|
|
580
491
|
|
|
581
492
|
def _name_space(self) -> str:
|
|
582
|
-
if self.code_model.namespace.count(
|
|
583
|
-
"."
|
|
584
|
-
) >= self._namespace_from_package_name.count("."):
|
|
493
|
+
if self.code_model.namespace.count(".") >= self._namespace_from_package_name.count("."):
|
|
585
494
|
return self.code_model.namespace
|
|
586
495
|
|
|
587
496
|
return self._namespace_from_package_name
|
|
@@ -592,15 +501,11 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
592
501
|
|
|
593
502
|
@property
|
|
594
503
|
def _additional_folder(self) -> Path:
|
|
595
|
-
namespace_config = get_namespace_config(
|
|
596
|
-
self.code_model.namespace, self.code_model.options["multiapi"]
|
|
597
|
-
)
|
|
504
|
+
namespace_config = get_namespace_config(self.code_model.namespace, self.code_model.options["multiapi"])
|
|
598
505
|
num_of_namespace = namespace_config.count(".") + 1
|
|
599
506
|
num_of_package_namespace = self._namespace_from_package_name.count(".") + 1
|
|
600
507
|
if num_of_namespace > num_of_package_namespace:
|
|
601
|
-
return Path(
|
|
602
|
-
"/".join(namespace_config.split(".")[num_of_package_namespace:])
|
|
603
|
-
)
|
|
508
|
+
return Path("/".join(namespace_config.split(".")[num_of_package_namespace:]))
|
|
604
509
|
return Path("")
|
|
605
510
|
|
|
606
511
|
def _serialize_and_write_sample(self, env: Environment, namespace_path: Path):
|
|
@@ -610,8 +515,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
610
515
|
for operation in op_group.operations:
|
|
611
516
|
if (
|
|
612
517
|
self.code_model.options["multiapi"]
|
|
613
|
-
and operation.api_versions[0]
|
|
614
|
-
!= self.code_model.options["default_api_version"]
|
|
518
|
+
and operation.api_versions[0] != self.code_model.options["default_api_version"]
|
|
615
519
|
):
|
|
616
520
|
continue
|
|
617
521
|
samples = operation.yaml_data["samples"]
|
|
@@ -622,10 +526,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
622
526
|
file_name = to_snake_case(extract_sample_name(file)) + ".py"
|
|
623
527
|
try:
|
|
624
528
|
self.write_file(
|
|
625
|
-
out_path
|
|
626
|
-
/ self._additional_folder
|
|
627
|
-
/ _sample_output_path(file)
|
|
628
|
-
/ file_name,
|
|
529
|
+
out_path / self._additional_folder / _sample_output_path(file) / file_name,
|
|
629
530
|
SampleSerializer(
|
|
630
531
|
code_model=self.code_model,
|
|
631
532
|
env=env,
|
|
@@ -644,9 +545,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
644
545
|
self.code_model.for_test = True
|
|
645
546
|
out_path = self._package_root_folder(namespace_path) / Path("generated_tests")
|
|
646
547
|
general_serializer = TestGeneralSerializer(code_model=self.code_model, env=env)
|
|
647
|
-
self.write_file(
|
|
648
|
-
out_path / "conftest.py", general_serializer.serialize_conftest()
|
|
649
|
-
)
|
|
548
|
+
self.write_file(out_path / "conftest.py", general_serializer.serialize_conftest())
|
|
650
549
|
for is_async in (True, False):
|
|
651
550
|
async_suffix = "_async" if is_async else ""
|
|
652
551
|
general_serializer.is_async = is_async
|
|
@@ -657,15 +556,12 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
657
556
|
|
|
658
557
|
for client in self.code_model.clients:
|
|
659
558
|
for og in client.operation_groups:
|
|
660
|
-
test_serializer = TestSerializer(
|
|
661
|
-
self.code_model, env, client=client, operation_group=og
|
|
662
|
-
)
|
|
559
|
+
test_serializer = TestSerializer(self.code_model, env, client=client, operation_group=og)
|
|
663
560
|
for is_async in (True, False):
|
|
664
561
|
try:
|
|
665
562
|
test_serializer.is_async = is_async
|
|
666
563
|
self.write_file(
|
|
667
|
-
out_path
|
|
668
|
-
/ f"{to_snake_case(test_serializer.test_class_name)}.py",
|
|
564
|
+
out_path / f"{to_snake_case(test_serializer.test_class_name)}.py",
|
|
669
565
|
test_serializer.serialize_test(),
|
|
670
566
|
)
|
|
671
567
|
except Exception as e: # pylint: disable=broad-except
|