@autorest/python 5.11.2 → 5.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +69 -0
- package/autorest/codegen/__init__.py +5 -5
- package/autorest/codegen/models/__init__.py +3 -23
- package/autorest/codegen/models/base_builder.py +2 -5
- package/autorest/codegen/models/client.py +2 -2
- package/autorest/codegen/models/code_model.py +5 -1
- package/autorest/codegen/models/operation_group.py +5 -3
- package/autorest/codegen/models/parameter.py +7 -8
- package/autorest/codegen/models/parameter_list.py +32 -27
- package/autorest/codegen/models/request_builder.py +5 -1
- package/autorest/codegen/models/request_builder_parameter.py +4 -5
- package/autorest/codegen/models/request_builder_parameter_list.py +18 -11
- package/autorest/codegen/models/rest.py +3 -2
- package/autorest/codegen/models/utils.py +8 -0
- package/autorest/codegen/serializers/__init__.py +48 -48
- package/autorest/codegen/serializers/builder_serializer.py +150 -146
- package/autorest/codegen/serializers/client_serializer.py +37 -9
- package/autorest/codegen/serializers/general_serializer.py +7 -5
- package/autorest/codegen/serializers/import_serializer.py +6 -6
- package/autorest/codegen/serializers/metadata_serializer.py +2 -2
- package/autorest/codegen/serializers/model_base_serializer.py +3 -3
- package/autorest/codegen/serializers/model_generic_serializer.py +1 -1
- package/autorest/codegen/serializers/model_python3_serializer.py +1 -1
- package/autorest/codegen/serializers/{operation_group_serializer.py → operation_groups_serializer.py} +27 -29
- package/autorest/codegen/serializers/operations_init_serializer.py +34 -2
- package/autorest/codegen/serializers/patch_serializer.py +15 -0
- package/autorest/codegen/serializers/rest_serializer.py +9 -4
- package/autorest/codegen/serializers/utils.py +2 -2
- package/autorest/codegen/templates/config.py.jinja2 +1 -11
- package/autorest/codegen/templates/init.py.jinja2 +4 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +5 -5
- package/autorest/codegen/templates/model_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/{operations_class.py.jinja2 → operation_group.py.jinja2} +2 -0
- package/autorest/codegen/templates/{operations_container.py.jinja2 → operation_groups_container.py.jinja2} +7 -21
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +13 -0
- package/autorest/codegen/templates/patch.py.jinja2 +31 -0
- package/autorest/codegen/templates/request_builder.py.jinja2 +7 -2
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
- package/autorest/codegen/templates/setup.py.jinja2 +1 -1
- package/autorest/multiapi/serializers/__init__.py +3 -3
- package/autorest/multiapi/serializers/import_serializer.py +5 -5
- package/autorest/namer/name_converter.py +3 -1
- package/install.py +1 -0
- package/package.json +4 -3
- package/requirements.txt +14 -0
- package/setup.py +1 -0
- package/autorest/codegen/templates/operations_class_mixin.py.jinja2 +0 -16
- package/autorest/codegen/templates/operations_container_init.py.jinja2 +0 -24
- package/autorest/codegen/templates/operations_container_mixin.py.jinja2 +0 -21
- package/autorest/codegen/templates/operations_init.py.jinja2 +0 -26
|
@@ -9,27 +9,32 @@ from ..models import CodeModel
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class ClientSerializer:
|
|
12
|
-
def __init__(self, code_model: CodeModel) -> None:
|
|
12
|
+
def __init__(self, code_model: CodeModel, is_python3_file: bool) -> None:
|
|
13
13
|
self.code_model = code_model
|
|
14
|
+
self.is_python3_file = is_python3_file
|
|
14
15
|
|
|
15
16
|
def _init_signature(self, async_mode: bool) -> str:
|
|
16
17
|
return utils.serialize_method(
|
|
17
18
|
function_def="def",
|
|
18
19
|
method_name="__init__",
|
|
19
20
|
is_in_class=True,
|
|
20
|
-
method_param_signatures=self.code_model.service_client.parameters.client_method_signature(
|
|
21
|
+
method_param_signatures=self.code_model.service_client.parameters.client_method_signature(
|
|
22
|
+
async_mode or self.is_python3_file
|
|
23
|
+
),
|
|
21
24
|
)
|
|
22
25
|
|
|
23
26
|
def init_signature_and_response_type_annotation(self, async_mode: bool) -> str:
|
|
24
27
|
init_signature = self._init_signature(async_mode)
|
|
25
28
|
return utils.method_signature_and_response_type_annotation_template(
|
|
26
|
-
|
|
29
|
+
is_python3_file=async_mode or self.is_python3_file,
|
|
27
30
|
method_signature=init_signature,
|
|
28
31
|
response_type_annotation="None",
|
|
29
32
|
)
|
|
30
33
|
|
|
31
34
|
def pop_kwargs_from_signature(self, async_mode: bool) -> List[str]:
|
|
32
|
-
return utils.pop_kwargs_from_signature(self.code_model.service_client.parameters.kwargs_to_pop(
|
|
35
|
+
return utils.pop_kwargs_from_signature(self.code_model.service_client.parameters.kwargs_to_pop(
|
|
36
|
+
async_mode or self.is_python3_file
|
|
37
|
+
))
|
|
33
38
|
|
|
34
39
|
def class_definition(self, async_mode) -> str:
|
|
35
40
|
class_name = self.code_model.class_name
|
|
@@ -37,7 +42,7 @@ class ClientSerializer:
|
|
|
37
42
|
base_class = ""
|
|
38
43
|
if has_mixin_og:
|
|
39
44
|
base_class = f"{class_name}OperationsMixin"
|
|
40
|
-
elif not async_mode:
|
|
45
|
+
elif not (async_mode or self.is_python3_file):
|
|
41
46
|
base_class = "object"
|
|
42
47
|
if base_class:
|
|
43
48
|
return f"class {class_name}({base_class}):"
|
|
@@ -107,13 +112,15 @@ class ClientSerializer:
|
|
|
107
112
|
function_def="def",
|
|
108
113
|
method_name=self.code_model.send_request_name,
|
|
109
114
|
is_in_class=True,
|
|
110
|
-
method_param_signatures=self.code_model.service_client.send_request_signature(
|
|
115
|
+
method_param_signatures=self.code_model.service_client.send_request_signature(
|
|
116
|
+
async_mode, async_mode or self.is_python3_file
|
|
117
|
+
),
|
|
111
118
|
)
|
|
112
119
|
|
|
113
120
|
def send_request_signature_and_response_type_annotation(self, async_mode: bool) -> str:
|
|
114
121
|
send_request_signature = self._send_request_signature(async_mode)
|
|
115
122
|
return utils.method_signature_and_response_type_annotation_template(
|
|
116
|
-
|
|
123
|
+
is_python3_file=async_mode or self.is_python3_file,
|
|
117
124
|
method_signature=send_request_signature,
|
|
118
125
|
response_type_annotation="Awaitable[AsyncHttpResponse]" if async_mode else "HttpResponse",
|
|
119
126
|
)
|
|
@@ -179,11 +186,32 @@ class ClientSerializer:
|
|
|
179
186
|
|
|
180
187
|
class ConfigSerializer:
|
|
181
188
|
|
|
182
|
-
def __init__(self, code_model: CodeModel) -> None:
|
|
189
|
+
def __init__(self, code_model: CodeModel, is_python3_file: bool) -> None:
|
|
183
190
|
self.code_model = code_model
|
|
191
|
+
self.is_python3_file = is_python3_file
|
|
192
|
+
|
|
193
|
+
def _init_signature(self, async_mode: bool) -> str:
|
|
194
|
+
return utils.serialize_method(
|
|
195
|
+
function_def="def",
|
|
196
|
+
method_name="__init__",
|
|
197
|
+
is_in_class=True,
|
|
198
|
+
method_param_signatures=self.code_model.global_parameters.config_method_signature(
|
|
199
|
+
async_mode or self.is_python3_file
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def init_signature_and_response_type_annotation(self, async_mode: bool) -> str:
|
|
204
|
+
init_signature = self._init_signature(async_mode)
|
|
205
|
+
return utils.method_signature_and_response_type_annotation_template(
|
|
206
|
+
is_python3_file=async_mode or self.is_python3_file,
|
|
207
|
+
method_signature=init_signature,
|
|
208
|
+
response_type_annotation="None",
|
|
209
|
+
)
|
|
184
210
|
|
|
185
211
|
def pop_kwargs_from_signature(self, async_mode: bool) -> List[str]:
|
|
186
|
-
return utils.pop_kwargs_from_signature(self.code_model.global_parameters.config_kwargs_to_pop(
|
|
212
|
+
return utils.pop_kwargs_from_signature(self.code_model.global_parameters.config_kwargs_to_pop(
|
|
213
|
+
async_mode or self.is_python3_file
|
|
214
|
+
))
|
|
187
215
|
|
|
188
216
|
def set_constants(self) -> List[str]:
|
|
189
217
|
return [
|
|
@@ -54,13 +54,14 @@ class GeneralSerializer:
|
|
|
54
54
|
):
|
|
55
55
|
self._correct_credential_parameter()
|
|
56
56
|
|
|
57
|
+
python3_only = self.code_model.options["python3_only"]
|
|
57
58
|
return template.render(
|
|
58
59
|
code_model=self.code_model,
|
|
59
60
|
async_mode=self.async_mode,
|
|
60
|
-
serializer=ClientSerializer(self.code_model),
|
|
61
|
+
serializer=ClientSerializer(self.code_model, is_python3_file=python3_only),
|
|
61
62
|
imports=FileImportSerializer(
|
|
62
63
|
self.code_model.service_client.imports(self.async_mode),
|
|
63
|
-
|
|
64
|
+
is_python3_file=self.async_mode or python3_only
|
|
64
65
|
),
|
|
65
66
|
)
|
|
66
67
|
|
|
@@ -80,7 +81,7 @@ class GeneralSerializer:
|
|
|
80
81
|
code_model=self.code_model,
|
|
81
82
|
imports=FileImportSerializer(
|
|
82
83
|
file_import,
|
|
83
|
-
|
|
84
|
+
is_python3_file=self.async_mode,
|
|
84
85
|
)
|
|
85
86
|
)
|
|
86
87
|
|
|
@@ -99,15 +100,16 @@ class GeneralSerializer:
|
|
|
99
100
|
self._correct_credential_parameter()
|
|
100
101
|
|
|
101
102
|
template = self.env.get_template("config.py.jinja2")
|
|
103
|
+
python3_only = self.code_model.options["python3_only"]
|
|
102
104
|
return template.render(
|
|
103
105
|
code_model=self.code_model,
|
|
104
106
|
async_mode=self.async_mode,
|
|
105
107
|
imports=FileImportSerializer(
|
|
106
108
|
config_imports(
|
|
107
109
|
self.code_model, self.code_model.global_parameters, self.async_mode
|
|
108
|
-
),
|
|
110
|
+
), is_python3_file=self.async_mode or python3_only
|
|
109
111
|
),
|
|
110
|
-
serializer=ConfigSerializer(self.code_model),
|
|
112
|
+
serializer=ConfigSerializer(self.code_model, is_python3_file=python3_only),
|
|
111
113
|
sdk_moniker=sdk_moniker,
|
|
112
114
|
)
|
|
113
115
|
|
|
@@ -42,9 +42,9 @@ def _get_import_clauses(
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
class FileImportSerializer:
|
|
45
|
-
def __init__(self, file_import: FileImport,
|
|
45
|
+
def __init__(self, file_import: FileImport, is_python3_file: bool, async_mode: bool = False) -> None:
|
|
46
46
|
self._file_import = file_import
|
|
47
|
-
self.
|
|
47
|
+
self.is_python3_file = is_python3_file
|
|
48
48
|
self.async_mode = async_mode
|
|
49
49
|
|
|
50
50
|
def _switch_typing_section_key(self, new_key: TypingSection):
|
|
@@ -67,14 +67,14 @@ class FileImportSerializer:
|
|
|
67
67
|
def _add_type_checking_import(self):
|
|
68
68
|
if (
|
|
69
69
|
self._file_import.imports.get(TypingSection.TYPING) or
|
|
70
|
-
(not self.
|
|
70
|
+
(not self.is_python3_file and self._file_import.imports.get(TypingSection.CONDITIONAL))
|
|
71
71
|
):
|
|
72
72
|
self._file_import.add_from_import("typing", "TYPE_CHECKING", ImportType.STDLIB)
|
|
73
73
|
|
|
74
74
|
def _get_typing_definitions(self) -> str:
|
|
75
75
|
if not self._file_import.type_definitions:
|
|
76
76
|
return ""
|
|
77
|
-
spacing = "" if self.
|
|
77
|
+
spacing = "" if self.is_python3_file else " "
|
|
78
78
|
declarations: List[str] = [f"\n{spacing}T = TypeVar('T')"]
|
|
79
79
|
declarations.extend([
|
|
80
80
|
"{}{} = {}".format(
|
|
@@ -90,7 +90,7 @@ class FileImportSerializer:
|
|
|
90
90
|
self._add_type_checking_import()
|
|
91
91
|
regular_imports = ""
|
|
92
92
|
regular_imports_dict = self._get_imports_dict(
|
|
93
|
-
baseline_typing_section=TypingSection.REGULAR, add_conditional_typing=self.
|
|
93
|
+
baseline_typing_section=TypingSection.REGULAR, add_conditional_typing=self.is_python3_file
|
|
94
94
|
)
|
|
95
95
|
|
|
96
96
|
if regular_imports_dict:
|
|
@@ -100,7 +100,7 @@ class FileImportSerializer:
|
|
|
100
100
|
|
|
101
101
|
typing_imports = ""
|
|
102
102
|
typing_imports_dict = self._get_imports_dict(
|
|
103
|
-
baseline_typing_section=TypingSection.TYPING, add_conditional_typing=not self.
|
|
103
|
+
baseline_typing_section=TypingSection.TYPING, add_conditional_typing=not self.is_python3_file
|
|
104
104
|
)
|
|
105
105
|
if typing_imports_dict:
|
|
106
106
|
typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
|
|
@@ -185,9 +185,9 @@ class MetadataSerializer:
|
|
|
185
185
|
config_imports(self.code_model, async_global_parameters, async_mode=True).imports
|
|
186
186
|
),
|
|
187
187
|
get_async_operation_serializer=functools.partial(
|
|
188
|
-
get_operation_serializer, code_model=self.code_model, async_mode=True,
|
|
188
|
+
get_operation_serializer, code_model=self.code_model, async_mode=True, is_python3_file=True
|
|
189
189
|
),
|
|
190
190
|
get_sync_operation_serializer=functools.partial(
|
|
191
|
-
get_operation_serializer, code_model=self.code_model, async_mode=False,
|
|
191
|
+
get_operation_serializer, code_model=self.code_model, async_mode=False, is_python3_file=False
|
|
192
192
|
),
|
|
193
193
|
)
|
|
@@ -24,17 +24,17 @@ def _documentation_string(
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class ModelBaseSerializer:
|
|
27
|
-
def __init__(self, code_model: CodeModel, env: Environment,
|
|
27
|
+
def __init__(self, code_model: CodeModel, env: Environment, is_python3_file: bool) -> None:
|
|
28
28
|
self.code_model = code_model
|
|
29
29
|
self.env = env
|
|
30
|
-
self.
|
|
30
|
+
self.is_python3_file = is_python3_file
|
|
31
31
|
|
|
32
32
|
def serialize(self) -> str:
|
|
33
33
|
# Generate the models
|
|
34
34
|
template = self.env.get_template("model_container.py.jinja2")
|
|
35
35
|
return template.render(
|
|
36
36
|
code_model=self.code_model,
|
|
37
|
-
imports=FileImportSerializer(self.imports(),
|
|
37
|
+
imports=FileImportSerializer(self.imports(), is_python3_file=self.is_python3_file),
|
|
38
38
|
str=str,
|
|
39
39
|
init_line=self.init_line,
|
|
40
40
|
init_args=self.init_args,
|
|
@@ -13,7 +13,7 @@ class ModelGenericSerializer(ModelBaseSerializer):
|
|
|
13
13
|
|
|
14
14
|
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
15
15
|
super(ModelGenericSerializer, self).__init__(
|
|
16
|
-
code_model=code_model, env=env,
|
|
16
|
+
code_model=code_model, env=env, is_python3_file=False
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
def init_line(self, model: ObjectSchema) -> List[str]:
|
|
@@ -14,7 +14,7 @@ class ModelPython3Serializer(ModelBaseSerializer):
|
|
|
14
14
|
|
|
15
15
|
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
16
16
|
super(ModelPython3Serializer, self).__init__(
|
|
17
|
-
code_model=code_model, env=env,
|
|
17
|
+
code_model=code_model, env=env, is_python3_file=True
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
def init_line(self, model: ObjectSchema) -> List[str]:
|
|
@@ -3,30 +3,34 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Optional
|
|
6
7
|
import functools
|
|
7
|
-
from copy import copy
|
|
8
|
-
from typing import List
|
|
9
8
|
from jinja2 import Environment
|
|
10
9
|
|
|
10
|
+
from ..models import (
|
|
11
|
+
CodeModel,
|
|
12
|
+
OperationGroup,
|
|
13
|
+
FileImport,
|
|
14
|
+
LROOperation,
|
|
15
|
+
PagingOperation
|
|
16
|
+
)
|
|
11
17
|
from .import_serializer import FileImportSerializer
|
|
12
|
-
from ..models import LROOperation, PagingOperation, CodeModel, OperationGroup
|
|
13
18
|
from .builder_serializer import get_operation_serializer, get_request_builder_serializer
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
class OperationGroupSerializer:
|
|
20
|
+
class OperationGroupsSerializer:
|
|
17
21
|
def __init__(
|
|
18
22
|
self,
|
|
19
23
|
code_model: CodeModel,
|
|
20
24
|
env: Environment,
|
|
21
|
-
operation_groups: List[OperationGroup],
|
|
22
25
|
async_mode: bool,
|
|
23
|
-
|
|
26
|
+
is_python3_file: bool,
|
|
27
|
+
operation_group: Optional[OperationGroup] = None,
|
|
24
28
|
) -> None:
|
|
25
29
|
self.code_model = code_model
|
|
26
30
|
self.env = env
|
|
27
|
-
self.operation_groups = operation_groups
|
|
28
31
|
self.async_mode = async_mode
|
|
29
|
-
self.
|
|
32
|
+
self.is_python3_file = is_python3_file
|
|
33
|
+
self.operation_group = operation_group
|
|
30
34
|
|
|
31
35
|
def serialize(self) -> str:
|
|
32
36
|
def _is_lro(operation):
|
|
@@ -34,39 +38,33 @@ class OperationGroupSerializer:
|
|
|
34
38
|
|
|
35
39
|
def _is_paging(operation):
|
|
36
40
|
return isinstance(operation, PagingOperation)
|
|
41
|
+
operation_groups = [self.operation_group] if self.operation_group else self.code_model.operation_groups
|
|
42
|
+
imports = FileImport()
|
|
43
|
+
for operation_group in operation_groups:
|
|
44
|
+
imports.merge(operation_group.imports(
|
|
45
|
+
async_mode=self.async_mode,
|
|
46
|
+
))
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
operation_group_template = self.env.get_template("operations_container_mixin.py.jinja2")
|
|
41
|
-
|
|
42
|
-
has_schemas = self.code_model.schemas or self.code_model.enums
|
|
43
|
-
|
|
44
|
-
# extract all operations from operation_groups
|
|
45
|
-
operaions_all = [operation for groups in self.operation_groups for operation in groups.operations]
|
|
46
|
-
operation_group_temp = copy(self.operation_groups[0])
|
|
47
|
-
operation_group_temp.operations = operaions_all
|
|
48
|
-
|
|
49
|
-
return operation_group_template.render(
|
|
48
|
+
template = self.env.get_or_select_template("operation_groups_container.py.jinja2")
|
|
49
|
+
return template.render(
|
|
50
50
|
code_model=self.code_model,
|
|
51
|
-
operation_groups=
|
|
51
|
+
operation_groups=operation_groups,
|
|
52
52
|
imports=FileImportSerializer(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
has_schemas=bool(has_schemas)
|
|
56
|
-
), is_python_3_file=self.is_python_3_file,
|
|
53
|
+
imports,
|
|
54
|
+
is_python3_file=self.is_python3_file,
|
|
57
55
|
async_mode=self.async_mode
|
|
58
56
|
),
|
|
59
57
|
async_mode=self.async_mode,
|
|
60
|
-
|
|
58
|
+
is_python3_file=self.is_python3_file,
|
|
61
59
|
is_lro=_is_lro,
|
|
62
60
|
is_paging=_is_paging,
|
|
63
61
|
get_operation_serializer=functools.partial(
|
|
64
62
|
get_operation_serializer,
|
|
65
63
|
code_model=self.code_model,
|
|
66
64
|
async_mode=self.async_mode,
|
|
67
|
-
|
|
65
|
+
is_python3_file=self.is_python3_file,
|
|
68
66
|
),
|
|
69
67
|
request_builder_serializer=get_request_builder_serializer(
|
|
70
|
-
self.code_model, self.
|
|
68
|
+
self.code_model, self.is_python3_file,
|
|
71
69
|
),
|
|
72
70
|
)
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import List
|
|
6
7
|
from jinja2 import Environment
|
|
8
|
+
|
|
9
|
+
from autorest.codegen.models.operation_group import OperationGroup
|
|
7
10
|
from ..models import CodeModel
|
|
8
11
|
|
|
9
12
|
|
|
@@ -13,9 +16,38 @@ class OperationsInitSerializer:
|
|
|
13
16
|
self.env = env
|
|
14
17
|
self.async_mode = async_mode
|
|
15
18
|
|
|
19
|
+
def _operation_group_imports_helper(self, filename_suffix: str = "") -> List[str]:
|
|
20
|
+
def _get_filename(operation_group: OperationGroup) -> str:
|
|
21
|
+
prefix = "_operations" if self.code_model.options["combine_operation_files"] else operation_group.filename
|
|
22
|
+
return prefix + filename_suffix
|
|
23
|
+
return [
|
|
24
|
+
f"from .{_get_filename(og)} import {og.class_name}"
|
|
25
|
+
for og in self.code_model.operation_groups
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
def operation_group_imports(self) -> List[str]:
|
|
29
|
+
typed_py3_files = self.code_model.options["add_python3_operation_files"]
|
|
30
|
+
py3_only = self.code_model.options["python3_only"]
|
|
31
|
+
if typed_py3_files and not py3_only and not self.async_mode:
|
|
32
|
+
retval: List[str] = ["try:"]
|
|
33
|
+
retval.extend([
|
|
34
|
+
f" {line}"
|
|
35
|
+
for line in self._operation_group_imports_helper(filename_suffix="_py3")
|
|
36
|
+
])
|
|
37
|
+
retval.append("except (SyntaxError, ImportError):")
|
|
38
|
+
retval.extend([
|
|
39
|
+
f" {line}"
|
|
40
|
+
for line in self._operation_group_imports_helper()
|
|
41
|
+
])
|
|
42
|
+
return retval
|
|
43
|
+
return self._operation_group_imports_helper()
|
|
44
|
+
|
|
16
45
|
def serialize(self) -> str:
|
|
17
|
-
operation_group_init_template = self.env.get_template("
|
|
46
|
+
operation_group_init_template = self.env.get_template("operations_folder_init.py.jinja2")
|
|
18
47
|
|
|
19
48
|
return operation_group_init_template.render(
|
|
20
|
-
code_model=self.code_model,
|
|
49
|
+
code_model=self.code_model,
|
|
50
|
+
operation_groups=self.code_model.operation_groups,
|
|
51
|
+
async_mode=self.async_mode,
|
|
52
|
+
operation_group_imports=self.operation_group_imports,
|
|
21
53
|
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from jinja2 import Environment
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PatchSerializer:
|
|
10
|
+
def __init__(self, env: Environment) -> None:
|
|
11
|
+
self.env = env
|
|
12
|
+
|
|
13
|
+
def serialize(self) -> str:
|
|
14
|
+
template = self.env.get_template("patch.py.jinja2")
|
|
15
|
+
return template.render()
|
|
@@ -20,6 +20,7 @@ class RestSerializer:
|
|
|
20
20
|
self.code_model = code_model
|
|
21
21
|
self.env = env
|
|
22
22
|
self.request_builders = request_builders
|
|
23
|
+
self.builder_group_name = request_builders[0].builder_group_name
|
|
23
24
|
|
|
24
25
|
def serialize_init(self) -> str:
|
|
25
26
|
template = self.env.get_template("rest_init.py.jinja2")
|
|
@@ -33,8 +34,10 @@ class RestPython3Serializer(RestSerializer):
|
|
|
33
34
|
return template.render(
|
|
34
35
|
code_model=self.code_model,
|
|
35
36
|
request_builders=self.request_builders,
|
|
36
|
-
imports=FileImportSerializer(self.code_model.rest.imports(
|
|
37
|
-
|
|
37
|
+
imports=FileImportSerializer(self.code_model.rest.imports(
|
|
38
|
+
self.builder_group_name
|
|
39
|
+
), is_python3_file=True),
|
|
40
|
+
is_python3_file=True,
|
|
38
41
|
request_builder_serializer=RequestBuilderPython3Serializer(self.code_model),
|
|
39
42
|
)
|
|
40
43
|
|
|
@@ -46,7 +49,9 @@ class RestGenericSerializer(RestSerializer):
|
|
|
46
49
|
return template.render(
|
|
47
50
|
code_model=self.code_model,
|
|
48
51
|
request_builders=self.request_builders,
|
|
49
|
-
imports=FileImportSerializer(self.code_model.rest.imports(
|
|
50
|
-
|
|
52
|
+
imports=FileImportSerializer(self.code_model.rest.imports(
|
|
53
|
+
self.builder_group_name
|
|
54
|
+
), is_python3_file=False),
|
|
55
|
+
is_python3_file=False,
|
|
51
56
|
request_builder_serializer=RequestBuilderGenericSerializer(self.code_model),
|
|
52
57
|
)
|
|
@@ -90,11 +90,11 @@ def serialize_path(
|
|
|
90
90
|
|
|
91
91
|
def method_signature_and_response_type_annotation_template(
|
|
92
92
|
*,
|
|
93
|
-
|
|
93
|
+
is_python3_file: bool,
|
|
94
94
|
method_signature: str,
|
|
95
95
|
response_type_annotation: str,
|
|
96
96
|
) -> str:
|
|
97
|
-
if
|
|
97
|
+
if is_python3_file:
|
|
98
98
|
return f"{method_signature} -> {response_type_annotation}:"
|
|
99
99
|
return f"{method_signature}:\n # type: (...) -> {response_type_annotation}"
|
|
100
100
|
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
{% import 'keywords.jinja2' as keywords with context %}
|
|
2
2
|
{% import 'operation_tools.jinja2' as op_tools %}
|
|
3
3
|
{% set version_import = ".._version" if async_mode else "._version" %}
|
|
4
|
-
{% macro method_signature() %}
|
|
5
|
-
def __init__(
|
|
6
|
-
self,
|
|
7
|
-
{% for param_signature in code_model.global_parameters.config_method_signature(async_mode) %}
|
|
8
|
-
{{ param_signature }}
|
|
9
|
-
{% endfor %}
|
|
10
|
-
){{" -> None" if async_mode else "" }}:{% endmacro %}
|
|
11
4
|
{# actual template starts here #}
|
|
12
5
|
# coding=utf-8
|
|
13
6
|
{{ code_model.options['license_header'] }}
|
|
@@ -32,10 +25,7 @@ class {{ code_model.class_name }}Configuration(Configuration):
|
|
|
32
25
|
{% endfor %}
|
|
33
26
|
"""
|
|
34
27
|
|
|
35
|
-
{{
|
|
36
|
-
{% if not async_mode %}
|
|
37
|
-
# type: (...) -> None
|
|
38
|
-
{% endif %}
|
|
28
|
+
{{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
|
|
39
29
|
super({{ code_model.class_name }}Configuration, self).__init__(**kwargs)
|
|
40
30
|
{% if code_model.service_client.parameters.config_kwargs_to_pop(async_mode) %}
|
|
41
31
|
{{ op_tools.serialize(serializer.pop_kwargs_from_signature(async_mode)) | indent(8) }}
|
|
@@ -9,8 +9,7 @@ __version__ = VERSION
|
|
|
9
9
|
{% endif %}
|
|
10
10
|
__all__ = ['{{ code_model.class_name }}']
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
pass
|
|
12
|
+
# `._patch.py` is used for handwritten extensions to the generated code
|
|
13
|
+
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
|
|
14
|
+
from ._patch import patch_sdk
|
|
15
|
+
patch_sdk()
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"global_parameters": {
|
|
20
20
|
"sync": {
|
|
21
|
-
{% for gp in sync_global_parameters.config_method %}
|
|
21
|
+
{% for gp in sync_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
|
|
22
22
|
{{ gp.serialized_name | tojson }}: {
|
|
23
|
-
"signature": {{ gp.method_signature(
|
|
23
|
+
"signature": {{ gp.method_signature(is_python3_file=False) | tojson }},
|
|
24
24
|
"description": {{ gp.description | tojson }},
|
|
25
25
|
"docstring_type": {{ gp.docstring_type | tojson }},
|
|
26
26
|
"required": {{ gp.required | tojson }}
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
{% endfor %}
|
|
29
29
|
},
|
|
30
30
|
"async": {
|
|
31
|
-
{% for gp in async_global_parameters.config_method %}
|
|
31
|
+
{% for gp in async_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
|
|
32
32
|
{{ gp.serialized_name | tojson }}: {
|
|
33
|
-
"signature": {{ (gp.method_signature(
|
|
33
|
+
"signature": {{ (gp.method_signature(is_python3_file=True)) | tojson }},
|
|
34
34
|
"description": {{ gp.description | tojson }},
|
|
35
35
|
"docstring_type": {{ gp.docstring_type | tojson }},
|
|
36
36
|
"required": {{ gp.required | tojson }}
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
{{ gp.serialized_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
|
|
43
43
|
{% endfor %}
|
|
44
44
|
},
|
|
45
|
-
"call": {{ code_model.global_parameters.config_method | map(attribute="serialized_name") | join(', ') | tojson }},
|
|
45
|
+
"call": {{ code_model.global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") | map(attribute="serialized_name") | join(', ') | tojson }},
|
|
46
46
|
"service_client_specific": {
|
|
47
47
|
"sync": {
|
|
48
48
|
"api_version": {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
class {{ operation_group.class_name }}{{ object_base_class }}:
|
|
2
|
+
{% if not operation_group.is_empty_operation_group %}
|
|
2
3
|
"""{{ operation_group.class_name }} {{ operations_description }}.
|
|
3
4
|
|
|
4
5
|
You should not instantiate this class directly. Instead, you should create a Client instance that
|
|
@@ -23,6 +24,7 @@ class {{ operation_group.class_name }}{{ object_base_class }}:
|
|
|
23
24
|
self._serialize = serializer
|
|
24
25
|
self._deserialize = deserializer
|
|
25
26
|
self._config = config
|
|
27
|
+
{% endif %}
|
|
26
28
|
{% for operation in operation_group.operations %}
|
|
27
29
|
|
|
28
30
|
{% set request_builder = operation.request_builder %}
|
|
@@ -2,39 +2,25 @@
|
|
|
2
2
|
{% set object_base_class = "" if async_mode else "(object)" %}
|
|
3
3
|
{% set operations_description = "async operations" if async_mode else "operations" %}
|
|
4
4
|
{% set return_none_type_annotation = " -> None" if async_mode else "" %}
|
|
5
|
-
{% set operation_group = operation_groups[0] %}
|
|
6
5
|
# coding=utf-8
|
|
7
6
|
{{ code_model.options['license_header'] }}
|
|
8
7
|
{{ imports }}
|
|
9
8
|
|
|
10
9
|
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
|
|
11
10
|
{{ op_tools.declare_serializer(code_model) }}
|
|
12
|
-
{%- if not
|
|
11
|
+
{%- if not is_python3_file %}
|
|
13
12
|
# fmt: off
|
|
14
13
|
{% endif %}
|
|
15
|
-
{%
|
|
14
|
+
{% for operation_group in operation_groups %}
|
|
16
15
|
{% for request_builder in code_model.rest.request_builders | selectattr("operation_group_name", "equalto", operation_group.name) %}
|
|
17
16
|
|
|
18
17
|
{% include "request_builder.py.jinja2" %}
|
|
19
18
|
{% endfor %}
|
|
20
|
-
{%
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{% include "request_builder.py.jinja2" %}
|
|
24
|
-
{% endfor %}
|
|
25
|
-
{% endif %}
|
|
26
|
-
{% if not is_python_3_file %}
|
|
19
|
+
{% endfor %}
|
|
20
|
+
{% if not is_python3_file %}
|
|
27
21
|
# fmt: on
|
|
28
22
|
{% endif %}
|
|
29
23
|
{% endif %}
|
|
30
|
-
{%
|
|
31
|
-
{% include "
|
|
32
|
-
{%
|
|
33
|
-
{% for operation_group in operation_groups %}
|
|
34
|
-
{% if operation_group.is_empty_operation_group %}
|
|
35
|
-
{% include "operations_class_mixin.py.jinja2" %}
|
|
36
|
-
{% else %}
|
|
37
|
-
{% include "operations_class.py.jinja2" %}
|
|
38
|
-
{% endif %}
|
|
39
|
-
{% endfor %}
|
|
40
|
-
{% endif %}
|
|
24
|
+
{% for operation_group in operation_groups %}
|
|
25
|
+
{% include "operation_group.py.jinja2" %}
|
|
26
|
+
{% endfor %}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
+
{# actual template starts here #}
|
|
3
|
+
# coding=utf-8
|
|
4
|
+
{{ code_model.options['license_header'] }}
|
|
5
|
+
|
|
6
|
+
{{ op_tools.serialize(operation_group_imports()) }}
|
|
7
|
+
{% if operation_groups %}
|
|
8
|
+
__all__ = [
|
|
9
|
+
{% for operation_group in operation_groups %}
|
|
10
|
+
'{{ operation_group.class_name }}',
|
|
11
|
+
{% endfor %}
|
|
12
|
+
]
|
|
13
|
+
{% endif %}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# --------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# The MIT License (MIT)
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the ""Software""), to
|
|
10
|
+
# deal in the Software without restriction, including without limitation the
|
|
11
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
12
|
+
# sell copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
# IN THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
# --------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
# This file is used for handwritten extensions to the generated code. Example:
|
|
29
|
+
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
|
|
30
|
+
def patch_sdk():
|
|
31
|
+
pass
|