@autorest/python 5.12.4 → 5.13.0
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 +173 -109
- package/autorest/black/__init__.py +7 -1
- package/autorest/codegen/__init__.py +12 -2
- package/autorest/codegen/models/__init__.py +2 -1
- package/autorest/codegen/models/client.py +22 -19
- package/autorest/codegen/models/constant_schema.py +0 -4
- package/autorest/codegen/models/credential_schema.py +3 -3
- package/autorest/codegen/models/dictionary_schema.py +1 -1
- package/autorest/codegen/models/enum_schema.py +2 -2
- package/autorest/codegen/models/imports.py +90 -50
- package/autorest/codegen/models/list_schema.py +1 -1
- package/autorest/codegen/models/lro_operation.py +15 -9
- package/autorest/codegen/models/object_schema.py +2 -2
- package/autorest/codegen/models/operation.py +39 -30
- package/autorest/codegen/models/operation_group.py +5 -14
- package/autorest/codegen/models/paging_operation.py +9 -9
- package/autorest/codegen/models/parameter.py +37 -11
- package/autorest/codegen/models/parameter_list.py +11 -4
- package/autorest/codegen/models/primitive_schemas.py +2 -2
- package/autorest/codegen/models/property.py +1 -1
- package/autorest/codegen/models/request_builder.py +7 -6
- package/autorest/codegen/models/request_builder_parameter.py +5 -0
- package/autorest/codegen/models/request_builder_parameter_list.py +1 -0
- package/autorest/codegen/models/schema_response.py +1 -1
- package/autorest/codegen/serializers/__init__.py +75 -71
- package/autorest/codegen/serializers/builder_serializer.py +68 -37
- package/autorest/codegen/serializers/client_serializer.py +14 -3
- package/autorest/codegen/serializers/general_serializer.py +7 -7
- package/autorest/codegen/serializers/import_serializer.py +44 -46
- package/autorest/codegen/serializers/metadata_serializer.py +12 -10
- package/autorest/codegen/serializers/utils.py +5 -1
- package/autorest/codegen/templates/config.py.jinja2 +2 -7
- package/autorest/codegen/templates/lro_operation.py.jinja2 +3 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +2 -0
- package/autorest/codegen/templates/operation.py.jinja2 +8 -2
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -1
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +3 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +2 -7
- package/autorest/codegen/templates/service_client.py.jinja2 +1 -1
- package/autorest/multiapi/models/imports.py +1 -1
- package/autorest/multiapi/serializers/import_serializer.py +1 -1
- package/autorest/namer/name_converter.py +1 -1
- package/package.json +2 -2
- package/run-python3.js +1 -7
- package/venvtools.py +2 -2
|
@@ -207,7 +207,9 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
207
207
|
lambda parameter: parameter.implementation == self.implementation
|
|
208
208
|
)
|
|
209
209
|
positional = [p for p in parameters_of_this_implementation if p.is_positional]
|
|
210
|
-
keyword_only =
|
|
210
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
211
|
+
[p for p in parameters_of_this_implementation if p.is_keyword_only]
|
|
212
|
+
)
|
|
211
213
|
kwargs = self._filter_out_multiple_content_type(
|
|
212
214
|
[p for p in parameters_of_this_implementation if p.is_kwarg]
|
|
213
215
|
)
|
|
@@ -275,6 +277,7 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
275
277
|
def _create_files_or_data_param(
|
|
276
278
|
params: List[Parameter], serialized_name: str, description: str
|
|
277
279
|
) -> Parameter:
|
|
280
|
+
params[0].need_import = False
|
|
278
281
|
param = copy(params[0])
|
|
279
282
|
param.serialized_name = serialized_name
|
|
280
283
|
param.schema = DictionarySchema(
|
|
@@ -314,7 +317,9 @@ class ParameterOnlyPathAndBodyPositionalList(ParameterList):
|
|
|
314
317
|
file_and_data_params.append(data_param)
|
|
315
318
|
method_params = [p for p in method_params if not p.is_multipart and not p.is_data_input]
|
|
316
319
|
positional = [p for p in method_params if p.is_positional]
|
|
317
|
-
keyword_only =
|
|
320
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
321
|
+
[p for p in method_params if p.is_keyword_only]
|
|
322
|
+
)
|
|
318
323
|
kwargs = self._filter_out_multiple_content_type(
|
|
319
324
|
[p for p in method_params if p.is_kwarg]
|
|
320
325
|
)
|
|
@@ -337,7 +342,9 @@ class GlobalParameterList(ParameterList):
|
|
|
337
342
|
"""
|
|
338
343
|
# Client level should not be on Method, etc.
|
|
339
344
|
positional = [p for p in self.parameters if p.is_positional]
|
|
340
|
-
keyword_only =
|
|
345
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
346
|
+
[p for p in self.parameters if p.is_keyword_only]
|
|
347
|
+
)
|
|
341
348
|
kwargs = self._filter_out_multiple_content_type(
|
|
342
349
|
[p for p in self.parameters if p.is_kwarg]
|
|
343
350
|
)
|
|
@@ -383,7 +390,7 @@ class GlobalParameterList(ParameterList):
|
|
|
383
390
|
schema=StringSchema(namespace="", yaml_data={"type": "str"}),
|
|
384
391
|
rest_api_name=self.host_variable_name,
|
|
385
392
|
serialized_name=self.host_variable_name,
|
|
386
|
-
description=f"Service URL.
|
|
393
|
+
description=f"Service URL.",
|
|
387
394
|
implementation="Client",
|
|
388
395
|
required=True,
|
|
389
396
|
location=ParameterLocation.Other,
|
|
@@ -116,7 +116,7 @@ class IOSchema(PrimitiveSchema):
|
|
|
116
116
|
|
|
117
117
|
def imports(self) -> FileImport:
|
|
118
118
|
file_import = FileImport()
|
|
119
|
-
file_import.
|
|
119
|
+
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
120
120
|
return file_import
|
|
121
121
|
|
|
122
122
|
class AnySchema(PrimitiveSchema):
|
|
@@ -138,7 +138,7 @@ class AnySchema(PrimitiveSchema):
|
|
|
138
138
|
|
|
139
139
|
def imports(self) -> FileImport:
|
|
140
140
|
file_import = FileImport()
|
|
141
|
-
file_import.
|
|
141
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
142
142
|
return file_import
|
|
143
143
|
|
|
144
144
|
class JSONSchema(AnySchema):
|
|
@@ -170,5 +170,5 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
170
170
|
def model_file_imports(self) -> FileImport:
|
|
171
171
|
file_import = self.schema.model_file_imports()
|
|
172
172
|
if not self.required:
|
|
173
|
-
file_import.
|
|
173
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
174
174
|
return file_import
|
|
@@ -66,9 +66,10 @@ class RequestBuilder(BaseBuilder):
|
|
|
66
66
|
def imports(self) -> FileImport:
|
|
67
67
|
file_import = FileImport()
|
|
68
68
|
for parameter in self.parameters:
|
|
69
|
-
|
|
69
|
+
if parameter.need_import:
|
|
70
|
+
file_import.merge(parameter.imports())
|
|
70
71
|
|
|
71
|
-
file_import.
|
|
72
|
+
file_import.add_submodule_import(
|
|
72
73
|
"azure.core.rest",
|
|
73
74
|
"HttpRequest",
|
|
74
75
|
ImportType.AZURECORE,
|
|
@@ -77,17 +78,17 @@ class RequestBuilder(BaseBuilder):
|
|
|
77
78
|
relative_path = ".."
|
|
78
79
|
if not self.code_model.options["builders_visibility"] == "embedded" and self.operation_group_name:
|
|
79
80
|
relative_path = "..." if self.operation_group_name else ".."
|
|
80
|
-
file_import.
|
|
81
|
+
file_import.add_submodule_import(
|
|
81
82
|
f"{relative_path}_vendor", "_format_url_section", ImportType.LOCAL
|
|
82
83
|
)
|
|
83
84
|
if self.parameters.headers or self.parameters.query:
|
|
84
|
-
file_import.
|
|
85
|
+
file_import.add_submodule_import(
|
|
85
86
|
"typing", "Dict", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
86
87
|
)
|
|
87
|
-
file_import.
|
|
88
|
+
file_import.add_submodule_import(
|
|
88
89
|
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
89
90
|
)
|
|
90
|
-
file_import.
|
|
91
|
+
file_import.add_submodule_import("msrest", "Serializer", ImportType.THIRDPARTY)
|
|
91
92
|
if self.parameters.has_body and (
|
|
92
93
|
self.code_model.options["builders_visibility"] != "embedded" or
|
|
93
94
|
self.code_model.options["add_python3_operation_files"]
|
|
@@ -62,6 +62,11 @@ class RequestBuilderParameter(ParameterOnlyPathAndBodyPositional):
|
|
|
62
62
|
def is_keyword_only(self) -> bool:
|
|
63
63
|
return not self.location == ParameterLocation.Path and not self.is_kwarg
|
|
64
64
|
|
|
65
|
+
@is_keyword_only.setter
|
|
66
|
+
def is_keyword_only(self, val: bool) -> None:
|
|
67
|
+
self._keyword_only = val
|
|
68
|
+
self.is_kwarg = False
|
|
69
|
+
|
|
65
70
|
@property
|
|
66
71
|
def full_serialized_name(self) -> str:
|
|
67
72
|
return self.serialized_name
|
|
@@ -99,7 +99,7 @@ class SchemaResponse(BaseModel):
|
|
|
99
99
|
def imports(self, code_model) -> FileImport:
|
|
100
100
|
file_import = FileImport()
|
|
101
101
|
if not code_model.options["models_mode"] and self.is_xml:
|
|
102
|
-
file_import.
|
|
102
|
+
file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
|
|
103
103
|
return file_import
|
|
104
104
|
|
|
105
105
|
@classmethod
|
|
@@ -30,10 +30,11 @@ __all__ = [
|
|
|
30
30
|
]
|
|
31
31
|
|
|
32
32
|
class JinjaSerializer:
|
|
33
|
-
def __init__(self, autorestapi: AutorestAPI) -> None:
|
|
33
|
+
def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None:
|
|
34
34
|
self._autorestapi = autorestapi
|
|
35
|
+
self.code_model = code_model
|
|
35
36
|
|
|
36
|
-
def serialize(self
|
|
37
|
+
def serialize(self) -> None:
|
|
37
38
|
env = Environment(
|
|
38
39
|
loader=PackageLoader("autorest.codegen", "templates"),
|
|
39
40
|
keep_trailing_newline=True,
|
|
@@ -44,32 +45,34 @@ class JinjaSerializer:
|
|
|
44
45
|
)
|
|
45
46
|
|
|
46
47
|
namespace_path = (
|
|
47
|
-
Path(".")
|
|
48
|
+
Path(".")
|
|
49
|
+
if self.code_model.options["no_namespace_folders"]
|
|
50
|
+
else Path(*(self.code_model.namespace.split(".")))
|
|
48
51
|
)
|
|
49
52
|
|
|
50
53
|
# if there was a patch file before, we keep it
|
|
51
54
|
self._keep_patch_file(namespace_path / Path("_patch.py"), env)
|
|
52
55
|
self._keep_patch_file(namespace_path / Path("aio") / Path("_patch.py"), env)
|
|
53
56
|
|
|
54
|
-
self._serialize_and_write_top_level_folder(
|
|
57
|
+
self._serialize_and_write_top_level_folder(env=env, namespace_path=namespace_path)
|
|
55
58
|
|
|
56
|
-
if code_model.rest.request_builders:
|
|
57
|
-
if code_model.options["builders_visibility"] != "embedded":
|
|
58
|
-
self._serialize_and_write_rest_layer(
|
|
59
|
-
if not code_model.options["no_async"]:
|
|
59
|
+
if self.code_model.rest.request_builders:
|
|
60
|
+
if self.code_model.options["builders_visibility"] != "embedded":
|
|
61
|
+
self._serialize_and_write_rest_layer(env=env, namespace_path=namespace_path)
|
|
62
|
+
if not self.code_model.options["no_async"]:
|
|
60
63
|
self._serialize_and_write_aio_top_level_folder(
|
|
61
|
-
|
|
64
|
+
env=env, namespace_path=namespace_path,
|
|
62
65
|
)
|
|
63
66
|
|
|
64
|
-
if code_model.options["show_operations"] and code_model.operation_groups:
|
|
65
|
-
self._serialize_and_write_operations_folder(
|
|
66
|
-
if code_model.options["multiapi"]:
|
|
67
|
+
if self.code_model.options["show_operations"] and self.code_model.operation_groups:
|
|
68
|
+
self._serialize_and_write_operations_folder(env=env, namespace_path=namespace_path)
|
|
69
|
+
if self.code_model.options["multiapi"]:
|
|
67
70
|
self._serialize_and_write_metadata(
|
|
68
|
-
|
|
71
|
+
env=env, namespace_path=namespace_path
|
|
69
72
|
)
|
|
70
73
|
|
|
71
|
-
if code_model.options["models_mode"] and (code_model.schemas or code_model.enums):
|
|
72
|
-
self._serialize_and_write_models_folder(
|
|
74
|
+
if self.code_model.options["models_mode"] and (self.code_model.schemas or self.code_model.enums):
|
|
75
|
+
self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path)
|
|
73
76
|
|
|
74
77
|
|
|
75
78
|
|
|
@@ -80,49 +83,51 @@ class JinjaSerializer:
|
|
|
80
83
|
self._autorestapi.write_file(path_file, PatchSerializer(env=env).serialize())
|
|
81
84
|
|
|
82
85
|
|
|
83
|
-
def _serialize_and_write_models_folder(self,
|
|
86
|
+
def _serialize_and_write_models_folder(self, env: Environment, namespace_path: Path) -> None:
|
|
84
87
|
# Write the models folder
|
|
85
88
|
models_path = namespace_path / Path("models")
|
|
86
|
-
if code_model.schemas:
|
|
87
|
-
if not code_model.options['python3_only']:
|
|
89
|
+
if self.code_model.schemas:
|
|
90
|
+
if not self.code_model.options['python3_only']:
|
|
88
91
|
self._autorestapi.write_file(
|
|
89
|
-
models_path / Path("_models.py"),
|
|
92
|
+
models_path / Path("_models.py"),
|
|
93
|
+
ModelGenericSerializer(code_model=self.code_model, env=env).serialize()
|
|
90
94
|
)
|
|
91
95
|
self._autorestapi.write_file(
|
|
92
|
-
models_path / Path("_models_py3.py"),
|
|
96
|
+
models_path / Path("_models_py3.py"),
|
|
97
|
+
ModelPython3Serializer(code_model=self.code_model, env=env).serialize()
|
|
93
98
|
)
|
|
94
|
-
if code_model.enums:
|
|
99
|
+
if self.code_model.enums:
|
|
95
100
|
self._autorestapi.write_file(
|
|
96
|
-
models_path / Path(f"_{code_model.module_name}_enums.py"),
|
|
97
|
-
EnumSerializer(code_model=code_model, env=env).serialize(),
|
|
101
|
+
models_path / Path(f"_{self.code_model.module_name}_enums.py"),
|
|
102
|
+
EnumSerializer(code_model=self.code_model, env=env).serialize(),
|
|
98
103
|
)
|
|
99
104
|
self._autorestapi.write_file(
|
|
100
|
-
models_path / Path("__init__.py"), ModelInitSerializer(code_model=code_model, env=env).serialize()
|
|
105
|
+
models_path / Path("__init__.py"), ModelInitSerializer(code_model=self.code_model, env=env).serialize()
|
|
101
106
|
)
|
|
102
107
|
|
|
103
108
|
def _serialize_and_write_rest_layer(
|
|
104
|
-
self,
|
|
109
|
+
self, env: Environment, namespace_path: Path
|
|
105
110
|
) -> None:
|
|
106
|
-
rest_path = namespace_path / Path(code_model.rest_layer_name)
|
|
111
|
+
rest_path = namespace_path / Path(self.code_model.rest_layer_name)
|
|
107
112
|
operation_group_names = {
|
|
108
|
-
rb.operation_group_name for rb in code_model.rest.request_builders
|
|
113
|
+
rb.operation_group_name for rb in self.code_model.rest.request_builders
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
for operation_group_name in operation_group_names:
|
|
112
117
|
request_builders = [
|
|
113
|
-
r for r in code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
118
|
+
r for r in self.code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
114
119
|
]
|
|
115
120
|
self._serialize_and_write_single_rest_layer(
|
|
116
|
-
|
|
121
|
+
env, rest_path, request_builders
|
|
117
122
|
)
|
|
118
123
|
if not "" in operation_group_names:
|
|
119
124
|
self._autorestapi.write_file(
|
|
120
|
-
rest_path / Path("__init__.py"), code_model.options['license_header']
|
|
125
|
+
rest_path / Path("__init__.py"), self.code_model.options['license_header']
|
|
121
126
|
)
|
|
122
127
|
|
|
123
128
|
|
|
124
129
|
def _serialize_and_write_single_rest_layer(
|
|
125
|
-
self,
|
|
130
|
+
self, env: Environment, rest_path: Path, request_builders: List[RequestBuilder]
|
|
126
131
|
) -> None:
|
|
127
132
|
builder_group_name = request_builders[0].builder_group_name
|
|
128
133
|
output_path = rest_path / Path(builder_group_name) if builder_group_name else rest_path
|
|
@@ -130,7 +135,7 @@ class JinjaSerializer:
|
|
|
130
135
|
self._autorestapi.write_file(
|
|
131
136
|
output_path / Path("_request_builders.py"),
|
|
132
137
|
RestGenericSerializer(
|
|
133
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
138
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
134
139
|
).serialize_request_builders()
|
|
135
140
|
)
|
|
136
141
|
|
|
@@ -138,20 +143,19 @@ class JinjaSerializer:
|
|
|
138
143
|
self._autorestapi.write_file(
|
|
139
144
|
output_path / Path("_request_builders_py3.py"),
|
|
140
145
|
RestPython3Serializer(
|
|
141
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
146
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
142
147
|
).serialize_request_builders()
|
|
143
148
|
)
|
|
144
149
|
|
|
145
150
|
# write rest init file
|
|
146
151
|
self._autorestapi.write_file(
|
|
147
152
|
output_path / Path("__init__.py"), RestSerializer(
|
|
148
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
153
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
149
154
|
).serialize_init()
|
|
150
155
|
)
|
|
151
156
|
|
|
152
157
|
def _serialize_and_write_operations_file(
|
|
153
158
|
self,
|
|
154
|
-
code_model: CodeModel,
|
|
155
159
|
env: Environment,
|
|
156
160
|
namespace_path: Path,
|
|
157
161
|
operation_group: Optional[OperationGroup] = None
|
|
@@ -159,35 +163,35 @@ class JinjaSerializer:
|
|
|
159
163
|
filename = operation_group.filename if operation_group else "_operations"
|
|
160
164
|
# write first sync file
|
|
161
165
|
operation_group_serializer = OperationGroupsSerializer(
|
|
162
|
-
code_model=code_model,
|
|
166
|
+
code_model=self.code_model,
|
|
163
167
|
env=env,
|
|
164
168
|
async_mode=False,
|
|
165
|
-
is_python3_file=code_model.options['python3_only'],
|
|
169
|
+
is_python3_file=self.code_model.options['python3_only'],
|
|
166
170
|
operation_group=operation_group
|
|
167
171
|
)
|
|
168
172
|
self._autorestapi.write_file(
|
|
169
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
173
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
170
174
|
operation_group_serializer.serialize(),
|
|
171
175
|
)
|
|
172
176
|
|
|
173
|
-
if not code_model.options['python3_only'] and code_model.options["add_python3_operation_files"]:
|
|
177
|
+
if not self.code_model.options['python3_only'] and self.code_model.options["add_python3_operation_files"]:
|
|
174
178
|
# write typed second file if not python 3 only
|
|
175
179
|
operation_group_serializer = OperationGroupsSerializer(
|
|
176
|
-
code_model=code_model,
|
|
180
|
+
code_model=self.code_model,
|
|
177
181
|
env=env,
|
|
178
182
|
async_mode=False,
|
|
179
183
|
is_python3_file=True,
|
|
180
184
|
|
|
181
185
|
)
|
|
182
186
|
self._autorestapi.write_file(
|
|
183
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
187
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
184
188
|
operation_group_serializer.serialize(),
|
|
185
189
|
)
|
|
186
190
|
|
|
187
|
-
if not code_model.options["no_async"]:
|
|
191
|
+
if not self.code_model.options["no_async"]:
|
|
188
192
|
# write async operation group and operation files
|
|
189
193
|
operation_group_async_serializer = OperationGroupsSerializer(
|
|
190
|
-
code_model=code_model,
|
|
194
|
+
code_model=self.code_model,
|
|
191
195
|
env=env,
|
|
192
196
|
async_mode=True,
|
|
193
197
|
is_python3_file=True,
|
|
@@ -197,47 +201,47 @@ class JinjaSerializer:
|
|
|
197
201
|
(
|
|
198
202
|
namespace_path
|
|
199
203
|
/ Path("aio")
|
|
200
|
-
/ Path(code_model.operations_folder_name)
|
|
204
|
+
/ Path(self.code_model.operations_folder_name)
|
|
201
205
|
/ Path(f"{filename}.py")
|
|
202
206
|
),
|
|
203
207
|
operation_group_async_serializer.serialize(),
|
|
204
208
|
)
|
|
205
209
|
|
|
206
210
|
def _serialize_and_write_operations_folder(
|
|
207
|
-
self,
|
|
211
|
+
self, env: Environment, namespace_path: Path
|
|
208
212
|
) -> None:
|
|
209
213
|
# write sync operations init file
|
|
210
|
-
operations_init_serializer = OperationsInitSerializer(code_model=code_model, env=env, async_mode=False)
|
|
214
|
+
operations_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
211
215
|
self._autorestapi.write_file(
|
|
212
|
-
namespace_path / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
216
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
213
217
|
operations_init_serializer.serialize(),
|
|
214
218
|
)
|
|
215
219
|
|
|
216
220
|
# write async operations init file
|
|
217
|
-
if not code_model.options["no_async"]:
|
|
218
|
-
operations_async_init_serializer = OperationsInitSerializer(
|
|
221
|
+
if not self.code_model.options["no_async"]:
|
|
222
|
+
operations_async_init_serializer = OperationsInitSerializer(
|
|
223
|
+
code_model=self.code_model, env=env, async_mode=True
|
|
224
|
+
)
|
|
219
225
|
self._autorestapi.write_file(
|
|
220
|
-
namespace_path / Path("aio") / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
226
|
+
namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
221
227
|
operations_async_init_serializer.serialize(),
|
|
222
228
|
)
|
|
223
229
|
|
|
224
|
-
if code_model.options["combine_operation_files"]:
|
|
230
|
+
if self.code_model.options["combine_operation_files"]:
|
|
225
231
|
self._serialize_and_write_operations_file(
|
|
226
|
-
code_model=code_model,
|
|
227
232
|
env=env,
|
|
228
233
|
namespace_path=namespace_path,
|
|
229
234
|
)
|
|
230
235
|
else:
|
|
231
|
-
for operation_group in code_model.operation_groups:
|
|
236
|
+
for operation_group in self.code_model.operation_groups:
|
|
232
237
|
self._serialize_and_write_operations_file(
|
|
233
|
-
code_model=code_model,
|
|
234
238
|
env=env,
|
|
235
239
|
namespace_path=namespace_path,
|
|
236
240
|
operation_group=operation_group,
|
|
237
241
|
)
|
|
238
242
|
|
|
239
243
|
def _serialize_and_write_version_file(
|
|
240
|
-
self,
|
|
244
|
+
self, namespace_path: Path, general_serializer: GeneralSerializer
|
|
241
245
|
):
|
|
242
246
|
def _read_version_file(original_version_file_name: str) -> str:
|
|
243
247
|
return self._autorestapi.read_file(namespace_path / original_version_file_name)
|
|
@@ -247,23 +251,23 @@ class JinjaSerializer:
|
|
|
247
251
|
namespace_path / Path("_version.py"),
|
|
248
252
|
_read_version_file(original_version_file_name)
|
|
249
253
|
)
|
|
250
|
-
keep_version_file = code_model.options['keep_version_file']
|
|
254
|
+
keep_version_file = self.code_model.options['keep_version_file']
|
|
251
255
|
if keep_version_file and _read_version_file("_version.py"):
|
|
252
256
|
_write_version_file(original_version_file_name="_version.py")
|
|
253
257
|
elif keep_version_file and _read_version_file("version.py"):
|
|
254
258
|
_write_version_file(original_version_file_name="version.py")
|
|
255
|
-
elif code_model.options['package_version']:
|
|
259
|
+
elif self.code_model.options['package_version']:
|
|
256
260
|
self._autorestapi.write_file(
|
|
257
261
|
namespace_path / Path("_version.py"),
|
|
258
262
|
general_serializer.serialize_version_file()
|
|
259
263
|
)
|
|
260
264
|
|
|
261
265
|
def _serialize_and_write_top_level_folder(
|
|
262
|
-
self,
|
|
266
|
+
self, env: Environment, namespace_path: Path
|
|
263
267
|
) -> None:
|
|
264
|
-
general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=False)
|
|
268
|
+
general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
265
269
|
|
|
266
|
-
if code_model.rest.request_builders:
|
|
270
|
+
if self.code_model.rest.request_builders:
|
|
267
271
|
self._autorestapi.write_file(
|
|
268
272
|
namespace_path / Path("__init__.py"), general_serializer.serialize_init_file()
|
|
269
273
|
)
|
|
@@ -280,37 +284,37 @@ class JinjaSerializer:
|
|
|
280
284
|
p = p.parent
|
|
281
285
|
|
|
282
286
|
# Write the service client
|
|
283
|
-
if code_model.rest.request_builders:
|
|
287
|
+
if self.code_model.rest.request_builders:
|
|
284
288
|
self._autorestapi.write_file(
|
|
285
|
-
namespace_path / Path(f"_{code_model.module_name}.py"),
|
|
289
|
+
namespace_path / Path(f"_{self.code_model.module_name}.py"),
|
|
286
290
|
general_serializer.serialize_service_client_file()
|
|
287
291
|
)
|
|
288
292
|
|
|
289
|
-
if code_model.need_vendored_code:
|
|
293
|
+
if self.code_model.need_vendored_code:
|
|
290
294
|
self._autorestapi.write_file(
|
|
291
295
|
namespace_path / Path("_vendor.py"),
|
|
292
296
|
general_serializer.serialize_vendor_file()
|
|
293
297
|
)
|
|
294
298
|
|
|
295
|
-
self._serialize_and_write_version_file(
|
|
299
|
+
self._serialize_and_write_version_file(namespace_path, general_serializer)
|
|
296
300
|
|
|
297
301
|
# write the empty py.typed file
|
|
298
302
|
self._autorestapi.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.")
|
|
299
303
|
|
|
300
304
|
# Write the config file
|
|
301
|
-
if code_model.rest.request_builders:
|
|
305
|
+
if self.code_model.rest.request_builders:
|
|
302
306
|
self._autorestapi.write_file(
|
|
303
307
|
namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file()
|
|
304
308
|
)
|
|
305
309
|
|
|
306
310
|
# Write the setup file
|
|
307
|
-
if code_model.options["basic_setup_py"]:
|
|
311
|
+
if self.code_model.options["basic_setup_py"]:
|
|
308
312
|
self._autorestapi.write_file(Path("setup.py"), general_serializer.serialize_setup_file())
|
|
309
313
|
|
|
310
314
|
def _serialize_and_write_aio_top_level_folder(
|
|
311
|
-
self,
|
|
315
|
+
self, env: Environment, namespace_path: Path
|
|
312
316
|
) -> None:
|
|
313
|
-
aio_general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=True)
|
|
317
|
+
aio_general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=True)
|
|
314
318
|
|
|
315
319
|
aio_path = namespace_path / Path("aio")
|
|
316
320
|
|
|
@@ -319,7 +323,7 @@ class JinjaSerializer:
|
|
|
319
323
|
|
|
320
324
|
# Write the service client
|
|
321
325
|
self._autorestapi.write_file(
|
|
322
|
-
aio_path / Path(f"_{code_model.module_name}.py"),
|
|
326
|
+
aio_path / Path(f"_{self.code_model.module_name}.py"),
|
|
323
327
|
aio_general_serializer.serialize_service_client_file(),
|
|
324
328
|
)
|
|
325
329
|
|
|
@@ -329,6 +333,6 @@ class JinjaSerializer:
|
|
|
329
333
|
)
|
|
330
334
|
|
|
331
335
|
|
|
332
|
-
def _serialize_and_write_metadata(self,
|
|
333
|
-
metadata_serializer = MetadataSerializer(code_model, env)
|
|
336
|
+
def _serialize_and_write_metadata(self, env: Environment, namespace_path: Path) -> None:
|
|
337
|
+
metadata_serializer = MetadataSerializer(self.code_model, env)
|
|
334
338
|
self._autorestapi.write_file(namespace_path / Path("_metadata.json"), metadata_serializer.serialize())
|