@typespec/http-client-python 0.27.0 → 0.27.2
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/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +20 -15
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/http.js +11 -1
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +30 -11
- package/dist/emitter/types.js.map +1 -1
- package/emitter/src/code-model.ts +28 -21
- package/emitter/src/http.ts +10 -1
- package/emitter/src/types.ts +32 -11
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/regenerate-common.ts +472 -0
- package/eng/scripts/ci/regenerate.ts +41 -427
- package/eng/scripts/setup/__pycache__/package_manager.cpython-311.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-311.pyc +0 -0
- package/generator/build/lib/pygen/codegen/models/client.py +5 -5
- package/generator/build/lib/pygen/codegen/models/credential_types.py +1 -1
- package/generator/build/lib/pygen/codegen/models/enum_type.py +1 -1
- package/generator/build/lib/pygen/codegen/models/imports.py +2 -3
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/build/lib/pygen/codegen/models/model_type.py +2 -2
- package/generator/build/lib/pygen/codegen/models/operation.py +10 -6
- package/generator/build/lib/pygen/codegen/models/operation_group.py +1 -1
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +7 -3
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +1 -1
- package/generator/build/lib/pygen/codegen/models/request_builder.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +16 -7
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +4 -31
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +8 -2
- package/generator/component-detection-pip-report.json +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/client.py +5 -5
- package/generator/pygen/codegen/models/credential_types.py +1 -1
- package/generator/pygen/codegen/models/enum_type.py +1 -1
- package/generator/pygen/codegen/models/imports.py +2 -3
- package/generator/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/pygen/codegen/models/model_type.py +2 -2
- package/generator/pygen/codegen/models/operation.py +10 -6
- package/generator/pygen/codegen/models/operation_group.py +1 -1
- package/generator/pygen/codegen/models/paging_operation.py +7 -3
- package/generator/pygen/codegen/models/primitive_types.py +1 -1
- package/generator/pygen/codegen/models/request_builder.py +1 -1
- package/generator/pygen/codegen/serializers/builder_serializer.py +16 -7
- package/generator/pygen/codegen/serializers/import_serializer.py +4 -31
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +8 -2
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +12 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +2 -3
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_page_async.py +12 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_older_versions_async.py +111 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_shared_models_async.py +132 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +30 -0
- package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +9 -0
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +2 -3
- package/generator/test/azure/mock_api_tests/test_azure_core_page.py +11 -0
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_older_versions.py +107 -0
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_shared_models.py +128 -0
- package/generator/test/azure/mock_api_tests/test_clear_output_folder.py +9 -0
- package/generator/test/azure/mock_api_tests/test_payload_multipart.py +27 -0
- package/generator/test/azure/requirements.txt +10 -2
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +6 -1
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py +10 -5
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py +30 -0
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_file_async.py +59 -0
- package/generator/test/generic_mock_api_tests/data/image.jpg +0 -0
- package/generator/test/generic_mock_api_tests/data/image.png +0 -0
- package/generator/test/generic_mock_api_tests/test_encode_bytes.py +6 -0
- package/generator/test/generic_mock_api_tests/test_payload_pageable.py +8 -4
- package/generator/test/generic_mock_api_tests/test_payload_xml.py +27 -0
- package/generator/test/generic_mock_api_tests/test_typetest_file.py +52 -0
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +31 -0
- package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +28 -0
- package/generator/test/unbranded/mock_api_tests/test_unbranded.py +9 -8
- package/generator/test/unbranded/requirements.txt +3 -1
- package/generator/test/unittests/test_model_base_serialization.py +161 -0
- package/package.json +38 -38
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { execFile } from "child_process";
|
|
4
4
|
import { promises, rmSync } from "fs";
|
|
5
|
-
import {
|
|
5
|
+
import { join, resolve } from "path";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { parseArgs, promisify } from "util";
|
|
8
|
+
import {
|
|
9
|
+
BASE_AZURE_EMITTER_OPTIONS,
|
|
10
|
+
BASE_EMITTER_OPTIONS,
|
|
11
|
+
buildOptions,
|
|
12
|
+
regenerate,
|
|
13
|
+
toPosix,
|
|
14
|
+
type RegenerateConfig,
|
|
15
|
+
type RegenerateFlags,
|
|
16
|
+
type RegenerateFlagsInput,
|
|
17
|
+
type TspCommand,
|
|
18
|
+
} from "./regenerate-common.js";
|
|
8
19
|
|
|
9
20
|
// PARSE INPUT ARGUMENTS
|
|
10
21
|
|
|
@@ -21,9 +32,6 @@ const argv = parseArgs({
|
|
|
21
32
|
},
|
|
22
33
|
});
|
|
23
34
|
|
|
24
|
-
// Add this near the top with other constants
|
|
25
|
-
const SKIP_SPECS: string[] = [];
|
|
26
|
-
|
|
27
35
|
// Get the directory of the current file
|
|
28
36
|
const PLUGIN_DIR = argv.values.pluginDir
|
|
29
37
|
? resolve(argv.values.pluginDir)
|
|
@@ -33,280 +41,38 @@ const HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@typespec/http-specs/specs"
|
|
|
33
41
|
const GENERATED_FOLDER = argv.values.generatedFolder
|
|
34
42
|
? resolve(argv.values.generatedFolder)
|
|
35
43
|
: resolve(PLUGIN_DIR, "generator");
|
|
36
|
-
|
|
37
|
-
interface TspCommand {
|
|
38
|
-
outputDir: string;
|
|
39
|
-
command: string[];
|
|
40
|
-
}
|
|
44
|
+
const EMITTER_NAME = argv.values.emitterName || "@typespec/http-client-python";
|
|
41
45
|
|
|
42
46
|
const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
43
|
-
|
|
44
|
-
namespace: "specs.azure.clientgenerator.core.access",
|
|
45
|
-
},
|
|
46
|
-
"azure/client-generator-core/alternate-type": {
|
|
47
|
-
namespace: "specs.azure.clientgenerator.core.alternatetype",
|
|
48
|
-
},
|
|
49
|
-
"azure/client-generator-core/api-version": {
|
|
50
|
-
namespace: "specs.azure.clientgenerator.core.apiversion",
|
|
51
|
-
},
|
|
52
|
-
"azure/client-generator-core/client-initialization": {
|
|
53
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization",
|
|
54
|
-
},
|
|
55
|
-
"azure/client-generator-core/client-location": {
|
|
56
|
-
namespace: "specs.azure.clientgenerator.core.clientlocation",
|
|
57
|
-
},
|
|
58
|
-
"azure/client-generator-core/deserialize-empty-string-as-null": {
|
|
59
|
-
namespace: "specs.azure.clientgenerator.core.emptystring",
|
|
60
|
-
},
|
|
61
|
-
"azure/client-generator-core/flatten-property": {
|
|
62
|
-
namespace: "specs.azure.clientgenerator.core.flattenproperty",
|
|
63
|
-
},
|
|
64
|
-
"azure/client-generator-core/usage": {
|
|
65
|
-
namespace: "specs.azure.clientgenerator.core.usage",
|
|
66
|
-
},
|
|
67
|
-
"azure/client-generator-core/override": {
|
|
68
|
-
namespace: "specs.azure.clientgenerator.core.override",
|
|
69
|
-
},
|
|
70
|
-
"azure/client-generator-core/hierarchy-building": {
|
|
71
|
-
namespace: "specs.azure.clientgenerator.core.hierarchybuilding",
|
|
72
|
-
},
|
|
73
|
-
"azure/core/basic": {
|
|
74
|
-
namespace: "specs.azure.core.basic",
|
|
75
|
-
},
|
|
76
|
-
"azure/core/lro/rpc": {
|
|
77
|
-
namespace: "specs.azure.core.lro.rpc",
|
|
78
|
-
},
|
|
79
|
-
"azure/core/lro/standard": {
|
|
80
|
-
namespace: "specs.azure.core.lro.standard",
|
|
81
|
-
},
|
|
82
|
-
"azure/core/model": {
|
|
83
|
-
namespace: "specs.azure.core.model",
|
|
84
|
-
},
|
|
85
|
-
"azure/core/page": {
|
|
86
|
-
namespace: "specs.azure.core.page",
|
|
87
|
-
},
|
|
88
|
-
"azure/core/scalar": {
|
|
89
|
-
namespace: "specs.azure.core.scalar",
|
|
90
|
-
},
|
|
91
|
-
"azure/core/traits": {
|
|
92
|
-
namespace: "specs.azure.core.traits",
|
|
93
|
-
},
|
|
94
|
-
"azure/encode/duration": {
|
|
95
|
-
namespace: "specs.azure.encode.duration",
|
|
96
|
-
},
|
|
97
|
-
"azure/example/basic": {
|
|
98
|
-
namespace: "specs.azure.example.basic",
|
|
99
|
-
},
|
|
100
|
-
"azure/payload/pageable": {
|
|
101
|
-
namespace: "specs.azure.payload.pageable",
|
|
102
|
-
},
|
|
103
|
-
"azure/versioning/previewVersion": {
|
|
104
|
-
namespace: "specs.azure.versioning.previewversion",
|
|
105
|
-
},
|
|
106
|
-
"client/structure/default": {
|
|
107
|
-
namespace: "client.structure.service",
|
|
108
|
-
},
|
|
47
|
+
...BASE_AZURE_EMITTER_OPTIONS,
|
|
109
48
|
"client/structure/client-operation-group": {
|
|
110
49
|
"package-name": "client-structure-clientoperationgroup",
|
|
111
50
|
namespace: "client.structure.clientoperationgroup",
|
|
112
51
|
},
|
|
113
|
-
"client/structure/multi-client": {
|
|
114
|
-
"package-name": "client-structure-multiclient",
|
|
115
|
-
namespace: "client.structure.multiclient",
|
|
116
|
-
},
|
|
117
|
-
"client/structure/renamed-operation": {
|
|
118
|
-
"package-name": "client-structure-renamedoperation",
|
|
119
|
-
namespace: "client.structure.renamedoperation",
|
|
120
|
-
},
|
|
121
|
-
"client/structure/two-operation-group": {
|
|
122
|
-
"package-name": "client-structure-twooperationgroup",
|
|
123
|
-
namespace: "client.structure.twooperationgroup",
|
|
124
|
-
},
|
|
125
|
-
"client/naming": {
|
|
126
|
-
namespace: "client.naming.main",
|
|
127
|
-
},
|
|
128
|
-
"client/overload": {
|
|
129
|
-
namespace: "client.overload",
|
|
130
|
-
},
|
|
131
|
-
"encode/duration": {
|
|
132
|
-
namespace: "encode.duration",
|
|
133
|
-
},
|
|
134
|
-
"encode/numeric": {
|
|
135
|
-
namespace: "encode.numeric",
|
|
136
|
-
},
|
|
137
|
-
"parameters/basic": {
|
|
138
|
-
namespace: "parameters.basic",
|
|
139
|
-
},
|
|
140
|
-
"parameters/spread": {
|
|
141
|
-
namespace: "parameters.spread",
|
|
142
|
-
},
|
|
143
|
-
"payload/content-negotiation": {
|
|
144
|
-
namespace: "payload.contentnegotiation",
|
|
145
|
-
},
|
|
146
|
-
"payload/multipart": {
|
|
147
|
-
namespace: "payload.multipart",
|
|
148
|
-
},
|
|
149
|
-
"serialization/encoded-name/json": {
|
|
150
|
-
namespace: "serialization.encodedname.json",
|
|
151
|
-
},
|
|
152
|
-
"special-words": {
|
|
153
|
-
namespace: "specialwords",
|
|
154
|
-
},
|
|
155
|
-
"service/multi-service": {
|
|
156
|
-
namespace: "service.multiservice",
|
|
157
|
-
},
|
|
158
52
|
};
|
|
159
53
|
|
|
160
54
|
const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
161
|
-
|
|
162
|
-
"package-name": "resiliency-srv-driven1",
|
|
163
|
-
namespace: "resiliency.srv.driven1",
|
|
164
|
-
"package-mode": "azure-dataplane",
|
|
165
|
-
"package-pprint-name": "ResiliencySrvDriven1",
|
|
166
|
-
},
|
|
167
|
-
"resiliency/srv-driven": {
|
|
168
|
-
"package-name": "resiliency-srv-driven2",
|
|
169
|
-
namespace: "resiliency.srv.driven2",
|
|
170
|
-
"package-mode": "azure-dataplane",
|
|
171
|
-
"package-pprint-name": "ResiliencySrvDriven2",
|
|
172
|
-
},
|
|
173
|
-
"authentication/api-key": {
|
|
174
|
-
"clear-output-folder": "true",
|
|
175
|
-
},
|
|
176
|
-
"authentication/http/custom": {
|
|
177
|
-
"package-name": "authentication-http-custom",
|
|
178
|
-
namespace: "authentication.http.custom",
|
|
179
|
-
"package-pprint-name": "Authentication Http Custom",
|
|
180
|
-
},
|
|
181
|
-
"authentication/union": [
|
|
182
|
-
{
|
|
183
|
-
"package-name": "authentication-union",
|
|
184
|
-
namespace: "authentication.union",
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
"package-name": "setuppy-authentication-union",
|
|
188
|
-
namespace: "setuppy.authentication.union",
|
|
189
|
-
"keep-setup-py": "true",
|
|
190
|
-
},
|
|
191
|
-
],
|
|
55
|
+
...BASE_EMITTER_OPTIONS,
|
|
192
56
|
"type/array": {
|
|
193
57
|
"package-name": "typetest-array",
|
|
194
58
|
namespace: "typetest.array",
|
|
195
59
|
"use-pyodide": "true",
|
|
196
60
|
},
|
|
197
|
-
"type/dictionary": {
|
|
198
|
-
"package-name": "typetest-dictionary",
|
|
199
|
-
namespace: "typetest.dictionary",
|
|
200
|
-
},
|
|
201
|
-
"type/enum/extensible": {
|
|
202
|
-
"package-name": "typetest-enum-extensible",
|
|
203
|
-
namespace: "typetest.enum.extensible",
|
|
204
|
-
},
|
|
205
|
-
"type/enum/fixed": {
|
|
206
|
-
"package-name": "typetest-enum-fixed",
|
|
207
|
-
namespace: "typetest.enum.fixed",
|
|
208
|
-
},
|
|
209
|
-
"type/model/empty": {
|
|
210
|
-
"package-name": "typetest-model-empty",
|
|
211
|
-
namespace: "typetest.model.empty",
|
|
212
|
-
},
|
|
213
|
-
"type/model/inheritance/enum-discriminator": {
|
|
214
|
-
"package-name": "typetest-model-enumdiscriminator",
|
|
215
|
-
namespace: "typetest.model.enumdiscriminator",
|
|
216
|
-
},
|
|
217
|
-
"type/model/inheritance/nested-discriminator": {
|
|
218
|
-
"package-name": "typetest-model-nesteddiscriminator",
|
|
219
|
-
namespace: "typetest.model.nesteddiscriminator",
|
|
220
|
-
},
|
|
221
|
-
"type/model/inheritance/not-discriminated": {
|
|
222
|
-
"package-name": "typetest-model-notdiscriminated",
|
|
223
|
-
namespace: "typetest.model.notdiscriminated",
|
|
224
|
-
},
|
|
225
|
-
"type/model/inheritance/single-discriminator": {
|
|
226
|
-
"package-name": "typetest-model-singlediscriminator",
|
|
227
|
-
namespace: "typetest.model.singlediscriminator",
|
|
228
|
-
},
|
|
229
61
|
"type/model/inheritance/recursive": {
|
|
230
62
|
"package-name": "typetest-model-recursive",
|
|
231
63
|
namespace: "typetest.model.recursive",
|
|
232
64
|
"use-pyodide": "true",
|
|
233
65
|
},
|
|
234
|
-
"type/model/usage": {
|
|
235
|
-
"package-name": "typetest-model-usage",
|
|
236
|
-
namespace: "typetest.model.usage",
|
|
237
|
-
},
|
|
238
|
-
"type/model/visibility": [
|
|
239
|
-
{
|
|
240
|
-
"package-name": "typetest-model-visibility",
|
|
241
|
-
namespace: "typetest.model.visibility",
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
"package-name": "headasbooleantrue",
|
|
245
|
-
namespace: "headasbooleantrue",
|
|
246
|
-
"head-as-boolean": "true",
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
"package-name": "headasbooleanfalse",
|
|
250
|
-
namespace: "headasbooleanfalse",
|
|
251
|
-
"head-as-boolean": "false",
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
"type/property/nullable": {
|
|
255
|
-
"package-name": "typetest-property-nullable",
|
|
256
|
-
namespace: "typetest.property.nullable",
|
|
257
|
-
},
|
|
258
|
-
"type/property/optionality": {
|
|
259
|
-
"package-name": "typetest-property-optional",
|
|
260
|
-
namespace: "typetest.property.optional",
|
|
261
|
-
},
|
|
262
|
-
"type/property/additional-properties": {
|
|
263
|
-
"package-name": "typetest-property-additionalproperties",
|
|
264
|
-
namespace: "typetest.property.additionalproperties",
|
|
265
|
-
},
|
|
266
|
-
"type/scalar": {
|
|
267
|
-
"package-name": "typetest-scalar",
|
|
268
|
-
namespace: "typetest.scalar",
|
|
269
|
-
},
|
|
270
|
-
"type/property/value-types": {
|
|
271
|
-
"package-name": "typetest-property-valuetypes",
|
|
272
|
-
namespace: "typetest.property.valuetypes",
|
|
273
|
-
},
|
|
274
|
-
"type/union": {
|
|
275
|
-
"package-name": "typetest-union",
|
|
276
|
-
namespace: "typetest.union",
|
|
277
|
-
},
|
|
278
|
-
"type/union/discriminated": {
|
|
279
|
-
"package-name": "typetest-discriminatedunion",
|
|
280
|
-
namespace: "typetest.discriminatedunion",
|
|
281
|
-
},
|
|
282
|
-
documentation: {
|
|
283
|
-
"package-name": "specs-documentation",
|
|
284
|
-
namespace: "specs.documentation",
|
|
285
|
-
},
|
|
286
66
|
};
|
|
287
67
|
|
|
288
|
-
function toPosix(dir: string): string {
|
|
289
|
-
return dir.replace(/\\/g, "/");
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function getEmitterOption(spec: string, flavor: string): Record<string, string>[] {
|
|
293
|
-
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
|
|
294
|
-
const relativeSpec = toPosix(relative(specDir, spec));
|
|
295
|
-
const key = relativeSpec.includes("resiliency/srv-driven/old.tsp")
|
|
296
|
-
? relativeSpec
|
|
297
|
-
: dirname(relativeSpec);
|
|
298
|
-
const emitter_options = EMITTER_OPTIONS[key] ||
|
|
299
|
-
(flavor === "azure" ? AZURE_EMITTER_OPTIONS[key] : [{}]) || [{}];
|
|
300
|
-
return Array.isArray(emitter_options) ? emitter_options : [emitter_options];
|
|
301
|
-
}
|
|
302
|
-
|
|
303
68
|
// Function to execute CLI commands asynchronously
|
|
304
69
|
async function executeCommand(tspCommand: TspCommand): Promise<void> {
|
|
70
|
+
const cmd = tspCommand.command as string[];
|
|
305
71
|
const execFileAsync = promisify(execFile);
|
|
306
72
|
try {
|
|
307
|
-
console.log(chalk.green(`start tsp ${
|
|
308
|
-
await execFileAsync("tsp",
|
|
309
|
-
console.log(chalk.green(`tsp ${
|
|
73
|
+
console.log(chalk.green(`start tsp ${cmd.join(" ")}`));
|
|
74
|
+
await execFileAsync("tsp", cmd, { shell: true });
|
|
75
|
+
console.log(chalk.green(`tsp ${cmd.join(" ")} succeeded`));
|
|
310
76
|
} catch (err) {
|
|
311
77
|
rmSync(tspCommand.outputDir, { recursive: true, force: true });
|
|
312
78
|
console.error(chalk.red(`exec error: ${err}`));
|
|
@@ -314,153 +80,6 @@ async function executeCommand(tspCommand: TspCommand): Promise<void> {
|
|
|
314
80
|
}
|
|
315
81
|
}
|
|
316
82
|
|
|
317
|
-
interface RegenerateFlagsInput {
|
|
318
|
-
flavor?: string;
|
|
319
|
-
debug?: boolean;
|
|
320
|
-
name?: string;
|
|
321
|
-
pyodide?: boolean;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
interface RegenerateFlags {
|
|
325
|
-
flavor: string;
|
|
326
|
-
debug: boolean;
|
|
327
|
-
name?: string;
|
|
328
|
-
pyodide?: boolean;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const SpecialFlags: Record<string, Record<string, any>> = {
|
|
332
|
-
azure: {
|
|
333
|
-
"generate-test": true,
|
|
334
|
-
"generate-sample": true,
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promise<string[]> {
|
|
339
|
-
const subdirectories: string[] = [];
|
|
340
|
-
|
|
341
|
-
async function searchDir(currentDir: string) {
|
|
342
|
-
const items = await promises.readdir(currentDir, { withFileTypes: true });
|
|
343
|
-
|
|
344
|
-
const promisesArray = items.map(async (item) => {
|
|
345
|
-
const subDirPath = join(currentDir, item.name);
|
|
346
|
-
if (item.isDirectory()) {
|
|
347
|
-
const mainTspPath = join(subDirPath, "main.tsp");
|
|
348
|
-
const clientTspPath = join(subDirPath, "client.tsp");
|
|
349
|
-
|
|
350
|
-
const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath));
|
|
351
|
-
|
|
352
|
-
// Replace the individual skip checks with:
|
|
353
|
-
if (SKIP_SPECS.some((skipSpec) => mainTspRelativePath.includes(skipSpec))) return;
|
|
354
|
-
|
|
355
|
-
const hasMainTsp = await promises
|
|
356
|
-
.access(mainTspPath)
|
|
357
|
-
.then(() => true)
|
|
358
|
-
.catch(() => false);
|
|
359
|
-
const hasClientTsp = await promises
|
|
360
|
-
.access(clientTspPath)
|
|
361
|
-
.then(() => true)
|
|
362
|
-
.catch(() => false);
|
|
363
|
-
|
|
364
|
-
if (mainTspRelativePath.toLowerCase().includes(flags.name || "")) {
|
|
365
|
-
if (mainTspRelativePath.includes("resiliency/srv-driven")) {
|
|
366
|
-
subdirectories.push(resolve(subDirPath, "old.tsp"));
|
|
367
|
-
}
|
|
368
|
-
if (hasClientTsp) {
|
|
369
|
-
subdirectories.push(resolve(subDirPath, "client.tsp"));
|
|
370
|
-
} else if (hasMainTsp) {
|
|
371
|
-
subdirectories.push(resolve(subDirPath, "main.tsp"));
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Recursively search in the subdirectory
|
|
376
|
-
await searchDir(subDirPath);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
await Promise.all(promisesArray);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
await searchDir(baseDir);
|
|
384
|
-
return subdirectories;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function defaultPackageName(spec: string): string {
|
|
388
|
-
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
|
|
389
|
-
return toPosix(relative(specDir, dirname(spec)))
|
|
390
|
-
.replace(/\//g, "-")
|
|
391
|
-
.toLowerCase();
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
interface EmitterConfig {
|
|
395
|
-
options: string[];
|
|
396
|
-
outputDir: string;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function addOptions(
|
|
400
|
-
spec: string,
|
|
401
|
-
generatedFolder: string,
|
|
402
|
-
flags: RegenerateFlags,
|
|
403
|
-
): EmitterConfig[] {
|
|
404
|
-
const emitterConfigs: EmitterConfig[] = [];
|
|
405
|
-
for (const config of getEmitterOption(spec, flags.flavor)) {
|
|
406
|
-
const options: Record<string, string> = { ...config };
|
|
407
|
-
if (flags.pyodide) {
|
|
408
|
-
options["use-pyodide"] = "true";
|
|
409
|
-
}
|
|
410
|
-
options["flavor"] = flags.flavor;
|
|
411
|
-
for (const [k, v] of Object.entries(SpecialFlags[flags.flavor] ?? {})) {
|
|
412
|
-
options[k] = v;
|
|
413
|
-
}
|
|
414
|
-
if (options["emitter-output-dir"] === undefined) {
|
|
415
|
-
const packageName = options["package-name"] || defaultPackageName(spec);
|
|
416
|
-
options["emitter-output-dir"] = toPosix(
|
|
417
|
-
`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`,
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
if (flags.debug) {
|
|
421
|
-
options["debug"] = "true";
|
|
422
|
-
}
|
|
423
|
-
options["examples-dir"] = toPosix(join(dirname(spec), "examples"));
|
|
424
|
-
const configs = Object.entries(options).flatMap(([k, v]) => {
|
|
425
|
-
return [
|
|
426
|
-
"--option",
|
|
427
|
-
`${argv.values.emitterName || "@typespec/http-client-python"}.${k}="${v}"`,
|
|
428
|
-
];
|
|
429
|
-
});
|
|
430
|
-
emitterConfigs.push({
|
|
431
|
-
options: configs,
|
|
432
|
-
outputDir: options["emitter-output-dir"],
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
return emitterConfigs;
|
|
436
|
-
}
|
|
437
|
-
function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
|
|
438
|
-
return addOptions(spec, GENERATED_FOLDER, flags).map((option) => {
|
|
439
|
-
return {
|
|
440
|
-
outputDir: option.outputDir,
|
|
441
|
-
command: ["compile", spec, "--emit", toPosix(PLUGIN_DIR), ...option.options],
|
|
442
|
-
};
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
|
|
447
|
-
async function worker(start: number, end: number) {
|
|
448
|
-
while (start < end) {
|
|
449
|
-
await tasks[start]();
|
|
450
|
-
start++;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const workers = [];
|
|
455
|
-
let start = 0;
|
|
456
|
-
while (start < tasks.length) {
|
|
457
|
-
const end = Math.min(start + poolLimit, tasks.length);
|
|
458
|
-
workers.push((async () => await worker(start, end))());
|
|
459
|
-
start = end;
|
|
460
|
-
}
|
|
461
|
-
await Promise.all(workers);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
83
|
// create some files before regeneration. After regeneration, these files should be deleted and we will test it
|
|
465
84
|
// in test case
|
|
466
85
|
async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
|
|
@@ -483,36 +102,31 @@ async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
|
|
|
483
102
|
}
|
|
484
103
|
}
|
|
485
104
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
flags.flavor === "azure"
|
|
498
|
-
? [...subdirectoriesForAzure, ...subdirectoriesForNonAzure]
|
|
499
|
-
: subdirectoriesForNonAzure;
|
|
500
|
-
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
|
|
501
|
-
_getCmdList(subdirectory, flagsResolved),
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
// Create tasks as functions for the pool
|
|
505
|
-
const tasks: Array<() => Promise<void>> = cmdList.map((tspCommand) => {
|
|
506
|
-
return () => executeCommand(tspCommand);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
// Run tasks with a concurrency limit
|
|
510
|
-
await runTaskPool(tasks, 30);
|
|
511
|
-
}
|
|
105
|
+
function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
|
|
106
|
+
return buildOptions(spec, GENERATED_FOLDER, flags, config).map((po) => {
|
|
107
|
+
const optionArgs = Object.entries(po.options).flatMap(([k, v]) => [
|
|
108
|
+
"--option",
|
|
109
|
+
`${EMITTER_NAME}.${k}="${v}"`,
|
|
110
|
+
]);
|
|
111
|
+
return {
|
|
112
|
+
outputDir: po.outputDir,
|
|
113
|
+
command: ["compile", spec, "--emit", toPosix(PLUGIN_DIR), ...optionArgs],
|
|
114
|
+
};
|
|
115
|
+
});
|
|
512
116
|
}
|
|
513
117
|
|
|
118
|
+
const config: RegenerateConfig = {
|
|
119
|
+
azureHttpSpecs: AZURE_HTTP_SPECS,
|
|
120
|
+
httpSpecs: HTTP_SPECS,
|
|
121
|
+
emitterOptions: EMITTER_OPTIONS,
|
|
122
|
+
azureEmitterOptions: AZURE_EMITTER_OPTIONS,
|
|
123
|
+
preprocess,
|
|
124
|
+
getCmdList: _getCmdList,
|
|
125
|
+
executeCommand,
|
|
126
|
+
};
|
|
127
|
+
|
|
514
128
|
const start = performance.now();
|
|
515
|
-
regenerate(argv.values)
|
|
129
|
+
regenerate(argv.values, config)
|
|
516
130
|
.then(() =>
|
|
517
131
|
console.log(
|
|
518
132
|
chalk.green(
|
|
Binary file
|
|
Binary file
|
|
@@ -247,7 +247,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
247
247
|
|
|
248
248
|
def imports(self, async_mode: bool, **kwargs) -> FileImport:
|
|
249
249
|
file_import = FileImport(self.code_model)
|
|
250
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.
|
|
250
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
|
|
251
251
|
if self.code_model.options["azure-arm"]:
|
|
252
252
|
file_import.add_submodule_import("azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE)
|
|
253
253
|
else:
|
|
@@ -307,20 +307,20 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
307
307
|
"rest",
|
|
308
308
|
"AsyncHttpResponse",
|
|
309
309
|
ImportType.SDKCORE,
|
|
310
|
-
TypingSection.
|
|
310
|
+
TypingSection.REGULAR,
|
|
311
311
|
)
|
|
312
312
|
else:
|
|
313
313
|
file_import.add_submodule_import(
|
|
314
314
|
"rest",
|
|
315
315
|
"HttpResponse",
|
|
316
316
|
ImportType.SDKCORE,
|
|
317
|
-
TypingSection.
|
|
317
|
+
TypingSection.REGULAR,
|
|
318
318
|
)
|
|
319
319
|
file_import.add_submodule_import(
|
|
320
320
|
"rest",
|
|
321
321
|
"HttpRequest",
|
|
322
322
|
ImportType.SDKCORE,
|
|
323
|
-
TypingSection.
|
|
323
|
+
TypingSection.REGULAR,
|
|
324
324
|
)
|
|
325
325
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
326
326
|
for og in self.operation_groups:
|
|
@@ -401,7 +401,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
401
401
|
"policies",
|
|
402
402
|
ImportType.SDKCORE,
|
|
403
403
|
)
|
|
404
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.
|
|
404
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
|
|
405
405
|
if self.code_model.options.get("package-version"):
|
|
406
406
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
407
407
|
file_import.add_submodule_import(
|
|
@@ -213,6 +213,6 @@ class KeyCredentialType(CredentialType[KeyCredentialPolicyType]):
|
|
|
213
213
|
"credentials",
|
|
214
214
|
self.policy.credential_name,
|
|
215
215
|
ImportType.SDKCORE,
|
|
216
|
-
typing_section=TypingSection.
|
|
216
|
+
typing_section=TypingSection.REGULAR,
|
|
217
217
|
)
|
|
218
218
|
return file_import
|
|
@@ -241,7 +241,7 @@ class EnumType(BaseType):
|
|
|
241
241
|
file_import = FileImport(self.code_model)
|
|
242
242
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
243
243
|
if self.code_model.options["models-mode"]:
|
|
244
|
-
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.
|
|
244
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
|
|
245
245
|
|
|
246
246
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
247
247
|
relative_path = self.code_model.get_relative_import_path(serialize_namespace, self.client_namespace)
|
|
@@ -23,9 +23,8 @@ class ImportType(str, Enum):
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class TypingSection(str, Enum):
|
|
26
|
-
REGULAR = "regular" # this import is always a
|
|
27
|
-
|
|
28
|
-
TYPING = "typing" # never a typing import
|
|
26
|
+
REGULAR = "regular" # this import is always a regular import
|
|
27
|
+
TYPING = "typing" # this import goes under TYPE_CHECKING
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
class MsrestImportType(Enum):
|
|
@@ -138,7 +138,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
138
138
|
"_deserialize",
|
|
139
139
|
ImportType.LOCAL,
|
|
140
140
|
)
|
|
141
|
-
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.
|
|
141
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
|
|
142
142
|
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
143
143
|
return file_import
|
|
144
144
|
|
|
@@ -270,7 +270,7 @@ class JSONModelType(ModelType):
|
|
|
270
270
|
|
|
271
271
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
272
272
|
file_import = FileImport(self.code_model)
|
|
273
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.
|
|
273
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
|
|
274
274
|
file_import.define_mutable_mapping_type()
|
|
275
275
|
if self.is_xml:
|
|
276
276
|
file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
|
|
@@ -351,7 +351,7 @@ class MsrestModelType(GeneratedModelType):
|
|
|
351
351
|
|
|
352
352
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
353
353
|
file_import = super().imports(**kwargs)
|
|
354
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.
|
|
354
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
|
|
355
355
|
return file_import
|
|
356
356
|
|
|
357
357
|
|