@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
|
@@ -66,9 +66,7 @@ class MultiAPI(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
66
66
|
) -> None:
|
|
67
67
|
super().__init__(output_folder=Path(output_folder).resolve(), **kwargs)
|
|
68
68
|
if input_package_name is None:
|
|
69
|
-
raise ValueError(
|
|
70
|
-
"package-name is required, either provide it as args or check your readme configuration"
|
|
71
|
-
)
|
|
69
|
+
raise ValueError("package-name is required, either provide it as args or check your readme configuration")
|
|
72
70
|
self.input_package_name = input_package_name
|
|
73
71
|
_LOGGER.debug("Received package name %s", input_package_name)
|
|
74
72
|
_LOGGER.debug("Received output-folder %s", output_folder)
|
|
@@ -116,8 +114,7 @@ class MultiAPI(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
116
114
|
# If not, if it exists a stable API version for a global or RT, will always be used
|
|
117
115
|
return cast(
|
|
118
116
|
bool,
|
|
119
|
-
self.user_specified_default_api
|
|
120
|
-
and "preview" in self.user_specified_default_api,
|
|
117
|
+
self.user_specified_default_api and "preview" in self.user_specified_default_api,
|
|
121
118
|
)
|
|
122
119
|
|
|
123
120
|
@property
|
|
@@ -147,9 +144,7 @@ class MultiAPI(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
147
144
|
total_api_version_list = metadata_json["total_api_version_list"]
|
|
148
145
|
if not version:
|
|
149
146
|
if total_api_version_list:
|
|
150
|
-
sys.exit(
|
|
151
|
-
f"Unable to match {total_api_version_list} to label {version_path.stem}"
|
|
152
|
-
)
|
|
147
|
+
sys.exit(f"Unable to match {total_api_version_list} to label {version_path.stem}")
|
|
153
148
|
else:
|
|
154
149
|
sys.exit(f"Unable to extract api version of {version_path.stem}")
|
|
155
150
|
mod_to_api_version[version_path.name] = version
|
|
@@ -186,6 +181,4 @@ class MultiAPIAutorest(MultiAPI, ReaderAndWriterAutorest):
|
|
|
186
181
|
|
|
187
182
|
@property
|
|
188
183
|
def serializer(self) -> MultiAPISerializer:
|
|
189
|
-
return MultiAPISerializerAutorest(
|
|
190
|
-
self._autorestapi, output_folder=self.output_folder
|
|
191
|
-
)
|
|
184
|
+
return MultiAPISerializerAutorest(self._autorestapi, output_folder=self.output_folder)
|
|
@@ -16,9 +16,7 @@ def _extract_version(metadata_json: Dict[str, Any], version_path: Path) -> str:
|
|
|
16
16
|
total_api_version_list = metadata_json["total_api_version_list"]
|
|
17
17
|
if not version:
|
|
18
18
|
if total_api_version_list:
|
|
19
|
-
sys.exit(
|
|
20
|
-
f"Unable to match {total_api_version_list} to label {version_path.stem}"
|
|
21
|
-
)
|
|
19
|
+
sys.exit(f"Unable to match {total_api_version_list} to label {version_path.stem}")
|
|
22
20
|
else:
|
|
23
21
|
sys.exit(f"Unable to extract api version of {version_path.stem}")
|
|
24
22
|
return version
|
|
@@ -36,20 +34,14 @@ class Client:
|
|
|
36
34
|
self.filename = default_version_metadata["client"]["filename"]
|
|
37
35
|
self.host_value = default_version_metadata["client"]["host_value"]
|
|
38
36
|
self.description = default_version_metadata["client"]["description"]
|
|
39
|
-
self.client_side_validation = default_version_metadata["client"][
|
|
40
|
-
"client_side_validation"
|
|
41
|
-
]
|
|
37
|
+
self.client_side_validation = default_version_metadata["client"]["client_side_validation"]
|
|
42
38
|
self.default_version_metadata = default_version_metadata
|
|
43
39
|
self.version_path_to_metadata = version_path_to_metadata
|
|
44
40
|
|
|
45
41
|
def imports(self, async_mode: bool) -> FileImport:
|
|
46
42
|
imports_to_load = "async_imports" if async_mode else "sync_imports"
|
|
47
|
-
file_import = FileImport(
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
local_imports = file_import.imports.get(TypingSection.REGULAR, {}).get(
|
|
51
|
-
ImportType.LOCAL, {}
|
|
52
|
-
)
|
|
43
|
+
file_import = FileImport(json.loads(self.default_version_metadata["client"][imports_to_load]))
|
|
44
|
+
local_imports = file_import.imports.get(TypingSection.REGULAR, {}).get(ImportType.LOCAL, {})
|
|
53
45
|
for key in local_imports:
|
|
54
46
|
if re.search("^\\.*_serialization$", key):
|
|
55
47
|
relative_path = ".." if async_mode else "."
|
|
@@ -61,22 +53,16 @@ class Client:
|
|
|
61
53
|
def parameterized_host_template_to_api_version(self) -> Dict[str, List[str]]:
|
|
62
54
|
parameterized_host_template_to_api_version: Dict[str, List[str]] = {}
|
|
63
55
|
for version_path, metadata_json in self.version_path_to_metadata.items():
|
|
64
|
-
parameterized_host_template = metadata_json["client"][
|
|
65
|
-
"parameterized_host_template"
|
|
66
|
-
]
|
|
56
|
+
parameterized_host_template = metadata_json["client"]["parameterized_host_template"]
|
|
67
57
|
version = _extract_version(metadata_json, version_path)
|
|
68
|
-
parameterized_host_template_to_api_version.setdefault(
|
|
69
|
-
parameterized_host_template, []
|
|
70
|
-
).append(version)
|
|
58
|
+
parameterized_host_template_to_api_version.setdefault(parameterized_host_template, []).append(version)
|
|
71
59
|
return parameterized_host_template_to_api_version
|
|
72
60
|
|
|
73
61
|
@property
|
|
74
62
|
def has_public_lro_operations(self) -> bool:
|
|
75
63
|
has_public_lro_operations = False
|
|
76
64
|
for _, metadata_json in self.version_path_to_metadata.items():
|
|
77
|
-
current_client_has_public_lro_operations = metadata_json["client"][
|
|
78
|
-
"has_public_lro_operations"
|
|
79
|
-
]
|
|
65
|
+
current_client_has_public_lro_operations = metadata_json["client"]["has_public_lro_operations"]
|
|
80
66
|
if current_client_has_public_lro_operations:
|
|
81
67
|
has_public_lro_operations = True
|
|
82
68
|
return has_public_lro_operations
|
|
@@ -34,16 +34,10 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
34
34
|
self.azure_arm = default_version_metadata["client"]["azure_arm"]
|
|
35
35
|
self.default_version_metadata = default_version_metadata
|
|
36
36
|
self.version_path_to_metadata = version_path_to_metadata
|
|
37
|
-
self.client = Client(
|
|
38
|
-
self.azure_arm, default_version_metadata, version_path_to_metadata
|
|
39
|
-
)
|
|
37
|
+
self.client = Client(self.azure_arm, default_version_metadata, version_path_to_metadata)
|
|
40
38
|
self.config = Config(default_version_metadata)
|
|
41
|
-
self.operation_mixin_group = OperationMixinGroup(
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
self.global_parameters = GlobalParameters(
|
|
45
|
-
default_version_metadata["global_parameters"]
|
|
46
|
-
)
|
|
39
|
+
self.operation_mixin_group = OperationMixinGroup(version_path_to_metadata, default_api_version)
|
|
40
|
+
self.global_parameters = GlobalParameters(default_version_metadata["global_parameters"])
|
|
47
41
|
self.user_specified_default_api = user_specified_default_api
|
|
48
42
|
self.options: Dict[str, Any] = {"flavor": "azure", "company_name": "Microsoft"}
|
|
49
43
|
self.core_library = "azure.core"
|
|
@@ -60,16 +54,12 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
60
54
|
operation_group_class_name,
|
|
61
55
|
) in operation_groups_metadata.items():
|
|
62
56
|
try:
|
|
63
|
-
operation_group = [
|
|
64
|
-
og for og in operation_groups if og.name == operation_group_name
|
|
65
|
-
][0]
|
|
57
|
+
operation_group = [og for og in operation_groups if og.name == operation_group_name][0]
|
|
66
58
|
except IndexError:
|
|
67
59
|
operation_group = OperationGroup(operation_group_name)
|
|
68
60
|
operation_groups.append(operation_group)
|
|
69
61
|
operation_group.append_available_api(version_path.name)
|
|
70
|
-
operation_group.append_api_class_name_pair(
|
|
71
|
-
version_path.name, operation_group_class_name
|
|
72
|
-
)
|
|
62
|
+
operation_group.append_api_class_name_pair(version_path.name, operation_group_class_name)
|
|
73
63
|
operation_groups.sort(key=lambda x: x.name)
|
|
74
64
|
return operation_groups
|
|
75
65
|
|
|
@@ -77,10 +67,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
77
67
|
def host_variable_name(self) -> str:
|
|
78
68
|
if self.client.parameterized_host_template_to_api_version:
|
|
79
69
|
return "base_url"
|
|
80
|
-
params =
|
|
81
|
-
self.global_parameters.parameters
|
|
82
|
-
+ self.global_parameters.service_client_specific_global_parameters
|
|
83
|
-
)
|
|
70
|
+
params = self.global_parameters.parameters + self.global_parameters.service_client_specific_global_parameters
|
|
84
71
|
try:
|
|
85
72
|
return next(p for p in params if p.name in ["endpoint", "base_url"]).name
|
|
86
73
|
except StopIteration:
|
|
@@ -121,8 +108,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
121
108
|
|
|
122
109
|
# First let's map operation groups to their available APIs
|
|
123
110
|
versioned_dict = {
|
|
124
|
-
operation_group.name: operation_group.available_apis
|
|
125
|
-
for operation_group in self.operation_groups
|
|
111
|
+
operation_group.name: operation_group.available_apis for operation_group in self.operation_groups
|
|
126
112
|
}
|
|
127
113
|
|
|
128
114
|
# Now let's also include mixins to their available APIs
|
|
@@ -144,9 +130,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
144
130
|
# If some others RT contains "local_default_api_version", and
|
|
145
131
|
# if it's greater than the future default, danger, don't profile it
|
|
146
132
|
if (
|
|
147
|
-
there_is_a_rt_that_contains_api_version(
|
|
148
|
-
versioned_dict, local_default_api_version
|
|
149
|
-
)
|
|
133
|
+
there_is_a_rt_that_contains_api_version(versioned_dict, local_default_api_version)
|
|
150
134
|
and local_default_api_version > self.default_api_version
|
|
151
135
|
):
|
|
152
136
|
continue
|
|
@@ -155,7 +139,4 @@ class CodeModel: # pylint: disable=too-many-instance-attributes
|
|
|
155
139
|
|
|
156
140
|
@property
|
|
157
141
|
def default_models(self):
|
|
158
|
-
return sorted(
|
|
159
|
-
{self.default_api_version}
|
|
160
|
-
| {versions for _, versions in self.last_rt_list.items()}
|
|
161
|
-
)
|
|
142
|
+
return sorted({self.default_api_version} | {versions for _, versions in self.last_rt_list.items()})
|
|
@@ -16,9 +16,7 @@ class Config:
|
|
|
16
16
|
|
|
17
17
|
def imports(self, async_mode: bool) -> FileImport:
|
|
18
18
|
imports_to_load = "async_imports" if async_mode else "sync_imports"
|
|
19
|
-
return FileImport(
|
|
20
|
-
json.loads(self.default_version_metadata["config"][imports_to_load])
|
|
21
|
-
)
|
|
19
|
+
return FileImport(json.loads(self.default_version_metadata["config"][imports_to_load]))
|
|
22
20
|
|
|
23
21
|
def credential_call(self, async_mode: bool) -> str:
|
|
24
22
|
if async_mode:
|
|
@@ -33,31 +33,21 @@ class GlobalParameters:
|
|
|
33
33
|
"""Return global params specific to multiapi service client + config
|
|
34
34
|
api_version, endpoint (re-adding it in specific are), and profile
|
|
35
35
|
"""
|
|
36
|
-
service_client_params_sync = self.global_parameters_metadata[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"service_client_specific"
|
|
41
|
-
]["async"]
|
|
42
|
-
|
|
43
|
-
return _convert_global_parameters(
|
|
44
|
-
service_client_params_sync, service_client_params_async
|
|
45
|
-
)
|
|
36
|
+
service_client_params_sync = self.global_parameters_metadata["service_client_specific"]["sync"]
|
|
37
|
+
service_client_params_async = self.global_parameters_metadata["service_client_specific"]["async"]
|
|
38
|
+
|
|
39
|
+
return _convert_global_parameters(service_client_params_sync, service_client_params_async)
|
|
46
40
|
|
|
47
41
|
@property
|
|
48
42
|
def parameters(self) -> List[GlobalParameter]:
|
|
49
43
|
global_parameters_metadata_sync = self.global_parameters_metadata["sync"]
|
|
50
44
|
global_parameters_metadata_async = self.global_parameters_metadata["async"]
|
|
51
45
|
|
|
52
|
-
return _convert_global_parameters(
|
|
53
|
-
global_parameters_metadata_sync, global_parameters_metadata_async
|
|
54
|
-
)
|
|
46
|
+
return _convert_global_parameters(global_parameters_metadata_sync, global_parameters_metadata_async)
|
|
55
47
|
|
|
56
48
|
@property
|
|
57
49
|
def constant_parameters(self) -> List[ConstantGlobalParameter]:
|
|
58
50
|
return [
|
|
59
51
|
ConstantGlobalParameter(constant_name, constant_value)
|
|
60
|
-
for constant_name, constant_value in self.global_parameters_metadata[
|
|
61
|
-
"constant"
|
|
62
|
-
].items()
|
|
52
|
+
for constant_name, constant_value in self.global_parameters_metadata["constant"].items()
|
|
63
53
|
]
|
|
@@ -43,9 +43,7 @@ class FileImport:
|
|
|
43
43
|
Tuple[
|
|
44
44
|
str,
|
|
45
45
|
Optional[str],
|
|
46
|
-
Tuple[
|
|
47
|
-
Tuple[Tuple[int, int], str, Optional[str]]
|
|
48
|
-
],
|
|
46
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
49
47
|
],
|
|
50
48
|
]
|
|
51
49
|
]
|
|
@@ -125,9 +123,9 @@ class FileImport:
|
|
|
125
123
|
],
|
|
126
124
|
convert_list_to_tuple(name_import),
|
|
127
125
|
)
|
|
128
|
-
self._imports.setdefault(typing_section, {}).setdefault(
|
|
129
|
-
|
|
130
|
-
)
|
|
126
|
+
self._imports.setdefault(typing_section, {}).setdefault(import_type, {}).setdefault(from_section, set()).add(
|
|
127
|
+
name_input
|
|
128
|
+
)
|
|
131
129
|
|
|
132
130
|
def add_submodule_import(
|
|
133
131
|
self,
|
|
@@ -175,6 +173,4 @@ class FileImport:
|
|
|
175
173
|
for import_type, package_list in import_type_dict.items():
|
|
176
174
|
for package_name, module_list in package_list.items():
|
|
177
175
|
for module_name in module_list:
|
|
178
|
-
self._add_import(
|
|
179
|
-
package_name, import_type, module_name, typing_section
|
|
180
|
-
)
|
|
176
|
+
self._add_import(package_name, import_type, module_name, typing_section)
|
|
@@ -32,11 +32,7 @@ class OperationMixinGroup:
|
|
|
32
32
|
return imports
|
|
33
33
|
|
|
34
34
|
def typing_definitions(self, async_mode: bool) -> str:
|
|
35
|
-
key =
|
|
36
|
-
"sync_mixin_typing_definitions"
|
|
37
|
-
if async_mode
|
|
38
|
-
else "async_mixin_typing_definitions"
|
|
39
|
-
)
|
|
35
|
+
key = "sync_mixin_typing_definitions" if async_mode else "async_mixin_typing_definitions"
|
|
40
36
|
origin = "".join(
|
|
41
37
|
[
|
|
42
38
|
metadata_json.get("operation_mixins", {}).get(key, "")
|
|
@@ -45,22 +41,16 @@ class OperationMixinGroup:
|
|
|
45
41
|
)
|
|
46
42
|
return "\n".join(set(origin.split("\n")))
|
|
47
43
|
|
|
48
|
-
def _use_metadata_of_default_api_version(
|
|
49
|
-
self, mixin_operations: List[MixinOperation]
|
|
50
|
-
) -> List[MixinOperation]:
|
|
44
|
+
def _use_metadata_of_default_api_version(self, mixin_operations: List[MixinOperation]) -> List[MixinOperation]:
|
|
51
45
|
default_api_version_path = [
|
|
52
46
|
version_path
|
|
53
47
|
for version_path in self.version_path_to_metadata.keys()
|
|
54
48
|
if version_path.name == self.default_api_version
|
|
55
49
|
][0]
|
|
56
|
-
default_version_metadata = self.version_path_to_metadata[
|
|
57
|
-
default_api_version_path
|
|
58
|
-
]
|
|
50
|
+
default_version_metadata = self.version_path_to_metadata[default_api_version_path]
|
|
59
51
|
if not default_version_metadata.get("operation_mixins"):
|
|
60
52
|
return mixin_operations
|
|
61
|
-
for name, metadata in default_version_metadata["operation_mixins"][
|
|
62
|
-
"operations"
|
|
63
|
-
].items():
|
|
53
|
+
for name, metadata in default_version_metadata["operation_mixins"]["operations"].items():
|
|
64
54
|
if name.startswith("_"):
|
|
65
55
|
continue
|
|
66
56
|
mixin_operation = [mo for mo in mixin_operations if mo.name == name][0]
|
|
@@ -81,9 +71,7 @@ class OperationMixinGroup:
|
|
|
81
71
|
if mixin_operation_name.startswith("_"):
|
|
82
72
|
continue
|
|
83
73
|
try:
|
|
84
|
-
mixin_operation = [
|
|
85
|
-
mo for mo in mixin_operations if mo.name == mixin_operation_name
|
|
86
|
-
][0]
|
|
74
|
+
mixin_operation = [mo for mo in mixin_operations if mo.name == mixin_operation_name][0]
|
|
87
75
|
except IndexError:
|
|
88
76
|
mixin_operation = MixinOperation(
|
|
89
77
|
name=mixin_operation_name,
|
|
@@ -27,13 +27,8 @@ _FILE_TO_TEMPLATE = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def _method_signature_helper(
|
|
31
|
-
|
|
32
|
-
) -> List[str]:
|
|
33
|
-
return [
|
|
34
|
-
p.signature(async_mode)
|
|
35
|
-
for p in sorted(parameters, key=lambda p: p.required, reverse=True)
|
|
36
|
-
]
|
|
30
|
+
def _method_signature_helper(parameters: List[GlobalParameter], async_mode: bool) -> List[str]:
|
|
31
|
+
return [p.signature(async_mode) for p in sorted(parameters, key=lambda p: p.required, reverse=True)]
|
|
37
32
|
|
|
38
33
|
|
|
39
34
|
def _get_file_path(filename: str, async_mode: bool) -> Path:
|
|
@@ -62,39 +57,25 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
62
57
|
code_model.global_parameters.parameters
|
|
63
58
|
+ code_model.global_parameters.service_client_specific_global_parameters
|
|
64
59
|
)
|
|
65
|
-
positional_params = [
|
|
66
|
-
|
|
67
|
-
]
|
|
68
|
-
keyword_only_params = [
|
|
69
|
-
p for p in all_params if p.method_location == "keywordOnly"
|
|
70
|
-
]
|
|
60
|
+
positional_params = [p for p in all_params if p.method_location == "positional"]
|
|
61
|
+
keyword_only_params = [p for p in all_params if p.method_location == "keywordOnly"]
|
|
71
62
|
return template.render(
|
|
72
63
|
code_model=code_model,
|
|
73
64
|
async_mode=async_mode,
|
|
74
|
-
positional_params=_method_signature_helper(
|
|
75
|
-
|
|
76
|
-
),
|
|
77
|
-
keyword_only_params=_method_signature_helper(
|
|
78
|
-
keyword_only_params, async_mode
|
|
79
|
-
),
|
|
65
|
+
positional_params=_method_signature_helper(positional_params, async_mode),
|
|
66
|
+
keyword_only_params=_method_signature_helper(keyword_only_params, async_mode),
|
|
80
67
|
**kwargs
|
|
81
68
|
)
|
|
82
69
|
|
|
83
70
|
# serialize init file
|
|
84
|
-
self.write_file(
|
|
85
|
-
_get_file_path("__init__", async_mode), _render_template("init")
|
|
86
|
-
)
|
|
71
|
+
self.write_file(_get_file_path("__init__", async_mode), _render_template("init"))
|
|
87
72
|
|
|
88
73
|
# serialize service client file
|
|
89
74
|
imports = FileImportSerializer(code_model.client.imports(async_mode))
|
|
90
|
-
config_policies = build_policies(
|
|
91
|
-
code_model.azure_arm, async_mode, is_azure_flavor=True
|
|
92
|
-
)
|
|
75
|
+
config_policies = build_policies(code_model.azure_arm, async_mode, is_azure_flavor=True)
|
|
93
76
|
self.write_file(
|
|
94
77
|
_get_file_path(code_model.client.filename, async_mode),
|
|
95
|
-
_render_template(
|
|
96
|
-
"client", imports=imports, config_policies=config_policies
|
|
97
|
-
),
|
|
78
|
+
_render_template("client", imports=imports, config_policies=config_policies),
|
|
98
79
|
)
|
|
99
80
|
|
|
100
81
|
# serialize config file
|
|
@@ -158,7 +139,5 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
158
139
|
|
|
159
140
|
|
|
160
141
|
class MultiAPISerializerAutorest(MultiAPISerializer, ReaderAndWriterAutorest):
|
|
161
|
-
def __init__(
|
|
162
|
-
self, autorestapi: AutorestAPI, *, output_folder: Union[str, Path]
|
|
163
|
-
) -> None:
|
|
142
|
+
def __init__(self, autorestapi: AutorestAPI, *, output_folder: Union[str, Path]) -> None:
|
|
164
143
|
super().__init__(autorestapi=autorestapi, output_folder=output_folder)
|
|
@@ -57,9 +57,7 @@ def _serialize_package(
|
|
|
57
57
|
)
|
|
58
58
|
for submodule_name, alias, version_modules in versioned_modules:
|
|
59
59
|
for n, (version, module_name, comment) in enumerate(version_modules):
|
|
60
|
-
buffer.append(
|
|
61
|
-
"{} sys.version_info >= {}:".format("if" if n == 0 else "elif", version)
|
|
62
|
-
)
|
|
60
|
+
buffer.append("{} sys.version_info >= {}:".format("if" if n == 0 else "elif", version))
|
|
63
61
|
buffer.append(
|
|
64
62
|
f" from {module_name} import {submodule_name}{f' as {alias}' if alias else ''}"
|
|
65
63
|
f"{f' # {comment}' if comment else ''}"
|
|
@@ -141,34 +139,24 @@ class FileImportSerializer:
|
|
|
141
139
|
|
|
142
140
|
def _switch_typing_section_key(self, new_key: TypingSection):
|
|
143
141
|
switched_dictionary = {}
|
|
144
|
-
switched_dictionary[new_key] = self._file_import.imports[
|
|
145
|
-
TypingSection.CONDITIONAL
|
|
146
|
-
]
|
|
142
|
+
switched_dictionary[new_key] = self._file_import.imports[TypingSection.CONDITIONAL]
|
|
147
143
|
return switched_dictionary
|
|
148
144
|
|
|
149
|
-
def _get_imports_dict(
|
|
150
|
-
self, baseline_typing_section: TypingSection, add_conditional_typing: bool
|
|
151
|
-
):
|
|
145
|
+
def _get_imports_dict(self, baseline_typing_section: TypingSection, add_conditional_typing: bool):
|
|
152
146
|
# If this is a python 3 file, our regular imports include the CONDITIONAL category
|
|
153
147
|
# If this is not a python 3 file, our typing imports include the CONDITIONAL category
|
|
154
148
|
file_import_copy = deepcopy(self._file_import)
|
|
155
|
-
if add_conditional_typing and self._file_import.imports.get(
|
|
156
|
-
TypingSection.CONDITIONAL
|
|
157
|
-
):
|
|
149
|
+
if add_conditional_typing and self._file_import.imports.get(TypingSection.CONDITIONAL):
|
|
158
150
|
# we switch the TypingSection key for the CONDITIONAL typing imports so we can merge
|
|
159
151
|
# the imports together
|
|
160
|
-
switched_imports_dictionary = self._switch_typing_section_key(
|
|
161
|
-
baseline_typing_section
|
|
162
|
-
)
|
|
152
|
+
switched_imports_dictionary = self._switch_typing_section_key(baseline_typing_section)
|
|
163
153
|
switched_imports = FileImport(switched_imports_dictionary)
|
|
164
154
|
file_import_copy.merge(switched_imports)
|
|
165
155
|
return file_import_copy.imports.get(baseline_typing_section, {})
|
|
166
156
|
|
|
167
157
|
def _add_type_checking_import(self):
|
|
168
158
|
if self._file_import.imports.get(TypingSection.TYPING):
|
|
169
|
-
self._file_import.add_submodule_import(
|
|
170
|
-
"typing", "TYPE_CHECKING", ImportType.STDLIB
|
|
171
|
-
)
|
|
159
|
+
self._file_import.add_submodule_import("typing", "TYPE_CHECKING", ImportType.STDLIB)
|
|
172
160
|
|
|
173
161
|
def __str__(self) -> str:
|
|
174
162
|
self._add_type_checking_import()
|
|
@@ -179,9 +167,7 @@ class FileImportSerializer:
|
|
|
179
167
|
)
|
|
180
168
|
|
|
181
169
|
if regular_imports_dict:
|
|
182
|
-
regular_imports = "\n\n".join(
|
|
183
|
-
_get_import_clauses(regular_imports_dict, "\n")
|
|
184
|
-
)
|
|
170
|
+
regular_imports = "\n\n".join(_get_import_clauses(regular_imports_dict, "\n"))
|
|
185
171
|
|
|
186
172
|
typing_imports = ""
|
|
187
173
|
typing_imports_dict = self._get_imports_dict(
|
|
@@ -190,8 +176,6 @@ class FileImportSerializer:
|
|
|
190
176
|
)
|
|
191
177
|
if typing_imports_dict:
|
|
192
178
|
typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
|
|
193
|
-
typing_imports += "\n\n ".join(
|
|
194
|
-
_get_import_clauses(typing_imports_dict, "\n ")
|
|
195
|
-
)
|
|
179
|
+
typing_imports += "\n\n ".join(_get_import_clauses(typing_imports_dict, "\n "))
|
|
196
180
|
|
|
197
181
|
return regular_imports + typing_imports + self._typing_definitions
|
|
@@ -25,17 +25,13 @@ def _get_default_api_version_from_list(
|
|
|
25
25
|
# and change it automatically so I can take both syntax as input
|
|
26
26
|
if user_specified_default_api and not user_specified_default_api.startswith("v"):
|
|
27
27
|
default_api_version = [
|
|
28
|
-
mod_api
|
|
29
|
-
for mod_api, real_api in mod_to_api_version.items()
|
|
30
|
-
if real_api == user_specified_default_api
|
|
28
|
+
mod_api for mod_api, real_api in mod_to_api_version.items() if real_api == user_specified_default_api
|
|
31
29
|
][0]
|
|
32
30
|
_LOGGER.info("Default API version will be: %s", default_api_version)
|
|
33
31
|
return default_api_version
|
|
34
32
|
|
|
35
33
|
absolute_latest = sorted(api_versions_list)[-1]
|
|
36
|
-
not_preview_versions = [
|
|
37
|
-
version for version in api_versions_list if "preview" not in version
|
|
38
|
-
]
|
|
34
|
+
not_preview_versions = [version for version in api_versions_list if "preview" not in version]
|
|
39
35
|
|
|
40
36
|
# If there is no preview, easy: the absolute latest is the only latest
|
|
41
37
|
if not not_preview_versions:
|
|
@@ -33,9 +33,7 @@ class MultiClientPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
33
33
|
template = env.get_template("version.py.jinja2")
|
|
34
34
|
self.write_file(
|
|
35
35
|
Path("_version.py"),
|
|
36
|
-
template.render(
|
|
37
|
-
package_version=self.options.get("package-version") or "1.0.0b1"
|
|
38
|
-
),
|
|
36
|
+
template.render(package_version=self.options.get("package-version") or "1.0.0b1"),
|
|
39
37
|
)
|
|
40
38
|
|
|
41
39
|
# py.typed
|
|
@@ -22,9 +22,7 @@ def format_file(file: Path, file_content: str) -> str:
|
|
|
22
22
|
if not file.suffix == ".py":
|
|
23
23
|
return file_content
|
|
24
24
|
try:
|
|
25
|
-
file_content = black.format_file_contents(
|
|
26
|
-
file_content, fast=True, mode=_BLACK_MODE
|
|
27
|
-
)
|
|
25
|
+
file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)
|
|
28
26
|
except NothingChanged:
|
|
29
27
|
pass
|
|
30
28
|
return file_content
|
|
@@ -98,11 +96,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
98
96
|
return self.get_namespace(next_dir, namespace)
|
|
99
97
|
|
|
100
98
|
def process(self) -> bool:
|
|
101
|
-
folders = [
|
|
102
|
-
f
|
|
103
|
-
for f in self.base_folder.glob("**/*")
|
|
104
|
-
if f.is_dir() and not f.stem.startswith("__")
|
|
105
|
-
]
|
|
99
|
+
folders = [f for f in self.base_folder.glob("**/*") if f.is_dir() and not f.stem.startswith("__")]
|
|
106
100
|
# will always have the root
|
|
107
101
|
self.fix_imports_in_init(
|
|
108
102
|
generated_file_name="_client",
|
|
@@ -128,13 +122,9 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
128
122
|
)
|
|
129
123
|
except StopIteration:
|
|
130
124
|
pass
|
|
131
|
-
operations_folders = [
|
|
132
|
-
f for f in folders if f.stem in ["operations", "_operations"]
|
|
133
|
-
]
|
|
125
|
+
operations_folders = [f for f in folders if f.stem in ["operations", "_operations"]]
|
|
134
126
|
for operations_folder in operations_folders:
|
|
135
|
-
sub_namespace = ".".join(
|
|
136
|
-
str(operations_folder.relative_to(self.base_folder)).split(os.sep)
|
|
137
|
-
)
|
|
127
|
+
sub_namespace = ".".join(str(operations_folder.relative_to(self.base_folder)).split(os.sep))
|
|
138
128
|
self.fix_imports_in_init(
|
|
139
129
|
generated_file_name="_operations",
|
|
140
130
|
folder_path=operations_folder,
|
|
@@ -143,9 +133,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
143
133
|
shutil.rmtree(f"{str(self.output_folder)}/.temp_folder")
|
|
144
134
|
return True
|
|
145
135
|
|
|
146
|
-
def fix_imports_in_init(
|
|
147
|
-
self, generated_file_name: str, folder_path: Path, namespace: str
|
|
148
|
-
) -> None:
|
|
136
|
+
def fix_imports_in_init(self, generated_file_name: str, folder_path: Path, namespace: str) -> None:
|
|
149
137
|
customized_objects_str = python_run(
|
|
150
138
|
self.venv_context,
|
|
151
139
|
command=[namespace, str(self.output_folder)],
|
|
@@ -154,9 +142,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
154
142
|
|
|
155
143
|
if not customized_objects_str:
|
|
156
144
|
return
|
|
157
|
-
customized_objects = {
|
|
158
|
-
k: None for k in customized_objects_str.split(",")
|
|
159
|
-
}.keys() # filter out duplicates
|
|
145
|
+
customized_objects = {k: None for k in customized_objects_str.split(",")}.keys() # filter out duplicates
|
|
160
146
|
file = (folder_path / "__init__.py").relative_to(self.output_folder)
|
|
161
147
|
file_content = self.read_file(file).replace("\r\n", "\n")
|
|
162
148
|
added_objs = []
|
|
@@ -175,16 +161,12 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
175
161
|
"\nexcept ImportError:\n _patch_all = []",
|
|
176
162
|
"",
|
|
177
163
|
)
|
|
178
|
-
file_content = file_content.replace(
|
|
179
|
-
"from ._patch import __all__ as _patch_all", ""
|
|
180
|
-
)
|
|
164
|
+
file_content = file_content.replace("from ._patch import __all__ as _patch_all", "")
|
|
181
165
|
file_content = file_content.replace(
|
|
182
166
|
"from ._patch import * # pylint: disable=unused-wildcard-import\n",
|
|
183
167
|
"",
|
|
184
168
|
)
|
|
185
|
-
file_content = file_content.replace(
|
|
186
|
-
"__all__.extend([p for p in _patch_all if p not in __all__])", ""
|
|
187
|
-
)
|
|
169
|
+
file_content = file_content.replace("__all__.extend([p for p in _patch_all if p not in __all__])", "")
|
|
188
170
|
if added_objs:
|
|
189
171
|
# add import
|
|
190
172
|
patch_sdk_import = "from ._patch import patch_sdk as _patch_sdk"
|
|
@@ -196,9 +178,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
196
178
|
file_content = file_content.replace(patch_sdk_import, replacement)
|
|
197
179
|
# add to __all__
|
|
198
180
|
added_objs_all = "\n".join([f' "{obj}",' for obj in added_objs]) + "\n"
|
|
199
|
-
file_content = file_content.replace(
|
|
200
|
-
"__all__ = [", f"__all__ = [\n{added_objs_all}", 1
|
|
201
|
-
)
|
|
181
|
+
file_content = file_content.replace("__all__ = [", f"__all__ = [\n{added_objs_all}", 1)
|
|
202
182
|
formatted_file = format_file(file, file_content)
|
|
203
183
|
self.write_file(file, formatted_file)
|
|
204
184
|
|
|
@@ -15,7 +15,5 @@ def main(namespace):
|
|
|
15
15
|
if __name__ == "__main__":
|
|
16
16
|
patched = ",".join(main(sys.argv[1]))
|
|
17
17
|
output_folder = sys.argv[2]
|
|
18
|
-
with open(
|
|
19
|
-
f"{output_folder}/.temp_folder/patched.txt", "w", encoding="utf-8-sig"
|
|
20
|
-
) as f:
|
|
18
|
+
with open(f"{output_folder}/.temp_folder/patched.txt", "w", encoding="utf-8-sig") as f:
|
|
21
19
|
f.write(patched)
|
|
@@ -69,9 +69,7 @@ def python_run( # pylint: disable=inconsistent-return-statements
|
|
|
69
69
|
stdout=False,
|
|
70
70
|
)
|
|
71
71
|
if module == "get_all":
|
|
72
|
-
with open(
|
|
73
|
-
f"{command[1]}/.temp_folder/patched.txt", "r", encoding="utf-8-sig"
|
|
74
|
-
) as f:
|
|
72
|
+
with open(f"{command[1]}/.temp_folder/patched.txt", "r", encoding="utf-8-sig") as f:
|
|
75
73
|
return f.read()
|
|
76
74
|
except subprocess.CalledProcessError as err:
|
|
77
75
|
print(err)
|