@autorest/python 6.13.15 → 6.13.17
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 +26 -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 +15 -56
- 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/enum.py.jinja2 +2 -2
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/model_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/model_dpg.py.jinja2 +3 -3
- package/autorest/codegen/templates/model_msrest.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.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 +40 -126
- 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
package/autorest/__init__.py
CHANGED
|
@@ -34,9 +34,7 @@ class ReaderAndWriter:
|
|
|
34
34
|
python_json = {}
|
|
35
35
|
self.options = kwargs
|
|
36
36
|
if python_json:
|
|
37
|
-
_LOGGER.warning(
|
|
38
|
-
"Loading python.json file. This behavior will be depreacted"
|
|
39
|
-
)
|
|
37
|
+
_LOGGER.warning("Loading python.json file. This behavior will be depreacted")
|
|
40
38
|
self.options.update(python_json)
|
|
41
39
|
|
|
42
40
|
def read_file(self, path: Union[str, Path]) -> str:
|
|
@@ -61,9 +59,7 @@ class ReaderAndWriter:
|
|
|
61
59
|
|
|
62
60
|
|
|
63
61
|
class ReaderAndWriterAutorest(ReaderAndWriter):
|
|
64
|
-
def __init__(
|
|
65
|
-
self, *, output_folder: Union[str, Path], autorestapi: AutorestAPI
|
|
66
|
-
) -> None:
|
|
62
|
+
def __init__(self, *, output_folder: Union[str, Path], autorestapi: AutorestAPI) -> None:
|
|
67
63
|
super().__init__(output_folder=output_folder)
|
|
68
64
|
self._autorestapi = autorestapi
|
|
69
65
|
|
|
@@ -97,9 +93,7 @@ class Plugin(ReaderAndWriter, ABC):
|
|
|
97
93
|
class PluginAutorest(Plugin, ReaderAndWriterAutorest):
|
|
98
94
|
"""For our Autorest plugins, we want to take autorest api as input as options, then pass it to the Plugin"""
|
|
99
95
|
|
|
100
|
-
def __init__(
|
|
101
|
-
self, autorestapi: AutorestAPI, *, output_folder: Union[str, Path]
|
|
102
|
-
) -> None:
|
|
96
|
+
def __init__(self, autorestapi: AutorestAPI, *, output_folder: Union[str, Path]) -> None:
|
|
103
97
|
super().__init__(autorestapi=autorestapi, output_folder=output_folder)
|
|
104
98
|
self.options = self.get_options()
|
|
105
99
|
|
|
@@ -141,9 +135,7 @@ class YamlUpdatePlugin(Plugin):
|
|
|
141
135
|
raise NotImplementedError()
|
|
142
136
|
|
|
143
137
|
|
|
144
|
-
class YamlUpdatePluginAutorest( # pylint: disable=abstract-method
|
|
145
|
-
YamlUpdatePlugin, PluginAutorest
|
|
146
|
-
):
|
|
138
|
+
class YamlUpdatePluginAutorest(YamlUpdatePlugin, PluginAutorest): # pylint: disable=abstract-method
|
|
147
139
|
def get_yaml(self) -> Dict[str, Any]:
|
|
148
140
|
return yaml.safe_load(self.read_file("code-model-v4-no-tags.yaml"))
|
|
149
141
|
|
package/autorest/_utils.py
CHANGED
|
@@ -8,9 +8,7 @@ import re
|
|
|
8
8
|
import argparse
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
def update_enum_value(
|
|
12
|
-
name: str, value: Any, description: str, enum_type: Dict[str, Any]
|
|
13
|
-
) -> Dict[str, Any]:
|
|
11
|
+
def update_enum_value(name: str, value: Any, description: str, enum_type: Dict[str, Any]) -> Dict[str, Any]:
|
|
14
12
|
return {
|
|
15
13
|
"name": name,
|
|
16
14
|
"type": "enumvalue",
|
|
@@ -37,12 +35,7 @@ def to_snake_case(name: str) -> str:
|
|
|
37
35
|
and len(name) - next_non_upper_case_char_location > 1
|
|
38
36
|
and name[next_non_upper_case_char_location].isalpha()
|
|
39
37
|
):
|
|
40
|
-
return (
|
|
41
|
-
prefix
|
|
42
|
-
+ match_str[: len(match_str) - 1]
|
|
43
|
-
+ "_"
|
|
44
|
-
+ match_str[len(match_str) - 1]
|
|
45
|
-
)
|
|
38
|
+
return prefix + match_str[: len(match_str) - 1] + "_" + match_str[len(match_str) - 1]
|
|
46
39
|
|
|
47
40
|
return prefix + match_str
|
|
48
41
|
|
|
@@ -89,12 +82,8 @@ def parse_args(
|
|
|
89
82
|
return value
|
|
90
83
|
|
|
91
84
|
unknown_args_ret = {
|
|
92
|
-
ua.strip("--").split("=", maxsplit=1)[ # pylint: disable=bad-str-strip-call
|
|
93
|
-
|
|
94
|
-
]: _get_value(
|
|
95
|
-
ua.strip("--").split("=", maxsplit=1)[ # pylint: disable=bad-str-strip-call
|
|
96
|
-
1
|
|
97
|
-
]
|
|
85
|
+
ua.strip("--").split("=", maxsplit=1)[0]: _get_value( # pylint: disable=bad-str-strip-call
|
|
86
|
+
ua.strip("--").split("=", maxsplit=1)[1] # pylint: disable=bad-str-strip-call
|
|
98
87
|
)
|
|
99
88
|
for ua in unknown_args
|
|
100
89
|
}
|
|
@@ -136,11 +125,7 @@ def build_policies(
|
|
|
136
125
|
"self._config.user_agent_policy",
|
|
137
126
|
"self._config.proxy_policy",
|
|
138
127
|
"policies.ContentDecodePolicy(**kwargs)",
|
|
139
|
-
(
|
|
140
|
-
f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
|
|
141
|
-
if is_arm
|
|
142
|
-
else None
|
|
143
|
-
),
|
|
128
|
+
(f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()" if is_arm else None),
|
|
144
129
|
"self._config.redirect_policy",
|
|
145
130
|
"self._config.retry_policy",
|
|
146
131
|
"self._config.authentication_policy",
|
|
@@ -55,9 +55,7 @@ class BlackScriptPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
55
55
|
def format_file(self, file: Path) -> None:
|
|
56
56
|
try:
|
|
57
57
|
file_content = self.read_file(file)
|
|
58
|
-
file_content = black.format_file_contents(
|
|
59
|
-
file_content, fast=True, mode=_BLACK_MODE
|
|
60
|
-
)
|
|
58
|
+
file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)
|
|
61
59
|
except NothingChanged:
|
|
62
60
|
pass
|
|
63
61
|
except: # pylint: disable=bare-except
|
|
@@ -55,25 +55,18 @@ class OptionsRetriever:
|
|
|
55
55
|
|
|
56
56
|
@property
|
|
57
57
|
def company_name(self) -> str:
|
|
58
|
-
return self.options.get(
|
|
59
|
-
"company-name", "Microsoft" if self.is_azure_flavor else ""
|
|
60
|
-
)
|
|
58
|
+
return self.options.get("company-name", "Microsoft" if self.is_azure_flavor else "")
|
|
61
59
|
|
|
62
60
|
@property
|
|
63
61
|
def license_header(self) -> str:
|
|
64
62
|
license_header = self.options.get(
|
|
65
63
|
"header-text",
|
|
66
|
-
(
|
|
67
|
-
DEFAULT_HEADER_TEXT.format(company_name=self.company_name)
|
|
68
|
-
if self.company_name
|
|
69
|
-
else ""
|
|
70
|
-
),
|
|
64
|
+
(DEFAULT_HEADER_TEXT.format(company_name=self.company_name) if self.company_name else ""),
|
|
71
65
|
)
|
|
72
66
|
if license_header:
|
|
73
67
|
license_header = license_header.replace("\n", "\n# ")
|
|
74
68
|
license_header = (
|
|
75
|
-
"# --------------------------------------------------------------------------\n# "
|
|
76
|
-
+ license_header
|
|
69
|
+
"# --------------------------------------------------------------------------\n# " + license_header
|
|
77
70
|
)
|
|
78
71
|
license_header += "\n# --------------------------------------------------------------------------"
|
|
79
72
|
return license_header
|
|
@@ -84,9 +77,7 @@ class OptionsRetriever:
|
|
|
84
77
|
|
|
85
78
|
@property
|
|
86
79
|
def _models_mode_default(self) -> str:
|
|
87
|
-
models_mode_default =
|
|
88
|
-
"none" if self.low_level_client or self.version_tolerant else "msrest"
|
|
89
|
-
)
|
|
80
|
+
models_mode_default = "none" if self.low_level_client or self.version_tolerant else "msrest"
|
|
90
81
|
if self.options.get("cadl_file") is not None:
|
|
91
82
|
models_mode_default = "dpg"
|
|
92
83
|
return models_mode_default
|
|
@@ -98,9 +89,7 @@ class OptionsRetriever:
|
|
|
98
89
|
@property
|
|
99
90
|
def models_mode(self) -> Union[str, bool]:
|
|
100
91
|
# switch to falsy value for easier code writing
|
|
101
|
-
return
|
|
102
|
-
False if self.original_models_mode == "none" else self.original_models_mode
|
|
103
|
-
)
|
|
92
|
+
return False if self.original_models_mode == "none" else self.original_models_mode
|
|
104
93
|
|
|
105
94
|
@property
|
|
106
95
|
def tracing(self) -> bool:
|
|
@@ -136,9 +125,7 @@ class OptionsRetriever:
|
|
|
136
125
|
|
|
137
126
|
@property
|
|
138
127
|
def package_pprint_name(self) -> str:
|
|
139
|
-
return self.options.get("package-pprint-name") or _default_pprint(
|
|
140
|
-
str(self.package_name)
|
|
141
|
-
)
|
|
128
|
+
return self.options.get("package-pprint-name") or _default_pprint(str(self.package_name))
|
|
142
129
|
|
|
143
130
|
@property
|
|
144
131
|
def default_optional_constants_to_none(self) -> bool:
|
|
@@ -162,9 +149,7 @@ class OptionsRetriever:
|
|
|
162
149
|
|
|
163
150
|
@property
|
|
164
151
|
def package_mode(self) -> str:
|
|
165
|
-
return self.options.get("packaging-files-dir") or self.options.get(
|
|
166
|
-
"package-mode", ""
|
|
167
|
-
)
|
|
152
|
+
return self.options.get("packaging-files-dir") or self.options.get("package-mode", "")
|
|
168
153
|
|
|
169
154
|
@property
|
|
170
155
|
def packaging_files_config(self) -> Optional[Dict[str, Any]]:
|
|
@@ -175,10 +160,7 @@ class OptionsRetriever:
|
|
|
175
160
|
# if it's a string, we can split on the comma to get the dict
|
|
176
161
|
# otherwise we just return
|
|
177
162
|
try:
|
|
178
|
-
return {
|
|
179
|
-
k.strip(): v.strip()
|
|
180
|
-
for k, v in [i.split(":") for i in packaging_files_config.split("|")]
|
|
181
|
-
}
|
|
163
|
+
return {k.strip(): v.strip() for k, v in [i.split(":") for i in packaging_files_config.split("|")]}
|
|
182
164
|
except AttributeError:
|
|
183
165
|
return packaging_files_config
|
|
184
166
|
|
|
@@ -194,10 +176,7 @@ class CodeGenerator(Plugin):
|
|
|
194
176
|
"hidden",
|
|
195
177
|
"embedded",
|
|
196
178
|
]:
|
|
197
|
-
raise ValueError(
|
|
198
|
-
"The value of --builders-visibility must be either 'public', 'hidden', "
|
|
199
|
-
"or 'embedded'"
|
|
200
|
-
)
|
|
179
|
+
raise ValueError("The value of --builders-visibility must be either 'public', 'hidden', or 'embedded'")
|
|
201
180
|
|
|
202
181
|
if self.options_retriever.original_models_mode not in ["msrest", "dpg", "none"]:
|
|
203
182
|
raise ValueError(
|
|
@@ -206,32 +185,20 @@ class CodeGenerator(Plugin):
|
|
|
206
185
|
"'none' if you don't want any."
|
|
207
186
|
)
|
|
208
187
|
|
|
209
|
-
if
|
|
210
|
-
not self.options_retriever.show_operations
|
|
211
|
-
and self.options_retriever.builders_visibility == "embedded"
|
|
212
|
-
):
|
|
188
|
+
if not self.options_retriever.show_operations and self.options_retriever.builders_visibility == "embedded":
|
|
213
189
|
raise ValueError(
|
|
214
190
|
"Can not embed builders without operations. "
|
|
215
191
|
"Either set --show-operations to True, or change the value of --builders-visibility "
|
|
216
192
|
"to 'public' or 'hidden'."
|
|
217
193
|
)
|
|
218
194
|
|
|
219
|
-
if
|
|
220
|
-
self.options_retriever.basic_setup_py
|
|
221
|
-
and not self.options_retriever.package_version
|
|
222
|
-
):
|
|
195
|
+
if self.options_retriever.basic_setup_py and not self.options_retriever.package_version:
|
|
223
196
|
raise ValueError("--basic-setup-py must be used with --package-version")
|
|
224
197
|
|
|
225
|
-
if
|
|
226
|
-
self.options_retriever.package_mode
|
|
227
|
-
and not self.options_retriever.package_version
|
|
228
|
-
):
|
|
198
|
+
if self.options_retriever.package_mode and not self.options_retriever.package_version:
|
|
229
199
|
raise ValueError("--package-mode must be used with --package-version")
|
|
230
200
|
|
|
231
|
-
if
|
|
232
|
-
not self.options_retriever.show_operations
|
|
233
|
-
and self.options_retriever.combine_operation_files
|
|
234
|
-
):
|
|
201
|
+
if not self.options_retriever.show_operations and self.options_retriever.combine_operation_files:
|
|
235
202
|
raise ValueError(
|
|
236
203
|
"Can not combine operation files if you are not showing operations. "
|
|
237
204
|
"If you want operation files, pass in flag --show-operations"
|
|
@@ -258,26 +225,16 @@ class CodeGenerator(Plugin):
|
|
|
258
225
|
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
259
226
|
)
|
|
260
227
|
|
|
261
|
-
if
|
|
262
|
-
|
|
263
|
-
and self.options_retriever.version_tolerant
|
|
264
|
-
):
|
|
265
|
-
raise ValueError(
|
|
266
|
-
"Can not generate version tolerant with --client-side-validation. "
|
|
267
|
-
)
|
|
228
|
+
if self.options_retriever.client_side_validation and self.options_retriever.version_tolerant:
|
|
229
|
+
raise ValueError("Can not generate version tolerant with --client-side-validation. ")
|
|
268
230
|
|
|
269
|
-
if not (
|
|
270
|
-
self.options_retriever.azure_arm or self.options_retriever.version_tolerant
|
|
271
|
-
):
|
|
231
|
+
if not (self.options_retriever.azure_arm or self.options_retriever.version_tolerant):
|
|
272
232
|
_LOGGER.warning(
|
|
273
233
|
"You are generating with options that would not allow the SDK to be shipped as an official Azure SDK. "
|
|
274
234
|
"Please read https://aka.ms/azsdk/dpcodegen for more details."
|
|
275
235
|
)
|
|
276
236
|
|
|
277
|
-
if
|
|
278
|
-
not self.options_retriever.is_azure_flavor
|
|
279
|
-
and self.options_retriever.tracing
|
|
280
|
-
):
|
|
237
|
+
if not self.options_retriever.is_azure_flavor and self.options_retriever.tracing:
|
|
281
238
|
raise ValueError("Can only have tracing turned on for Azure SDKs.")
|
|
282
239
|
|
|
283
240
|
@staticmethod
|
|
@@ -292,8 +249,7 @@ class CodeGenerator(Plugin):
|
|
|
292
249
|
exception = operation["exceptions"][i]
|
|
293
250
|
if (
|
|
294
251
|
exception.get("schema")
|
|
295
|
-
and exception["schema"]["language"]["default"]["name"]
|
|
296
|
-
== "CloudError"
|
|
252
|
+
and exception["schema"]["language"]["default"]["name"] == "CloudError"
|
|
297
253
|
):
|
|
298
254
|
del operation["exceptions"][i]
|
|
299
255
|
i -= 1
|
|
@@ -360,9 +316,7 @@ class CodeGenerator(Plugin):
|
|
|
360
316
|
self.remove_cloud_errors(yaml_data)
|
|
361
317
|
|
|
362
318
|
code_model = CodeModel(yaml_data=yaml_data, options=options)
|
|
363
|
-
if not self.options_retriever.is_azure_flavor and any(
|
|
364
|
-
client.lro_operations for client in code_model.clients
|
|
365
|
-
):
|
|
319
|
+
if not self.options_retriever.is_azure_flavor and any(client.lro_operations for client in code_model.clients):
|
|
366
320
|
raise ValueError("Only support LROs for Azure SDKs")
|
|
367
321
|
serializer = self.get_serializer(code_model)
|
|
368
322
|
serializer.serialize()
|
|
@@ -373,10 +327,7 @@ class CodeGenerator(Plugin):
|
|
|
373
327
|
class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
|
|
374
328
|
def get_options(self) -> Dict[str, Any]:
|
|
375
329
|
if self._autorestapi.get_boolean_value("python3-only") is False:
|
|
376
|
-
_LOGGER.warning(
|
|
377
|
-
"You have passed in --python3-only=False. We have force overriden "
|
|
378
|
-
"this to True."
|
|
379
|
-
)
|
|
330
|
+
_LOGGER.warning("You have passed in --python3-only=False. We have force overriden this to True.")
|
|
380
331
|
if self._autorestapi.get_boolean_value("add-python3-operation-files"):
|
|
381
332
|
_LOGGER.warning(
|
|
382
333
|
"You have passed in --add-python3-operation-files. "
|
|
@@ -391,49 +342,31 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
|
|
|
391
342
|
options = {
|
|
392
343
|
"azure-arm": self._autorestapi.get_boolean_value("azure-arm"),
|
|
393
344
|
"header-text": self._autorestapi.get_value("header-text"),
|
|
394
|
-
"low-level-client": self._autorestapi.get_boolean_value(
|
|
395
|
-
|
|
396
|
-
),
|
|
397
|
-
"version-tolerant": self._autorestapi.get_boolean_value(
|
|
398
|
-
"version-tolerant", True
|
|
399
|
-
),
|
|
345
|
+
"low-level-client": self._autorestapi.get_boolean_value("low-level-client", False),
|
|
346
|
+
"version-tolerant": self._autorestapi.get_boolean_value("version-tolerant", True),
|
|
400
347
|
"show-operations": self._autorestapi.get_boolean_value("show-operations"),
|
|
401
348
|
"python3-only": self._autorestapi.get_boolean_value("python3-only"),
|
|
402
|
-
"head-as-boolean": self._autorestapi.get_boolean_value(
|
|
403
|
-
|
|
404
|
-
),
|
|
405
|
-
"keep-version-file": self._autorestapi.get_boolean_value(
|
|
406
|
-
"keep-version-file"
|
|
407
|
-
),
|
|
349
|
+
"head-as-boolean": self._autorestapi.get_boolean_value("head-as-boolean", False),
|
|
350
|
+
"keep-version-file": self._autorestapi.get_boolean_value("keep-version-file"),
|
|
408
351
|
"no-async": self._autorestapi.get_boolean_value("no-async"),
|
|
409
|
-
"no-namespace-folders": self._autorestapi.get_boolean_value(
|
|
410
|
-
"no-namespace-folders"
|
|
411
|
-
),
|
|
352
|
+
"no-namespace-folders": self._autorestapi.get_boolean_value("no-namespace-folders"),
|
|
412
353
|
"basic-setup-py": self._autorestapi.get_boolean_value("basic-setup-py"),
|
|
413
354
|
"package-name": self._autorestapi.get_value("package-name"),
|
|
414
355
|
"package-version": self._autorestapi.get_value("package-version"),
|
|
415
|
-
"client-side-validation": self._autorestapi.get_boolean_value(
|
|
416
|
-
"client-side-validation"
|
|
417
|
-
),
|
|
356
|
+
"client-side-validation": self._autorestapi.get_boolean_value("client-side-validation"),
|
|
418
357
|
"tracing": self._autorestapi.get_boolean_value("trace"),
|
|
419
358
|
"multiapi": self._autorestapi.get_boolean_value("multiapi", False),
|
|
420
359
|
"polymorphic-examples": self._autorestapi.get_value("polymorphic-examples"),
|
|
421
360
|
"models-mode": self._autorestapi.get_value("models-mode"),
|
|
422
361
|
"builders-visibility": self._autorestapi.get_value("builders-visibility"),
|
|
423
|
-
"show-send-request": self._autorestapi.get_boolean_value(
|
|
424
|
-
"show-send-request"
|
|
425
|
-
),
|
|
362
|
+
"show-send-request": self._autorestapi.get_boolean_value("show-send-request"),
|
|
426
363
|
"only-path-and-body-params-positional": self._autorestapi.get_boolean_value(
|
|
427
364
|
"only-path-and-body-params-positional"
|
|
428
365
|
),
|
|
429
|
-
"combine-operation-files": self._autorestapi.get_boolean_value(
|
|
430
|
-
"combine-operation-files"
|
|
431
|
-
),
|
|
366
|
+
"combine-operation-files": self._autorestapi.get_boolean_value("combine-operation-files"),
|
|
432
367
|
"package-mode": self._autorestapi.get_value("package-mode"),
|
|
433
368
|
"package-pprint-name": self._autorestapi.get_value("package-pprint-name"),
|
|
434
|
-
"packaging-files-config": self._autorestapi.get_value(
|
|
435
|
-
"package-configuration"
|
|
436
|
-
),
|
|
369
|
+
"packaging-files-config": self._autorestapi.get_value("package-configuration"),
|
|
437
370
|
"default-optional-constants-to-none": self._autorestapi.get_boolean_value(
|
|
438
371
|
"default-optional-constants-to-none"
|
|
439
372
|
),
|
|
@@ -198,7 +198,5 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
|
198
198
|
|
|
199
199
|
|
|
200
200
|
RequestBuilderType = Union[RequestBuilder, OverloadedRequestBuilder]
|
|
201
|
-
ParameterType = Union[
|
|
202
|
-
Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter
|
|
203
|
-
]
|
|
201
|
+
ParameterType = Union[Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter]
|
|
204
202
|
OperationType = Union[Operation, LROOperation, PagingOperation, LROPagingOperation]
|
|
@@ -42,14 +42,10 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
42
42
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
43
43
|
super().__init__(yaml_data, code_model)
|
|
44
44
|
self.type = yaml_data["type"] # the type discriminator
|
|
45
|
-
self.api_versions: List[str] = yaml_data.get(
|
|
46
|
-
"apiVersions", []
|
|
47
|
-
) # api versions this type is in.
|
|
45
|
+
self.api_versions: List[str] = yaml_data.get("apiVersions", []) # api versions this type is in.
|
|
48
46
|
|
|
49
47
|
@classmethod
|
|
50
|
-
def from_yaml(
|
|
51
|
-
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
52
|
-
) -> "BaseType":
|
|
48
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "BaseType":
|
|
53
49
|
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
54
50
|
|
|
55
51
|
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
@@ -39,9 +39,7 @@ if TYPE_CHECKING:
|
|
|
39
39
|
from .request_builder import RequestBuilder
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
OverloadListType = TypeVar(
|
|
43
|
-
"OverloadListType", bound=Union[List["Operation"], List["RequestBuilder"]]
|
|
44
|
-
)
|
|
42
|
+
OverloadListType = TypeVar("OverloadListType", bound=Union[List["Operation"], List["RequestBuilder"]])
|
|
45
43
|
|
|
46
44
|
_LOGGER = logging.getLogger(__name__)
|
|
47
45
|
|
|
@@ -69,9 +67,7 @@ class BaseBuilder(
|
|
|
69
67
|
self.overloads = overloads or cast(OverloadListType, [])
|
|
70
68
|
self._summary: str = yaml_data.get("summary", "")
|
|
71
69
|
self.want_tracing: bool = yaml_data.get("wantTracing", True)
|
|
72
|
-
self.group_name: str = yaml_data[
|
|
73
|
-
"groupName"
|
|
74
|
-
] # either operationGroup or client I am on
|
|
70
|
+
self.group_name: str = yaml_data["groupName"] # either operationGroup or client I am on
|
|
75
71
|
self.is_overload: bool = yaml_data["isOverload"]
|
|
76
72
|
self.api_versions: List[str] = yaml_data["apiVersions"]
|
|
77
73
|
self.added_on: Optional[str] = yaml_data.get("addedOn")
|
|
@@ -40,9 +40,7 @@ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
|
40
40
|
):
|
|
41
41
|
super().__init__(yaml_data, code_model)
|
|
42
42
|
self.parameters = parameters
|
|
43
|
-
self.url: str = self.yaml_data[
|
|
44
|
-
"url"
|
|
45
|
-
] # the base endpoint of the client. Can be parameterized or not
|
|
43
|
+
self.url: str = self.yaml_data["url"] # the base endpoint of the client. Can be parameterized or not
|
|
46
44
|
self.legacy_filename: str = self.yaml_data.get("legacyFilename", "client")
|
|
47
45
|
|
|
48
46
|
@property
|
|
@@ -139,11 +137,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
139
137
|
@property
|
|
140
138
|
def send_request_name(self) -> str:
|
|
141
139
|
"""Name of the send request function"""
|
|
142
|
-
return
|
|
143
|
-
"send_request"
|
|
144
|
-
if self.code_model.options["show_send_request"]
|
|
145
|
-
else "_send_request"
|
|
146
|
-
)
|
|
140
|
+
return "send_request" if self.code_model.options["show_send_request"] else "_send_request"
|
|
147
141
|
|
|
148
142
|
@property
|
|
149
143
|
def has_parameterized_host(self) -> bool:
|
|
@@ -170,48 +164,28 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
170
164
|
@property
|
|
171
165
|
def filename(self) -> str:
|
|
172
166
|
"""Name of the file for the client"""
|
|
173
|
-
if
|
|
174
|
-
self.code_model.options["version_tolerant"]
|
|
175
|
-
or self.code_model.options["low_level_client"]
|
|
176
|
-
):
|
|
167
|
+
if self.code_model.options["version_tolerant"] or self.code_model.options["low_level_client"]:
|
|
177
168
|
return "_client"
|
|
178
169
|
return f"_{self.legacy_filename}"
|
|
179
170
|
|
|
180
|
-
def lookup_request_builder(
|
|
181
|
-
self, request_builder_id: int
|
|
182
|
-
) -> Union[RequestBuilder, OverloadedRequestBuilder]:
|
|
171
|
+
def lookup_request_builder(self, request_builder_id: int) -> Union[RequestBuilder, OverloadedRequestBuilder]:
|
|
183
172
|
"""Find the request builder based off of id"""
|
|
184
173
|
try:
|
|
185
|
-
return next(
|
|
186
|
-
rb
|
|
187
|
-
for rb in self.request_builders
|
|
188
|
-
if id(rb.yaml_data) == request_builder_id
|
|
189
|
-
)
|
|
174
|
+
return next(rb for rb in self.request_builders if id(rb.yaml_data) == request_builder_id)
|
|
190
175
|
except StopIteration as exc:
|
|
191
|
-
raise KeyError(
|
|
192
|
-
f"No request builder with id {request_builder_id} found."
|
|
193
|
-
) from exc
|
|
176
|
+
raise KeyError(f"No request builder with id {request_builder_id} found.") from exc
|
|
194
177
|
|
|
195
178
|
def lookup_operation(self, operation_id: int) -> "OperationType":
|
|
196
179
|
try:
|
|
197
|
-
return next(
|
|
198
|
-
o
|
|
199
|
-
for og in self.operation_groups
|
|
200
|
-
for o in og.operations
|
|
201
|
-
if id(o.yaml_data) == operation_id
|
|
202
|
-
)
|
|
180
|
+
return next(o for og in self.operation_groups for o in og.operations if id(o.yaml_data) == operation_id)
|
|
203
181
|
except StopIteration as exc:
|
|
204
182
|
raise KeyError(f"No operation with id {operation_id} found.") from exc
|
|
205
183
|
|
|
206
184
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
207
185
|
file_import = FileImport(self.code_model)
|
|
208
|
-
file_import.add_submodule_import(
|
|
209
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
210
|
-
)
|
|
186
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
211
187
|
if self.code_model.options["azure_arm"]:
|
|
212
|
-
file_import.add_submodule_import(
|
|
213
|
-
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE
|
|
214
|
-
)
|
|
188
|
+
file_import.add_submodule_import("azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE)
|
|
215
189
|
else:
|
|
216
190
|
file_import.add_submodule_import(
|
|
217
191
|
"" if self.code_model.is_azure_flavor else "runtime",
|
|
@@ -261,11 +235,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
261
235
|
@property
|
|
262
236
|
def lro_operations(self) -> List["OperationType"]:
|
|
263
237
|
"""all LRO operations in this SDK?"""
|
|
264
|
-
return [
|
|
265
|
-
operation
|
|
266
|
-
for operation_group in self.operation_groups
|
|
267
|
-
for operation in operation_group.lro_operations
|
|
268
|
-
]
|
|
238
|
+
return [operation for operation_group in self.operation_groups for operation in operation_group.lro_operations]
|
|
269
239
|
|
|
270
240
|
@property
|
|
271
241
|
def has_public_lro_operations(self) -> bool:
|
|
@@ -274,18 +244,14 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
274
244
|
|
|
275
245
|
@property
|
|
276
246
|
def has_operations(self) -> bool:
|
|
277
|
-
return any(
|
|
278
|
-
operation_group.has_operations for operation_group in self.operation_groups
|
|
279
|
-
)
|
|
247
|
+
return any(operation_group.has_operations for operation_group in self.operation_groups)
|
|
280
248
|
|
|
281
249
|
def link_lro_initial_operations(self) -> None:
|
|
282
250
|
"""Link each LRO operation to its initial operation"""
|
|
283
251
|
for operation_group in self.operation_groups:
|
|
284
252
|
for operation in operation_group.operations:
|
|
285
253
|
if isinstance(operation, (LROOperation, LROPagingOperation)):
|
|
286
|
-
operation.initial_operation = self.lookup_operation(
|
|
287
|
-
id(operation.yaml_data["initialOperation"])
|
|
288
|
-
)
|
|
254
|
+
operation.initial_operation = self.lookup_operation(id(operation.yaml_data["initialOperation"]))
|
|
289
255
|
|
|
290
256
|
@property
|
|
291
257
|
def need_request_converter(self) -> bool:
|
|
@@ -339,14 +305,9 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
339
305
|
ImportType.LOCAL,
|
|
340
306
|
)
|
|
341
307
|
|
|
342
|
-
if
|
|
343
|
-
self.code_model.model_types
|
|
344
|
-
and self.code_model.options["models_mode"] == "msrest"
|
|
345
|
-
):
|
|
308
|
+
if self.code_model.model_types and self.code_model.options["models_mode"] == "msrest":
|
|
346
309
|
path_to_models = ".." if async_mode else "."
|
|
347
|
-
file_import.add_submodule_import(
|
|
348
|
-
path_to_models, "models", ImportType.LOCAL, alias="_models"
|
|
349
|
-
)
|
|
310
|
+
file_import.add_submodule_import(path_to_models, "models", ImportType.LOCAL, alias="_models")
|
|
350
311
|
elif self.code_model.options["models_mode"] == "msrest":
|
|
351
312
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
352
313
|
# this import will always be commented, so will always add it to the typing section
|
|
@@ -356,22 +317,14 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
356
317
|
|
|
357
318
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
358
319
|
file_import = self._imports_shared(async_mode)
|
|
359
|
-
file_import.add_submodule_import(
|
|
360
|
-
"typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
361
|
-
)
|
|
320
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
362
321
|
try:
|
|
363
322
|
mixin_operation = next(og for og in self.operation_groups if og.is_mixin)
|
|
364
|
-
file_import.add_submodule_import(
|
|
365
|
-
"._operations_mixin", mixin_operation.class_name, ImportType.LOCAL
|
|
366
|
-
)
|
|
323
|
+
file_import.add_submodule_import("._operations_mixin", mixin_operation.class_name, ImportType.LOCAL)
|
|
367
324
|
except StopIteration:
|
|
368
325
|
pass
|
|
369
|
-
file_import.add_submodule_import(
|
|
370
|
-
|
|
371
|
-
)
|
|
372
|
-
file_import.add_submodule_import(
|
|
373
|
-
"azure.profiles", "ProfileDefinition", import_type=ImportType.SDKCORE
|
|
374
|
-
)
|
|
326
|
+
file_import.add_submodule_import("azure.profiles", "KnownProfiles", import_type=ImportType.SDKCORE)
|
|
327
|
+
file_import.add_submodule_import("azure.profiles", "ProfileDefinition", import_type=ImportType.SDKCORE)
|
|
375
328
|
file_import.add_submodule_import(
|
|
376
329
|
"azure.profiles.multiapiclient",
|
|
377
330
|
"MultiApiClientMixin",
|
|
@@ -430,35 +383,20 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
430
383
|
"policies",
|
|
431
384
|
ImportType.SDKCORE,
|
|
432
385
|
)
|
|
433
|
-
file_import.add_submodule_import(
|
|
434
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
435
|
-
)
|
|
386
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
436
387
|
if self.code_model.options["package_version"]:
|
|
437
|
-
file_import.add_submodule_import(
|
|
438
|
-
".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL
|
|
439
|
-
)
|
|
388
|
+
file_import.add_submodule_import(".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL)
|
|
440
389
|
if self.code_model.options["azure_arm"]:
|
|
441
|
-
policy =
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
else "ARMChallengeAuthenticationPolicy"
|
|
445
|
-
)
|
|
446
|
-
file_import.add_submodule_import(
|
|
447
|
-
"azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE
|
|
448
|
-
)
|
|
449
|
-
file_import.add_submodule_import(
|
|
450
|
-
"azure.mgmt.core.policies", policy, ImportType.SDKCORE
|
|
451
|
-
)
|
|
390
|
+
policy = "AsyncARMChallengeAuthenticationPolicy" if async_mode else "ARMChallengeAuthenticationPolicy"
|
|
391
|
+
file_import.add_submodule_import("azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE)
|
|
392
|
+
file_import.add_submodule_import("azure.mgmt.core.policies", policy, ImportType.SDKCORE)
|
|
452
393
|
|
|
453
394
|
return file_import
|
|
454
395
|
|
|
455
396
|
def imports(self, async_mode: bool) -> FileImport:
|
|
456
397
|
file_import = self._imports_shared(async_mode)
|
|
457
398
|
for gp in self.parameters:
|
|
458
|
-
if
|
|
459
|
-
gp.method_location == ParameterMethodLocation.KWARG
|
|
460
|
-
and gp not in self.parameters.kwargs_to_pop
|
|
461
|
-
):
|
|
399
|
+
if gp.method_location == ParameterMethodLocation.KWARG and gp not in self.parameters.kwargs_to_pop:
|
|
462
400
|
continue
|
|
463
401
|
file_import.merge(
|
|
464
402
|
gp.imports(
|