@autorest/python 5.12.5 → 5.14.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 +185 -118
- package/autorest/black/__init__.py +3 -0
- package/autorest/codegen/__init__.py +34 -2
- package/autorest/codegen/models/__init__.py +2 -1
- package/autorest/codegen/models/client.py +6 -5
- package/autorest/codegen/models/code_model.py +3 -0
- package/autorest/codegen/models/constant_schema.py +0 -4
- package/autorest/codegen/models/lro_operation.py +6 -2
- package/autorest/codegen/models/operation.py +20 -11
- package/autorest/codegen/models/operation_group.py +0 -9
- package/autorest/codegen/models/paging_operation.py +3 -3
- package/autorest/codegen/models/parameter.py +35 -9
- package/autorest/codegen/models/parameter_list.py +11 -4
- package/autorest/codegen/models/request_builder.py +3 -2
- package/autorest/codegen/models/request_builder_parameter.py +5 -0
- package/autorest/codegen/models/request_builder_parameter_list.py +1 -0
- package/autorest/codegen/serializers/__init__.py +147 -74
- 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 +4 -1
- package/autorest/codegen/serializers/utils.py +5 -1
- package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
- package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
- package/autorest/codegen/templates/README.md.jinja2 +105 -0
- package/autorest/codegen/templates/config.py.jinja2 +2 -7
- package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
- 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 +6 -2
- package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
- 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 +2 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +2 -7
- package/autorest/codegen/templates/service_client.py.jinja2 +1 -1
- package/autorest/codegen/templates/setup.py.jinja2 +79 -20
- package/autorest/namer/name_converter.py +1 -1
- package/package.json +2 -2
- package/run-python3.js +1 -7
- package/venvtools.py +2 -2
|
@@ -3,9 +3,9 @@
|
|
|
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, Optional
|
|
6
|
+
from typing import Dict, List, Optional, Any
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from jinja2 import PackageLoader, Environment
|
|
8
|
+
from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
|
|
9
9
|
from autorest.codegen.models.operation_group import OperationGroup
|
|
10
10
|
|
|
11
11
|
from ...jsonrpc import AutorestAPI
|
|
@@ -13,6 +13,7 @@ from ..models import (
|
|
|
13
13
|
CodeModel,
|
|
14
14
|
OperationGroup,
|
|
15
15
|
RequestBuilder,
|
|
16
|
+
TokenCredentialSchema
|
|
16
17
|
)
|
|
17
18
|
from .enum_serializer import EnumSerializer
|
|
18
19
|
from .general_serializer import GeneralSerializer
|
|
@@ -29,11 +30,26 @@ __all__ = [
|
|
|
29
30
|
"JinjaSerializer",
|
|
30
31
|
]
|
|
31
32
|
|
|
33
|
+
_PACKAGE_FILES = [
|
|
34
|
+
"CHANGELOG.md.jinja2",
|
|
35
|
+
"dev_requirements.txt.jinja2",
|
|
36
|
+
"LICENSE.jinja2",
|
|
37
|
+
"MANIFEST.in.jinja2",
|
|
38
|
+
"README.md.jinja2",
|
|
39
|
+
"setup.py.jinja2",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
_REGENERATE_FILES = {
|
|
43
|
+
"setup.py",
|
|
44
|
+
"MANIFEST.in"
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
class JinjaSerializer:
|
|
33
|
-
def __init__(self, autorestapi: AutorestAPI) -> None:
|
|
48
|
+
def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None:
|
|
34
49
|
self._autorestapi = autorestapi
|
|
50
|
+
self.code_model = code_model
|
|
35
51
|
|
|
36
|
-
def serialize(self
|
|
52
|
+
def serialize(self) -> None:
|
|
37
53
|
env = Environment(
|
|
38
54
|
loader=PackageLoader("autorest.codegen", "templates"),
|
|
39
55
|
keep_trailing_newline=True,
|
|
@@ -44,33 +60,89 @@ class JinjaSerializer:
|
|
|
44
60
|
)
|
|
45
61
|
|
|
46
62
|
namespace_path = (
|
|
47
|
-
Path(".")
|
|
63
|
+
Path(".")
|
|
64
|
+
if self.code_model.options["no_namespace_folders"]
|
|
65
|
+
else Path(*(self.code_model.namespace.split(".")))
|
|
48
66
|
)
|
|
49
67
|
|
|
50
68
|
# if there was a patch file before, we keep it
|
|
51
69
|
self._keep_patch_file(namespace_path / Path("_patch.py"), env)
|
|
52
70
|
self._keep_patch_file(namespace_path / Path("aio") / Path("_patch.py"), env)
|
|
53
71
|
|
|
54
|
-
self._serialize_and_write_top_level_folder(
|
|
72
|
+
self._serialize_and_write_top_level_folder(env=env, namespace_path=namespace_path)
|
|
55
73
|
|
|
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"]:
|
|
74
|
+
if self.code_model.rest.request_builders:
|
|
75
|
+
if self.code_model.options["builders_visibility"] != "embedded":
|
|
76
|
+
self._serialize_and_write_rest_layer(env=env, namespace_path=namespace_path)
|
|
77
|
+
if not self.code_model.options["no_async"]:
|
|
60
78
|
self._serialize_and_write_aio_top_level_folder(
|
|
61
|
-
|
|
79
|
+
env=env, namespace_path=namespace_path,
|
|
62
80
|
)
|
|
63
81
|
|
|
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"]:
|
|
82
|
+
if self.code_model.options["show_operations"] and self.code_model.operation_groups:
|
|
83
|
+
self._serialize_and_write_operations_folder(env=env, namespace_path=namespace_path)
|
|
84
|
+
if self.code_model.options["multiapi"]:
|
|
67
85
|
self._serialize_and_write_metadata(
|
|
68
|
-
|
|
86
|
+
env=env, namespace_path=namespace_path
|
|
69
87
|
)
|
|
70
88
|
|
|
71
|
-
if code_model.options["models_mode"] and (code_model.schemas or code_model.enums):
|
|
72
|
-
self._serialize_and_write_models_folder(
|
|
73
|
-
|
|
89
|
+
if self.code_model.options["models_mode"] and (self.code_model.schemas or self.code_model.enums):
|
|
90
|
+
self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path)
|
|
91
|
+
|
|
92
|
+
if self.code_model.options["package_mode"]:
|
|
93
|
+
self._serialize_and_write_package_files(out_path=namespace_path)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _serialize_and_write_package_files(self, out_path: Path) -> None:
|
|
97
|
+
def _serialize_and_write_package_files_proc(**kwargs: Any):
|
|
98
|
+
for template_name in package_files:
|
|
99
|
+
file = template_name.replace(".jinja2", "")
|
|
100
|
+
output_name = out_path / file
|
|
101
|
+
if not self._autorestapi.read_file(output_name) or file in _REGENERATE_FILES:
|
|
102
|
+
template = env.get_template(template_name)
|
|
103
|
+
render_result = template.render(**kwargs)
|
|
104
|
+
self._autorestapi.write_file(output_name, render_result)
|
|
105
|
+
|
|
106
|
+
def _prepare_params() -> Dict[Any, Any]:
|
|
107
|
+
package_parts = self.code_model.options["package_name"].split("-")[:-1]
|
|
108
|
+
try:
|
|
109
|
+
token_cred = isinstance(self.code_model.credential_schema_policy.credential, TokenCredentialSchema)
|
|
110
|
+
except ValueError:
|
|
111
|
+
token_cred = False
|
|
112
|
+
version = self.code_model.options["package_version"]
|
|
113
|
+
if any(x in version for x in ["a", "b", "rc"]) or version[0] == '0':
|
|
114
|
+
dev_status = "4 - Beta"
|
|
115
|
+
else:
|
|
116
|
+
dev_status = "5 - Production/Stable"
|
|
117
|
+
params = {
|
|
118
|
+
"token_credential": token_cred,
|
|
119
|
+
"pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))],
|
|
120
|
+
"init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))],
|
|
121
|
+
"dev_status": dev_status
|
|
122
|
+
}
|
|
123
|
+
params.update(self.code_model.options)
|
|
124
|
+
params.update(self.code_model.package_dependency)
|
|
125
|
+
return params
|
|
126
|
+
|
|
127
|
+
count = self.code_model.options["package_name"].count("-") + 1
|
|
128
|
+
for _ in range(count):
|
|
129
|
+
out_path = out_path / Path("..")
|
|
130
|
+
|
|
131
|
+
if self.code_model.options["package_mode"] in ("dataplane", "mgmtplane"):
|
|
132
|
+
env = Environment(
|
|
133
|
+
loader=PackageLoader("autorest.codegen", "templates"),
|
|
134
|
+
undefined=StrictUndefined)
|
|
135
|
+
package_files = _PACKAGE_FILES
|
|
136
|
+
_serialize_and_write_package_files_proc(**_prepare_params())
|
|
137
|
+
elif Path(self.code_model.options["package_mode"]).exists():
|
|
138
|
+
env = Environment(
|
|
139
|
+
loader=FileSystemLoader(str(Path(self.code_model.options["package_mode"]))),
|
|
140
|
+
keep_trailing_newline=True,
|
|
141
|
+
undefined=StrictUndefined
|
|
142
|
+
)
|
|
143
|
+
package_files = env.list_templates()
|
|
144
|
+
params = self.code_model.options["package_configuration"] or {}
|
|
145
|
+
_serialize_and_write_package_files_proc(**params)
|
|
74
146
|
|
|
75
147
|
|
|
76
148
|
def _keep_patch_file(self, path_file: Path, env: Environment):
|
|
@@ -80,49 +152,51 @@ class JinjaSerializer:
|
|
|
80
152
|
self._autorestapi.write_file(path_file, PatchSerializer(env=env).serialize())
|
|
81
153
|
|
|
82
154
|
|
|
83
|
-
def _serialize_and_write_models_folder(self,
|
|
155
|
+
def _serialize_and_write_models_folder(self, env: Environment, namespace_path: Path) -> None:
|
|
84
156
|
# Write the models folder
|
|
85
157
|
models_path = namespace_path / Path("models")
|
|
86
|
-
if code_model.schemas:
|
|
87
|
-
if not code_model.options['python3_only']:
|
|
158
|
+
if self.code_model.schemas:
|
|
159
|
+
if not self.code_model.options['python3_only']:
|
|
88
160
|
self._autorestapi.write_file(
|
|
89
|
-
models_path / Path("_models.py"),
|
|
161
|
+
models_path / Path("_models.py"),
|
|
162
|
+
ModelGenericSerializer(code_model=self.code_model, env=env).serialize()
|
|
90
163
|
)
|
|
91
164
|
self._autorestapi.write_file(
|
|
92
|
-
models_path / Path("_models_py3.py"),
|
|
165
|
+
models_path / Path("_models_py3.py"),
|
|
166
|
+
ModelPython3Serializer(code_model=self.code_model, env=env).serialize()
|
|
93
167
|
)
|
|
94
|
-
if code_model.enums:
|
|
168
|
+
if self.code_model.enums:
|
|
95
169
|
self._autorestapi.write_file(
|
|
96
|
-
models_path / Path(f"_{code_model.module_name}_enums.py"),
|
|
97
|
-
EnumSerializer(code_model=code_model, env=env).serialize(),
|
|
170
|
+
models_path / Path(f"_{self.code_model.module_name}_enums.py"),
|
|
171
|
+
EnumSerializer(code_model=self.code_model, env=env).serialize(),
|
|
98
172
|
)
|
|
99
173
|
self._autorestapi.write_file(
|
|
100
|
-
models_path / Path("__init__.py"), ModelInitSerializer(code_model=code_model, env=env).serialize()
|
|
174
|
+
models_path / Path("__init__.py"), ModelInitSerializer(code_model=self.code_model, env=env).serialize()
|
|
101
175
|
)
|
|
102
176
|
|
|
103
177
|
def _serialize_and_write_rest_layer(
|
|
104
|
-
self,
|
|
178
|
+
self, env: Environment, namespace_path: Path
|
|
105
179
|
) -> None:
|
|
106
|
-
rest_path = namespace_path / Path(code_model.rest_layer_name)
|
|
180
|
+
rest_path = namespace_path / Path(self.code_model.rest_layer_name)
|
|
107
181
|
operation_group_names = {
|
|
108
|
-
rb.operation_group_name for rb in code_model.rest.request_builders
|
|
182
|
+
rb.operation_group_name for rb in self.code_model.rest.request_builders
|
|
109
183
|
}
|
|
110
184
|
|
|
111
185
|
for operation_group_name in operation_group_names:
|
|
112
186
|
request_builders = [
|
|
113
|
-
r for r in code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
187
|
+
r for r in self.code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
114
188
|
]
|
|
115
189
|
self._serialize_and_write_single_rest_layer(
|
|
116
|
-
|
|
190
|
+
env, rest_path, request_builders
|
|
117
191
|
)
|
|
118
192
|
if not "" in operation_group_names:
|
|
119
193
|
self._autorestapi.write_file(
|
|
120
|
-
rest_path / Path("__init__.py"), code_model.options['license_header']
|
|
194
|
+
rest_path / Path("__init__.py"), self.code_model.options['license_header']
|
|
121
195
|
)
|
|
122
196
|
|
|
123
197
|
|
|
124
198
|
def _serialize_and_write_single_rest_layer(
|
|
125
|
-
self,
|
|
199
|
+
self, env: Environment, rest_path: Path, request_builders: List[RequestBuilder]
|
|
126
200
|
) -> None:
|
|
127
201
|
builder_group_name = request_builders[0].builder_group_name
|
|
128
202
|
output_path = rest_path / Path(builder_group_name) if builder_group_name else rest_path
|
|
@@ -130,7 +204,7 @@ class JinjaSerializer:
|
|
|
130
204
|
self._autorestapi.write_file(
|
|
131
205
|
output_path / Path("_request_builders.py"),
|
|
132
206
|
RestGenericSerializer(
|
|
133
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
207
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
134
208
|
).serialize_request_builders()
|
|
135
209
|
)
|
|
136
210
|
|
|
@@ -138,20 +212,19 @@ class JinjaSerializer:
|
|
|
138
212
|
self._autorestapi.write_file(
|
|
139
213
|
output_path / Path("_request_builders_py3.py"),
|
|
140
214
|
RestPython3Serializer(
|
|
141
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
215
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
142
216
|
).serialize_request_builders()
|
|
143
217
|
)
|
|
144
218
|
|
|
145
219
|
# write rest init file
|
|
146
220
|
self._autorestapi.write_file(
|
|
147
221
|
output_path / Path("__init__.py"), RestSerializer(
|
|
148
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
222
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
149
223
|
).serialize_init()
|
|
150
224
|
)
|
|
151
225
|
|
|
152
226
|
def _serialize_and_write_operations_file(
|
|
153
227
|
self,
|
|
154
|
-
code_model: CodeModel,
|
|
155
228
|
env: Environment,
|
|
156
229
|
namespace_path: Path,
|
|
157
230
|
operation_group: Optional[OperationGroup] = None
|
|
@@ -159,35 +232,35 @@ class JinjaSerializer:
|
|
|
159
232
|
filename = operation_group.filename if operation_group else "_operations"
|
|
160
233
|
# write first sync file
|
|
161
234
|
operation_group_serializer = OperationGroupsSerializer(
|
|
162
|
-
code_model=code_model,
|
|
235
|
+
code_model=self.code_model,
|
|
163
236
|
env=env,
|
|
164
237
|
async_mode=False,
|
|
165
|
-
is_python3_file=code_model.options['python3_only'],
|
|
238
|
+
is_python3_file=self.code_model.options['python3_only'],
|
|
166
239
|
operation_group=operation_group
|
|
167
240
|
)
|
|
168
241
|
self._autorestapi.write_file(
|
|
169
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
242
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
170
243
|
operation_group_serializer.serialize(),
|
|
171
244
|
)
|
|
172
245
|
|
|
173
|
-
if not code_model.options['python3_only'] and code_model.options["add_python3_operation_files"]:
|
|
246
|
+
if not self.code_model.options['python3_only'] and self.code_model.options["add_python3_operation_files"]:
|
|
174
247
|
# write typed second file if not python 3 only
|
|
175
248
|
operation_group_serializer = OperationGroupsSerializer(
|
|
176
|
-
code_model=code_model,
|
|
249
|
+
code_model=self.code_model,
|
|
177
250
|
env=env,
|
|
178
251
|
async_mode=False,
|
|
179
252
|
is_python3_file=True,
|
|
180
253
|
|
|
181
254
|
)
|
|
182
255
|
self._autorestapi.write_file(
|
|
183
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
256
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
184
257
|
operation_group_serializer.serialize(),
|
|
185
258
|
)
|
|
186
259
|
|
|
187
|
-
if not code_model.options["no_async"]:
|
|
260
|
+
if not self.code_model.options["no_async"]:
|
|
188
261
|
# write async operation group and operation files
|
|
189
262
|
operation_group_async_serializer = OperationGroupsSerializer(
|
|
190
|
-
code_model=code_model,
|
|
263
|
+
code_model=self.code_model,
|
|
191
264
|
env=env,
|
|
192
265
|
async_mode=True,
|
|
193
266
|
is_python3_file=True,
|
|
@@ -197,47 +270,47 @@ class JinjaSerializer:
|
|
|
197
270
|
(
|
|
198
271
|
namespace_path
|
|
199
272
|
/ Path("aio")
|
|
200
|
-
/ Path(code_model.operations_folder_name)
|
|
273
|
+
/ Path(self.code_model.operations_folder_name)
|
|
201
274
|
/ Path(f"{filename}.py")
|
|
202
275
|
),
|
|
203
276
|
operation_group_async_serializer.serialize(),
|
|
204
277
|
)
|
|
205
278
|
|
|
206
279
|
def _serialize_and_write_operations_folder(
|
|
207
|
-
self,
|
|
280
|
+
self, env: Environment, namespace_path: Path
|
|
208
281
|
) -> None:
|
|
209
282
|
# write sync operations init file
|
|
210
|
-
operations_init_serializer = OperationsInitSerializer(code_model=code_model, env=env, async_mode=False)
|
|
283
|
+
operations_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
211
284
|
self._autorestapi.write_file(
|
|
212
|
-
namespace_path / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
285
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
213
286
|
operations_init_serializer.serialize(),
|
|
214
287
|
)
|
|
215
288
|
|
|
216
289
|
# write async operations init file
|
|
217
|
-
if not code_model.options["no_async"]:
|
|
218
|
-
operations_async_init_serializer = OperationsInitSerializer(
|
|
290
|
+
if not self.code_model.options["no_async"]:
|
|
291
|
+
operations_async_init_serializer = OperationsInitSerializer(
|
|
292
|
+
code_model=self.code_model, env=env, async_mode=True
|
|
293
|
+
)
|
|
219
294
|
self._autorestapi.write_file(
|
|
220
|
-
namespace_path / Path("aio") / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
295
|
+
namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
221
296
|
operations_async_init_serializer.serialize(),
|
|
222
297
|
)
|
|
223
298
|
|
|
224
|
-
if code_model.options["combine_operation_files"]:
|
|
299
|
+
if self.code_model.options["combine_operation_files"]:
|
|
225
300
|
self._serialize_and_write_operations_file(
|
|
226
|
-
code_model=code_model,
|
|
227
301
|
env=env,
|
|
228
302
|
namespace_path=namespace_path,
|
|
229
303
|
)
|
|
230
304
|
else:
|
|
231
|
-
for operation_group in code_model.operation_groups:
|
|
305
|
+
for operation_group in self.code_model.operation_groups:
|
|
232
306
|
self._serialize_and_write_operations_file(
|
|
233
|
-
code_model=code_model,
|
|
234
307
|
env=env,
|
|
235
308
|
namespace_path=namespace_path,
|
|
236
309
|
operation_group=operation_group,
|
|
237
310
|
)
|
|
238
311
|
|
|
239
312
|
def _serialize_and_write_version_file(
|
|
240
|
-
self,
|
|
313
|
+
self, namespace_path: Path, general_serializer: GeneralSerializer
|
|
241
314
|
):
|
|
242
315
|
def _read_version_file(original_version_file_name: str) -> str:
|
|
243
316
|
return self._autorestapi.read_file(namespace_path / original_version_file_name)
|
|
@@ -247,23 +320,23 @@ class JinjaSerializer:
|
|
|
247
320
|
namespace_path / Path("_version.py"),
|
|
248
321
|
_read_version_file(original_version_file_name)
|
|
249
322
|
)
|
|
250
|
-
keep_version_file = code_model.options['keep_version_file']
|
|
323
|
+
keep_version_file = self.code_model.options['keep_version_file']
|
|
251
324
|
if keep_version_file and _read_version_file("_version.py"):
|
|
252
325
|
_write_version_file(original_version_file_name="_version.py")
|
|
253
326
|
elif keep_version_file and _read_version_file("version.py"):
|
|
254
327
|
_write_version_file(original_version_file_name="version.py")
|
|
255
|
-
elif code_model.options['package_version']:
|
|
328
|
+
elif self.code_model.options['package_version']:
|
|
256
329
|
self._autorestapi.write_file(
|
|
257
330
|
namespace_path / Path("_version.py"),
|
|
258
331
|
general_serializer.serialize_version_file()
|
|
259
332
|
)
|
|
260
333
|
|
|
261
334
|
def _serialize_and_write_top_level_folder(
|
|
262
|
-
self,
|
|
335
|
+
self, env: Environment, namespace_path: Path
|
|
263
336
|
) -> None:
|
|
264
|
-
general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=False)
|
|
337
|
+
general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
265
338
|
|
|
266
|
-
if code_model.rest.request_builders:
|
|
339
|
+
if self.code_model.rest.request_builders:
|
|
267
340
|
self._autorestapi.write_file(
|
|
268
341
|
namespace_path / Path("__init__.py"), general_serializer.serialize_init_file()
|
|
269
342
|
)
|
|
@@ -280,37 +353,37 @@ class JinjaSerializer:
|
|
|
280
353
|
p = p.parent
|
|
281
354
|
|
|
282
355
|
# Write the service client
|
|
283
|
-
if code_model.rest.request_builders:
|
|
356
|
+
if self.code_model.rest.request_builders:
|
|
284
357
|
self._autorestapi.write_file(
|
|
285
|
-
namespace_path / Path(f"_{code_model.module_name}.py"),
|
|
358
|
+
namespace_path / Path(f"_{self.code_model.module_name}.py"),
|
|
286
359
|
general_serializer.serialize_service_client_file()
|
|
287
360
|
)
|
|
288
361
|
|
|
289
|
-
if code_model.need_vendored_code:
|
|
362
|
+
if self.code_model.need_vendored_code:
|
|
290
363
|
self._autorestapi.write_file(
|
|
291
364
|
namespace_path / Path("_vendor.py"),
|
|
292
365
|
general_serializer.serialize_vendor_file()
|
|
293
366
|
)
|
|
294
367
|
|
|
295
|
-
self._serialize_and_write_version_file(
|
|
368
|
+
self._serialize_and_write_version_file(namespace_path, general_serializer)
|
|
296
369
|
|
|
297
370
|
# write the empty py.typed file
|
|
298
371
|
self._autorestapi.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.")
|
|
299
372
|
|
|
300
373
|
# Write the config file
|
|
301
|
-
if code_model.rest.request_builders:
|
|
374
|
+
if self.code_model.rest.request_builders:
|
|
302
375
|
self._autorestapi.write_file(
|
|
303
376
|
namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file()
|
|
304
377
|
)
|
|
305
378
|
|
|
306
379
|
# Write the setup file
|
|
307
|
-
if code_model.options["basic_setup_py"]:
|
|
380
|
+
if self.code_model.options["basic_setup_py"]:
|
|
308
381
|
self._autorestapi.write_file(Path("setup.py"), general_serializer.serialize_setup_file())
|
|
309
382
|
|
|
310
383
|
def _serialize_and_write_aio_top_level_folder(
|
|
311
|
-
self,
|
|
384
|
+
self, env: Environment, namespace_path: Path
|
|
312
385
|
) -> None:
|
|
313
|
-
aio_general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=True)
|
|
386
|
+
aio_general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=True)
|
|
314
387
|
|
|
315
388
|
aio_path = namespace_path / Path("aio")
|
|
316
389
|
|
|
@@ -319,7 +392,7 @@ class JinjaSerializer:
|
|
|
319
392
|
|
|
320
393
|
# Write the service client
|
|
321
394
|
self._autorestapi.write_file(
|
|
322
|
-
aio_path / Path(f"_{code_model.module_name}.py"),
|
|
395
|
+
aio_path / Path(f"_{self.code_model.module_name}.py"),
|
|
323
396
|
aio_general_serializer.serialize_service_client_file(),
|
|
324
397
|
)
|
|
325
398
|
|
|
@@ -329,6 +402,6 @@ class JinjaSerializer:
|
|
|
329
402
|
)
|
|
330
403
|
|
|
331
404
|
|
|
332
|
-
def _serialize_and_write_metadata(self,
|
|
333
|
-
metadata_serializer = MetadataSerializer(code_model, env)
|
|
405
|
+
def _serialize_and_write_metadata(self, env: Environment, namespace_path: Path) -> None:
|
|
406
|
+
metadata_serializer = MetadataSerializer(self.code_model, env)
|
|
334
407
|
self._autorestapi.write_file(namespace_path / Path("_metadata.json"), metadata_serializer.serialize())
|