@autorest/python 5.19.0 → 6.0.0-rc.1
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 +29 -2
- package/README.md +9 -0
- package/autorest/codegen/__init__.py +18 -29
- package/autorest/codegen/models/base_builder.py +17 -6
- package/autorest/codegen/models/client.py +1 -1
- package/autorest/codegen/models/code_model.py +7 -12
- package/autorest/codegen/models/lro_operation.py +2 -6
- package/autorest/codegen/models/lro_paging_operation.py +3 -9
- package/autorest/codegen/models/model_type.py +1 -6
- package/autorest/codegen/models/operation.py +6 -37
- package/autorest/codegen/models/operation_group.py +4 -7
- package/autorest/codegen/models/paging_operation.py +2 -6
- package/autorest/codegen/models/parameter.py +3 -7
- package/autorest/codegen/models/parameter_list.py +20 -36
- package/autorest/codegen/models/request_builder.py +0 -22
- package/autorest/codegen/serializers/__init__.py +3 -50
- package/autorest/codegen/serializers/builder_serializer.py +30 -36
- package/autorest/codegen/serializers/client_serializer.py +14 -31
- package/autorest/codegen/serializers/general_serializer.py +2 -7
- package/autorest/codegen/serializers/import_serializer.py +11 -22
- package/autorest/codegen/serializers/metadata_serializer.py +0 -2
- package/autorest/codegen/serializers/{model_base_serializer.py → model_serializer.py} +47 -38
- package/autorest/codegen/serializers/operation_groups_serializer.py +0 -7
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -23
- package/autorest/codegen/serializers/patch_serializer.py +1 -3
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -4
- package/autorest/codegen/serializers/utils.py +1 -4
- package/autorest/codegen/templates/client.py.jinja2 +3 -3
- package/autorest/codegen/templates/config.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +5 -12
- package/autorest/codegen/templates/operation_group.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +0 -6
- package/autorest/codegen/templates/patch.py.jinja2 +1 -2
- package/autorest/codegen/templates/request_builders.py.jinja2 +0 -3
- package/autorest/codegen/templates/rest_init.py.jinja2 +3 -8
- package/autorest/m4reformatter/__init__.py +9 -3
- package/autorest/multiapi/serializers/__init__.py +3 -8
- package/autorest/multiapi/serializers/import_serializer.py +4 -8
- package/package.json +2 -2
- package/autorest/codegen/serializers/model_generic_serializer.py +0 -32
- package/autorest/codegen/serializers/model_python3_serializer.py +0 -72
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from abc import abstractmethod
|
|
7
6
|
from typing import cast, List
|
|
8
7
|
from jinja2 import Environment
|
|
9
8
|
from ..models import ModelType, CodeModel, Property
|
|
@@ -27,22 +26,17 @@ def _documentation_string(
|
|
|
27
26
|
return retval
|
|
28
27
|
|
|
29
28
|
|
|
30
|
-
class
|
|
31
|
-
def __init__(
|
|
32
|
-
self, code_model: CodeModel, env: Environment, is_python3_file: bool
|
|
33
|
-
) -> None:
|
|
29
|
+
class ModelSerializer:
|
|
30
|
+
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
34
31
|
self.code_model = code_model
|
|
35
32
|
self.env = env
|
|
36
|
-
self.is_python3_file = is_python3_file
|
|
37
33
|
|
|
38
34
|
def serialize(self) -> str:
|
|
39
35
|
# Generate the models
|
|
40
36
|
template = self.env.get_template("model_container.py.jinja2")
|
|
41
37
|
return template.render(
|
|
42
38
|
code_model=self.code_model,
|
|
43
|
-
imports=FileImportSerializer(
|
|
44
|
-
self.imports(), is_python3_file=self.is_python3_file
|
|
45
|
-
),
|
|
39
|
+
imports=FileImportSerializer(self.imports()),
|
|
46
40
|
str=str,
|
|
47
41
|
serializer=self,
|
|
48
42
|
)
|
|
@@ -54,6 +48,11 @@ class ModelBaseSerializer:
|
|
|
54
48
|
)
|
|
55
49
|
for model in self.code_model.model_types:
|
|
56
50
|
file_import.merge(model.imports(is_operation_file=False))
|
|
51
|
+
init_line_parameters = [
|
|
52
|
+
p for p in model.properties if not p.readonly and not p.is_discriminator
|
|
53
|
+
]
|
|
54
|
+
for param in init_line_parameters:
|
|
55
|
+
file_import.merge(param.imports())
|
|
57
56
|
return file_import
|
|
58
57
|
|
|
59
58
|
@staticmethod
|
|
@@ -92,18 +91,12 @@ class ModelBaseSerializer:
|
|
|
92
91
|
def variable_documentation_string(prop: Property) -> List[str]:
|
|
93
92
|
return _documentation_string(prop, "ivar", "vartype")
|
|
94
93
|
|
|
95
|
-
@abstractmethod
|
|
96
|
-
def super_call_template(self, model: ModelType) -> str:
|
|
97
|
-
...
|
|
98
|
-
|
|
99
94
|
def super_call(self, model: ModelType):
|
|
100
|
-
return self.
|
|
101
|
-
self.properties_to_pass_to_super(model)
|
|
102
|
-
)
|
|
95
|
+
return f"super().__init__({self.properties_to_pass_to_super(model)})"
|
|
103
96
|
|
|
104
97
|
def initialize_properties(self, model: ModelType) -> List[str]:
|
|
105
98
|
init_args = []
|
|
106
|
-
for prop in
|
|
99
|
+
for prop in self.get_properties_to_initialize(model):
|
|
107
100
|
if prop.is_discriminator:
|
|
108
101
|
discriminator_value = (
|
|
109
102
|
f"'{model.discriminator_value}'"
|
|
@@ -120,13 +113,17 @@ class ModelBaseSerializer:
|
|
|
120
113
|
elif prop.readonly:
|
|
121
114
|
init_args.append(f"self.{prop.client_name} = None")
|
|
122
115
|
elif not prop.constant:
|
|
123
|
-
init_args.append(self.
|
|
116
|
+
init_args.append(f"self.{prop.client_name} = {prop.client_name}")
|
|
124
117
|
return init_args
|
|
125
118
|
|
|
126
|
-
|
|
119
|
+
@staticmethod
|
|
120
|
+
def initialize_standard_property(prop: Property):
|
|
127
121
|
if not (prop.optional or prop.client_default_value is not None):
|
|
128
|
-
return
|
|
129
|
-
return
|
|
122
|
+
return f"{prop.client_name}: {prop.type_annotation()},{prop.pylint_disable}"
|
|
123
|
+
return (
|
|
124
|
+
f"{prop.client_name}: {prop.type_annotation()} = "
|
|
125
|
+
f"{prop.client_default_value_declaration},{prop.pylint_disable}"
|
|
126
|
+
)
|
|
130
127
|
|
|
131
128
|
@staticmethod
|
|
132
129
|
def discriminator_docstring(model: ModelType) -> str:
|
|
@@ -135,22 +132,34 @@ class ModelBaseSerializer:
|
|
|
135
132
|
f"Known sub-classes are: {', '.join(v.name for v in model.discriminated_subtypes.values())}"
|
|
136
133
|
)
|
|
137
134
|
|
|
138
|
-
@abstractmethod
|
|
139
135
|
def init_line(self, model: ModelType) -> List[str]:
|
|
140
|
-
|
|
136
|
+
init_properties_declaration = []
|
|
137
|
+
init_line_parameters = [
|
|
138
|
+
p
|
|
139
|
+
for p in model.properties
|
|
140
|
+
if not p.readonly and not p.is_discriminator and not p.constant
|
|
141
|
+
]
|
|
142
|
+
init_line_parameters.sort(key=lambda x: x.optional)
|
|
143
|
+
if init_line_parameters:
|
|
144
|
+
init_properties_declaration.append("*,")
|
|
145
|
+
for param in init_line_parameters:
|
|
146
|
+
init_properties_declaration.append(self.initialize_standard_property(param))
|
|
147
|
+
|
|
148
|
+
return init_properties_declaration
|
|
141
149
|
|
|
142
|
-
@
|
|
143
|
-
def properties_to_pass_to_super(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
@staticmethod
|
|
151
|
+
def properties_to_pass_to_super(model: ModelType) -> str:
|
|
152
|
+
properties_to_pass_to_super = []
|
|
153
|
+
for parent in model.parents:
|
|
154
|
+
for prop in model.properties:
|
|
155
|
+
if (
|
|
156
|
+
prop in parent.properties
|
|
157
|
+
and not prop.is_discriminator
|
|
158
|
+
and not prop.constant
|
|
159
|
+
and not prop.readonly
|
|
160
|
+
):
|
|
161
|
+
properties_to_pass_to_super.append(
|
|
162
|
+
f"{prop.client_name}={prop.client_name}"
|
|
163
|
+
)
|
|
164
|
+
properties_to_pass_to_super.append("**kwargs")
|
|
165
|
+
return ", ".join(properties_to_pass_to_super)
|
|
@@ -22,13 +22,11 @@ class OperationGroupsSerializer:
|
|
|
22
22
|
code_model: CodeModel,
|
|
23
23
|
env: Environment,
|
|
24
24
|
async_mode: bool,
|
|
25
|
-
is_python3_file: bool,
|
|
26
25
|
operation_group: Optional[OperationGroup] = None,
|
|
27
26
|
) -> None:
|
|
28
27
|
self.code_model = code_model
|
|
29
28
|
self.env = env
|
|
30
29
|
self.async_mode = async_mode
|
|
31
|
-
self.is_python3_file = is_python3_file
|
|
32
30
|
self.operation_group = operation_group
|
|
33
31
|
|
|
34
32
|
def serialize(self) -> str:
|
|
@@ -42,7 +40,6 @@ class OperationGroupsSerializer:
|
|
|
42
40
|
imports.merge(
|
|
43
41
|
operation_group.imports(
|
|
44
42
|
async_mode=self.async_mode,
|
|
45
|
-
is_python3_file=self.is_python3_file,
|
|
46
43
|
)
|
|
47
44
|
)
|
|
48
45
|
|
|
@@ -54,21 +51,17 @@ class OperationGroupsSerializer:
|
|
|
54
51
|
operation_groups=operation_groups,
|
|
55
52
|
imports=FileImportSerializer(
|
|
56
53
|
imports,
|
|
57
|
-
is_python3_file=self.is_python3_file,
|
|
58
54
|
async_mode=self.async_mode,
|
|
59
55
|
),
|
|
60
56
|
async_mode=self.async_mode,
|
|
61
|
-
is_python3_file=self.is_python3_file,
|
|
62
57
|
get_operation_serializer=functools.partial(
|
|
63
58
|
get_operation_serializer,
|
|
64
59
|
code_model=self.code_model,
|
|
65
60
|
async_mode=self.async_mode,
|
|
66
|
-
is_python3_file=self.is_python3_file,
|
|
67
61
|
),
|
|
68
62
|
request_builder_serializer=RequestBuilderSerializer(
|
|
69
63
|
self.code_model,
|
|
70
64
|
async_mode=False,
|
|
71
|
-
is_python3_file=self.is_python3_file,
|
|
72
65
|
),
|
|
73
66
|
request_builders=[
|
|
74
67
|
rb for rb in self.code_model.request_builders if not rb.abstract
|
|
@@ -18,40 +18,19 @@ class OperationsInitSerializer:
|
|
|
18
18
|
self.env = env
|
|
19
19
|
self.async_mode = async_mode
|
|
20
20
|
|
|
21
|
-
def
|
|
21
|
+
def operation_group_imports(self) -> List[str]:
|
|
22
22
|
def _get_filename(operation_group: OperationGroup) -> str:
|
|
23
|
-
|
|
23
|
+
return (
|
|
24
24
|
"_operations"
|
|
25
25
|
if self.code_model.options["combine_operation_files"]
|
|
26
26
|
else operation_group.filename
|
|
27
27
|
)
|
|
28
|
-
return prefix + filename_suffix
|
|
29
28
|
|
|
30
29
|
return [
|
|
31
30
|
f"from .{_get_filename(og)} import {og.class_name}"
|
|
32
31
|
for og in self.code_model.operation_groups
|
|
33
32
|
]
|
|
34
33
|
|
|
35
|
-
def operation_group_imports(self) -> List[str]:
|
|
36
|
-
typed_py3_files = self.code_model.options["add_python3_operation_files"]
|
|
37
|
-
py3_only = self.code_model.options["python3_only"]
|
|
38
|
-
if typed_py3_files and not py3_only and not self.async_mode:
|
|
39
|
-
retval: List[str] = ["try:"]
|
|
40
|
-
retval.extend(
|
|
41
|
-
[
|
|
42
|
-
f" {line}"
|
|
43
|
-
for line in self._operation_group_imports_helper(
|
|
44
|
-
filename_suffix="_py3"
|
|
45
|
-
)
|
|
46
|
-
]
|
|
47
|
-
)
|
|
48
|
-
retval.append("except (SyntaxError, ImportError):")
|
|
49
|
-
retval.extend(
|
|
50
|
-
[f" {line}" for line in self._operation_group_imports_helper()]
|
|
51
|
-
)
|
|
52
|
-
return retval
|
|
53
|
-
return self._operation_group_imports_helper()
|
|
54
|
-
|
|
55
34
|
def serialize(self) -> str:
|
|
56
35
|
operation_group_init_template = self.env.get_template(
|
|
57
36
|
"operations_folder_init.py.jinja2"
|
|
@@ -19,9 +19,7 @@ class PatchSerializer:
|
|
|
19
19
|
imports.add_submodule_import(
|
|
20
20
|
"typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
21
21
|
)
|
|
22
|
-
is_python3_file = self.code_model.options["python3_only"]
|
|
23
22
|
return template.render(
|
|
24
23
|
code_model=self.code_model,
|
|
25
|
-
imports=FileImportSerializer(imports
|
|
26
|
-
is_python3_file=is_python3_file,
|
|
24
|
+
imports=FileImportSerializer(imports),
|
|
27
25
|
)
|
|
@@ -18,13 +18,11 @@ class RequestBuildersSerializer:
|
|
|
18
18
|
code_model: CodeModel,
|
|
19
19
|
env: Environment,
|
|
20
20
|
request_builders: List[RequestBuilderType],
|
|
21
|
-
is_python3_file: bool,
|
|
22
21
|
) -> None:
|
|
23
22
|
self.code_model = code_model
|
|
24
23
|
self.env = env
|
|
25
24
|
self.request_builders = request_builders
|
|
26
25
|
self.group_name = request_builders[0].group_name
|
|
27
|
-
self.is_python3_file = is_python3_file
|
|
28
26
|
|
|
29
27
|
@property
|
|
30
28
|
def imports(self) -> FileImport:
|
|
@@ -49,9 +47,8 @@ class RequestBuildersSerializer:
|
|
|
49
47
|
request_builders=[rb for rb in self.request_builders if not rb.abstract],
|
|
50
48
|
imports=FileImportSerializer(
|
|
51
49
|
self.imports,
|
|
52
|
-
is_python3_file=True,
|
|
53
50
|
),
|
|
54
51
|
request_builder_serializer=RequestBuilderSerializer(
|
|
55
|
-
self.code_model, async_mode=False
|
|
52
|
+
self.code_model, async_mode=False
|
|
56
53
|
),
|
|
57
54
|
)
|
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
def method_signature_and_response_type_annotation_template(
|
|
9
9
|
*,
|
|
10
|
-
is_python3_file: bool,
|
|
11
10
|
method_signature: str,
|
|
12
11
|
response_type_annotation: str,
|
|
13
12
|
) -> str:
|
|
14
|
-
|
|
15
|
-
return f"{method_signature} -> {response_type_annotation}:"
|
|
16
|
-
return f"{method_signature}:\n # type: (...) -> {response_type_annotation}"
|
|
13
|
+
return f"{method_signature} -> {response_type_annotation}:"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
{{ imports }}
|
|
8
8
|
|
|
9
|
-
{{ serializer.class_definition
|
|
9
|
+
{{ serializer.class_definition }}
|
|
10
10
|
"""{{ op_tools.wrap_string(code_model.client.description, "\n") | indent }}
|
|
11
11
|
|
|
12
12
|
{{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
{% if serializer.should_init_super %}
|
|
15
15
|
super().__init__()
|
|
16
16
|
{% endif %}
|
|
17
|
-
{% if code_model.client.parameters.kwargs_to_pop
|
|
18
|
-
{{ op_tools.serialize(serializer.pop_kwargs_from_signature(
|
|
17
|
+
{% if code_model.client.parameters.kwargs_to_pop %}
|
|
18
|
+
{{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
|
|
19
19
|
{% endif %}
|
|
20
20
|
{% if code_model.client.has_parameterized_host %}
|
|
21
21
|
{{ serializer.host_variable_name }} = {{ keywords.escape_str(code_model.client.url) }}
|
|
@@ -22,8 +22,8 @@ class {{ code_model.client.name }}Configuration(Configuration): # pylint: disab
|
|
|
22
22
|
{{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
|
|
23
23
|
{{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
|
|
24
24
|
super({{ code_model.client.name }}Configuration, self).__init__(**kwargs)
|
|
25
|
-
{% if code_model.config.parameters.kwargs_to_pop
|
|
26
|
-
{{ op_tools.serialize(serializer.pop_kwargs_from_signature(
|
|
25
|
+
{% if code_model.config.parameters.kwargs_to_pop %}
|
|
26
|
+
{{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
|
|
27
27
|
{% endif %}
|
|
28
28
|
{% if serializer.check_required_parameters() %}
|
|
29
29
|
{{ op_tools.serialize(serializer.check_required_parameters()) | indent(8) -}}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"sync": {
|
|
21
21
|
{% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
|
|
22
22
|
{{ gp.client_name | tojson }}: {
|
|
23
|
-
"signature": {{ gp.method_signature(
|
|
23
|
+
"signature": {{ gp.method_signature(async_mode=False) | tojson }},
|
|
24
24
|
"description": {{ gp.description | tojson }},
|
|
25
25
|
"docstring_type": {{ gp.docstring_type(async_mode=False) | tojson }},
|
|
26
26
|
"required": {{ (not gp.optional) | tojson }}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"async": {
|
|
31
31
|
{% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
|
|
32
32
|
{{ gp.client_name | tojson }}: {
|
|
33
|
-
"signature": {{ (gp.method_signature(
|
|
33
|
+
"signature": {{ (gp.method_signature(async_mode=True)) | tojson }},
|
|
34
34
|
"description": {{ gp.description | tojson }},
|
|
35
35
|
"docstring_type": {{ gp.docstring_type(async_mode=True) | tojson }},
|
|
36
36
|
"required": {{ (not gp.optional) | tojson }}
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
{% if not client.has_parameterized_host %}
|
|
55
55
|
"base_url": {
|
|
56
|
-
"signature": {{ client.parameters.host.method_signature(
|
|
56
|
+
"signature": {{ client.parameters.host.method_signature(async_mode=False) | tojson }},
|
|
57
57
|
"description": "Service URL",
|
|
58
58
|
"docstring_type": "str",
|
|
59
59
|
"required": false
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
{% if not client.has_parameterized_host %}
|
|
77
77
|
"base_url": {
|
|
78
|
-
"signature": {{ client.parameters.host.method_signature(
|
|
78
|
+
"signature": {{ client.parameters.host.method_signature(async_mode=True) | tojson }},
|
|
79
79
|
"description": "Service URL",
|
|
80
80
|
"docstring_type": "str",
|
|
81
81
|
"required": false
|
|
@@ -3,21 +3,14 @@
|
|
|
3
3
|
{{ code_model.options['license_header'] }}
|
|
4
4
|
{% macro iterate_models_py3() %}
|
|
5
5
|
{% for schema in schemas %}
|
|
6
|
-
from .{{ code_model.
|
|
6
|
+
from .{{ code_model.models_filename }} import {{ schema }}
|
|
7
7
|
{% endfor %}
|
|
8
8
|
{% endmacro %}
|
|
9
|
-
|
|
10
9
|
{% if schemas %}
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{{ iterate_models_py3() | indent-}}
|
|
16
|
-
except (SyntaxError, ImportError):
|
|
17
|
-
{% for schema in schemas %}
|
|
18
|
-
from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
|
|
19
|
-
{% endfor %}
|
|
20
|
-
{% endif %}
|
|
10
|
+
|
|
11
|
+
{% for schema in schemas %}
|
|
12
|
+
from .{{ code_model.models_filename }} import {{ schema }}
|
|
13
|
+
{% endfor %}
|
|
21
14
|
{% endif %}
|
|
22
15
|
{% if enums %}
|
|
23
16
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
|
|
2
|
-
{% set base_class = ("(" + operation_group.base_class
|
|
2
|
+
{% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
|
|
3
3
|
{% macro check_abstract_methods() %}
|
|
4
4
|
{% if operation_group.has_abstract_operations %}
|
|
5
5
|
raise_if_not_implemented(self.__class__, [
|
|
@@ -8,18 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
|
|
10
10
|
{{ op_tools.declare_serializer(code_model, request_builders) }}
|
|
11
|
-
{%- if not is_python3_file %}
|
|
12
|
-
# fmt: off
|
|
13
|
-
{% endif %}
|
|
14
11
|
{% for operation_group in operation_groups %}
|
|
15
12
|
{% for request_builder in request_builders | selectattr("group_name", "equalto", operation_group.property_name) | rejectattr("is_overload") %}
|
|
16
13
|
|
|
17
14
|
{% include "request_builder.py.jinja2" %}
|
|
18
15
|
{% endfor %}
|
|
19
16
|
{% endfor %}
|
|
20
|
-
{% if not is_python3_file %}
|
|
21
|
-
# fmt: on
|
|
22
|
-
{% endif %}
|
|
23
17
|
{% endif %}
|
|
24
18
|
{% for operation_group in operation_groups %}
|
|
25
19
|
{% include "operation_group.py.jinja2" %}
|
|
@@ -8,8 +8,7 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python
|
|
|
8
8
|
"""
|
|
9
9
|
{{ imports }}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
__all__{{ type_annotation if is_python3_file else "" }} = []{{ "" if is_python3_file else (" # type" + type_annotation) }} # Add all objects you want publicly available to users at this package level
|
|
11
|
+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
|
|
13
12
|
|
|
14
13
|
def patch_sdk():
|
|
15
14
|
"""Do not remove from this file.
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
{{ code_model.options['license_header'] }}
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{% endfor %}
|
|
8
|
-
except (SyntaxError, ImportError):
|
|
9
|
-
{% for request_builder in request_builders %}
|
|
10
|
-
from ._request_builders import {{ request_builder.name }} # type: ignore
|
|
11
|
-
{% endfor %}
|
|
4
|
+
{% for request_builder in request_builders %}
|
|
5
|
+
from ._request_builders import {{ request_builder.name }}
|
|
6
|
+
{% endfor %}
|
|
12
7
|
|
|
13
8
|
__all__ = [
|
|
14
9
|
{% for request_builder in request_builders %}
|
|
@@ -494,6 +494,13 @@ class M4Reformatter(YamlUpdatePlugin): # pylint: disable=too-many-public-method
|
|
|
494
494
|
in_overriden = (
|
|
495
495
|
body_parameter["type"]["type"] == "combined" if body_parameter else False
|
|
496
496
|
)
|
|
497
|
+
abstract = False
|
|
498
|
+
if body_parameter and (
|
|
499
|
+
body_parameter.get("entries")
|
|
500
|
+
or len(body_parameter["type"].get("types", [])) > 2
|
|
501
|
+
):
|
|
502
|
+
# this means it's formdata or urlencoded, or there are more than 2 types of body
|
|
503
|
+
abstract = True
|
|
497
504
|
return {
|
|
498
505
|
"name": yaml_data["language"]["default"]["name"],
|
|
499
506
|
"description": yaml_data["language"]["default"]["description"],
|
|
@@ -520,6 +527,7 @@ class M4Reformatter(YamlUpdatePlugin): # pylint: disable=too-many-public-method
|
|
|
520
527
|
"discriminator": "operation",
|
|
521
528
|
"isOverload": is_overload,
|
|
522
529
|
"apiVersions": _get_api_versions(yaml_data.get("apiVersions", [])),
|
|
530
|
+
"abstract": abstract,
|
|
523
531
|
}
|
|
524
532
|
|
|
525
533
|
def get_operation_creator(
|
|
@@ -1072,9 +1080,7 @@ class M4Reformatter(YamlUpdatePlugin): # pylint: disable=too-many-public-method
|
|
|
1072
1080
|
"skipUrlEncoding": True,
|
|
1073
1081
|
"inOverload": False,
|
|
1074
1082
|
}
|
|
1075
|
-
if self.
|
|
1076
|
-
"version-tolerant"
|
|
1077
|
-
) or self._autorestapi.get_boolean_value("low-level-client"):
|
|
1083
|
+
if self.version_tolerant or self.low_level_client:
|
|
1078
1084
|
parameters.append(credential)
|
|
1079
1085
|
else:
|
|
1080
1086
|
parameters.insert(0, credential)
|
|
@@ -57,18 +57,14 @@ class MultiAPISerializer(object):
|
|
|
57
57
|
)
|
|
58
58
|
|
|
59
59
|
# serialize service client file
|
|
60
|
-
imports = FileImportSerializer(
|
|
61
|
-
code_model.client.imports(async_mode), is_python3_file=async_mode
|
|
62
|
-
)
|
|
60
|
+
imports = FileImportSerializer(code_model.client.imports(async_mode))
|
|
63
61
|
self._autorestapi.write_file(
|
|
64
62
|
_get_file_path(code_model.client.filename, async_mode),
|
|
65
63
|
_render_template("client", imports=imports),
|
|
66
64
|
)
|
|
67
65
|
|
|
68
66
|
# serialize config file
|
|
69
|
-
imports = FileImportSerializer(
|
|
70
|
-
code_model.config.imports(async_mode), is_python3_file=async_mode
|
|
71
|
-
)
|
|
67
|
+
imports = FileImportSerializer(code_model.config.imports(async_mode))
|
|
72
68
|
self._autorestapi.write_file(
|
|
73
69
|
_get_file_path("_configuration", async_mode),
|
|
74
70
|
_render_template("config", imports=imports),
|
|
@@ -77,8 +73,7 @@ class MultiAPISerializer(object):
|
|
|
77
73
|
# serialize mixins
|
|
78
74
|
if code_model.operation_mixin_group.mixin_operations:
|
|
79
75
|
imports = FileImportSerializer(
|
|
80
|
-
code_model.operation_mixin_group.imports(async_mode)
|
|
81
|
-
is_python3_file=async_mode,
|
|
76
|
+
code_model.operation_mixin_group.imports(async_mode)
|
|
82
77
|
)
|
|
83
78
|
self._autorestapi.write_file(
|
|
84
79
|
_get_file_path("_operations_mixin", async_mode),
|
|
@@ -54,9 +54,8 @@ def _get_import_clauses(
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
class FileImportSerializer:
|
|
57
|
-
def __init__(self, file_import: FileImport
|
|
57
|
+
def __init__(self, file_import: FileImport) -> None:
|
|
58
58
|
self._file_import = file_import
|
|
59
|
-
self.is_python3_file = is_python3_file
|
|
60
59
|
|
|
61
60
|
def _switch_typing_section_key(self, new_key: TypingSection):
|
|
62
61
|
switched_dictionary = {}
|
|
@@ -84,10 +83,7 @@ class FileImportSerializer:
|
|
|
84
83
|
return file_import_copy.imports.get(baseline_typing_section, {})
|
|
85
84
|
|
|
86
85
|
def _add_type_checking_import(self):
|
|
87
|
-
if self._file_import.imports.get(TypingSection.TYPING)
|
|
88
|
-
not self.is_python3_file
|
|
89
|
-
and self._file_import.imports.get(TypingSection.CONDITIONAL)
|
|
90
|
-
):
|
|
86
|
+
if self._file_import.imports.get(TypingSection.TYPING):
|
|
91
87
|
self._file_import.add_submodule_import(
|
|
92
88
|
"typing", "TYPE_CHECKING", ImportType.STDLIB
|
|
93
89
|
)
|
|
@@ -97,7 +93,7 @@ class FileImportSerializer:
|
|
|
97
93
|
regular_imports = ""
|
|
98
94
|
regular_imports_dict = self._get_imports_dict(
|
|
99
95
|
baseline_typing_section=TypingSection.REGULAR,
|
|
100
|
-
add_conditional_typing=
|
|
96
|
+
add_conditional_typing=True,
|
|
101
97
|
)
|
|
102
98
|
|
|
103
99
|
if regular_imports_dict:
|
|
@@ -108,7 +104,7 @@ class FileImportSerializer:
|
|
|
108
104
|
typing_imports = ""
|
|
109
105
|
typing_imports_dict = self._get_imports_dict(
|
|
110
106
|
baseline_typing_section=TypingSection.TYPING,
|
|
111
|
-
add_conditional_typing=
|
|
107
|
+
add_conditional_typing=False,
|
|
112
108
|
)
|
|
113
109
|
if typing_imports_dict:
|
|
114
110
|
typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "node run-python3.js prepare.py",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@autorest/system-requirements": "~1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@microsoft.azure/autorest.testserver": "^3.3.
|
|
30
|
+
"@microsoft.azure/autorest.testserver": "^3.3.29"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"autorest/**/*.py",
|
|
@@ -1,32 +0,0 @@
|
|
|
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 typing import List
|
|
7
|
-
from jinja2 import Environment
|
|
8
|
-
from .model_base_serializer import ModelBaseSerializer
|
|
9
|
-
from ..models import ModelType, CodeModel, Property
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ModelGenericSerializer(ModelBaseSerializer):
|
|
13
|
-
def __init__(self, code_model: CodeModel, env: Environment) -> None:
|
|
14
|
-
super().__init__(code_model=code_model, env=env, is_python3_file=False)
|
|
15
|
-
|
|
16
|
-
def init_line(self, model: ModelType) -> List[str]:
|
|
17
|
-
return []
|
|
18
|
-
|
|
19
|
-
def properties_to_pass_to_super(self, model: ModelType) -> str:
|
|
20
|
-
return "**kwargs"
|
|
21
|
-
|
|
22
|
-
def required_property_no_default_init(self, prop: Property) -> str:
|
|
23
|
-
return f"self.{prop.client_name} = kwargs['{prop.client_name}']"
|
|
24
|
-
|
|
25
|
-
def optional_property_init(self, prop: Property) -> str:
|
|
26
|
-
return f"self.{prop.client_name} = kwargs.get('{prop.client_name}', {prop.client_default_value_declaration})"
|
|
27
|
-
|
|
28
|
-
def initialize_standard_arg(self, prop: Property) -> str:
|
|
29
|
-
return self.initialize_standard_property(prop)
|
|
30
|
-
|
|
31
|
-
def super_call_template(self, model: ModelType) -> str:
|
|
32
|
-
return "super(" + model.name + ", self).__init__({})"
|