@typespec/http-client-python 0.27.1 → 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/emitter/src/code-model.ts +28 -21
- package/emitter/src/http.ts +10 -1
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/regenerate-common.ts +472 -0
- package/eng/scripts/ci/regenerate.ts +41 -437
- 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 +5 -5
- package/generator/build/lib/pygen/codegen/models/operation_group.py +1 -1
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +2 -2
- 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/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 +5 -5
- package/generator/pygen/codegen/models/operation_group.py +1 -1
- package/generator/pygen/codegen/models/paging_operation.py +2 -2
- 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_core_page_async.py +12 -0
- package/generator/test/azure/mock_api_tests/test_azure_core_page.py +11 -0
- package/generator/test/azure/mock_api_tests/test_clear_output_folder.py +9 -0
- package/generator/test/azure/requirements.txt +4 -1
- 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_xml_async.py +21 -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_xml.py +19 -0
- package/generator/test/unbranded/mock_api_tests/test_unbranded.py +9 -8
- package/generator/test/unbranded/requirements.txt +2 -1
- package/generator/test/unittests/test_model_base_serialization.py +161 -0
- package/package.json +11 -11
|
@@ -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[] = ["type/file"];
|
|
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,290 +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/default": {
|
|
53
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.default",
|
|
54
|
-
},
|
|
55
|
-
"azure/client-generator-core/client-initialization/individually": {
|
|
56
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.individually",
|
|
57
|
-
},
|
|
58
|
-
"azure/client-generator-core/client-initialization/individuallyParent": {
|
|
59
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent",
|
|
60
|
-
},
|
|
61
|
-
"azure/client-generator-core/client-location": {
|
|
62
|
-
namespace: "specs.azure.clientgenerator.core.clientlocation",
|
|
63
|
-
},
|
|
64
|
-
"azure/client-generator-core/deserialize-empty-string-as-null": {
|
|
65
|
-
namespace: "specs.azure.clientgenerator.core.emptystring",
|
|
66
|
-
},
|
|
67
|
-
"azure/client-generator-core/flatten-property": {
|
|
68
|
-
namespace: "specs.azure.clientgenerator.core.flattenproperty",
|
|
69
|
-
},
|
|
70
|
-
"azure/client-generator-core/usage": {
|
|
71
|
-
namespace: "specs.azure.clientgenerator.core.usage",
|
|
72
|
-
},
|
|
73
|
-
"azure/client-generator-core/override": {
|
|
74
|
-
namespace: "specs.azure.clientgenerator.core.override",
|
|
75
|
-
},
|
|
76
|
-
"azure/client-generator-core/hierarchy-building": {
|
|
77
|
-
namespace: "specs.azure.clientgenerator.core.hierarchybuilding",
|
|
78
|
-
},
|
|
79
|
-
"azure/core/basic": {
|
|
80
|
-
namespace: "specs.azure.core.basic",
|
|
81
|
-
},
|
|
82
|
-
"azure/core/lro/rpc": {
|
|
83
|
-
namespace: "specs.azure.core.lro.rpc",
|
|
84
|
-
},
|
|
85
|
-
"azure/core/lro/standard": {
|
|
86
|
-
namespace: "specs.azure.core.lro.standard",
|
|
87
|
-
},
|
|
88
|
-
"azure/core/model": {
|
|
89
|
-
namespace: "specs.azure.core.model",
|
|
90
|
-
},
|
|
91
|
-
"azure/core/page": {
|
|
92
|
-
namespace: "specs.azure.core.page",
|
|
93
|
-
},
|
|
94
|
-
"azure/core/scalar": {
|
|
95
|
-
namespace: "specs.azure.core.scalar",
|
|
96
|
-
},
|
|
97
|
-
"azure/core/traits": {
|
|
98
|
-
namespace: "specs.azure.core.traits",
|
|
99
|
-
},
|
|
100
|
-
"azure/encode/duration": {
|
|
101
|
-
namespace: "specs.azure.encode.duration",
|
|
102
|
-
},
|
|
103
|
-
"azure/example/basic": {
|
|
104
|
-
namespace: "specs.azure.example.basic",
|
|
105
|
-
},
|
|
106
|
-
"azure/payload/pageable": {
|
|
107
|
-
namespace: "specs.azure.payload.pageable",
|
|
108
|
-
},
|
|
109
|
-
"azure/versioning/previewVersion": {
|
|
110
|
-
namespace: "specs.azure.versioning.previewversion",
|
|
111
|
-
},
|
|
112
|
-
"client/structure/default": {
|
|
113
|
-
namespace: "client.structure.service",
|
|
114
|
-
},
|
|
47
|
+
...BASE_AZURE_EMITTER_OPTIONS,
|
|
115
48
|
"client/structure/client-operation-group": {
|
|
116
49
|
"package-name": "client-structure-clientoperationgroup",
|
|
117
50
|
namespace: "client.structure.clientoperationgroup",
|
|
118
51
|
},
|
|
119
|
-
"client/structure/multi-client": {
|
|
120
|
-
"package-name": "client-structure-multiclient",
|
|
121
|
-
namespace: "client.structure.multiclient",
|
|
122
|
-
},
|
|
123
|
-
"client/structure/renamed-operation": {
|
|
124
|
-
"package-name": "client-structure-renamedoperation",
|
|
125
|
-
namespace: "client.structure.renamedoperation",
|
|
126
|
-
},
|
|
127
|
-
"client/structure/two-operation-group": {
|
|
128
|
-
"package-name": "client-structure-twooperationgroup",
|
|
129
|
-
namespace: "client.structure.twooperationgroup",
|
|
130
|
-
},
|
|
131
|
-
"client/naming": {
|
|
132
|
-
namespace: "client.naming.main",
|
|
133
|
-
},
|
|
134
|
-
"client/overload": {
|
|
135
|
-
namespace: "client.overload",
|
|
136
|
-
},
|
|
137
|
-
"encode/duration": {
|
|
138
|
-
namespace: "encode.duration",
|
|
139
|
-
},
|
|
140
|
-
"encode/numeric": {
|
|
141
|
-
namespace: "encode.numeric",
|
|
142
|
-
},
|
|
143
|
-
"parameters/basic": {
|
|
144
|
-
namespace: "parameters.basic",
|
|
145
|
-
},
|
|
146
|
-
"parameters/spread": {
|
|
147
|
-
namespace: "parameters.spread",
|
|
148
|
-
},
|
|
149
|
-
"payload/content-negotiation": {
|
|
150
|
-
namespace: "payload.contentnegotiation",
|
|
151
|
-
},
|
|
152
|
-
"payload/multipart": {
|
|
153
|
-
namespace: "payload.multipart",
|
|
154
|
-
},
|
|
155
|
-
"serialization/encoded-name/json": {
|
|
156
|
-
namespace: "serialization.encodedname.json",
|
|
157
|
-
},
|
|
158
|
-
"special-words": {
|
|
159
|
-
namespace: "specialwords",
|
|
160
|
-
},
|
|
161
|
-
"service/multi-service": {
|
|
162
|
-
namespace: "service.multiservice",
|
|
163
|
-
},
|
|
164
52
|
};
|
|
165
53
|
|
|
166
54
|
const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
167
|
-
|
|
168
|
-
"package-name": "resiliency-srv-driven1",
|
|
169
|
-
namespace: "resiliency.srv.driven1",
|
|
170
|
-
"package-mode": "azure-dataplane",
|
|
171
|
-
"package-pprint-name": "ResiliencySrvDriven1",
|
|
172
|
-
},
|
|
173
|
-
"resiliency/srv-driven": {
|
|
174
|
-
"package-name": "resiliency-srv-driven2",
|
|
175
|
-
namespace: "resiliency.srv.driven2",
|
|
176
|
-
"package-mode": "azure-dataplane",
|
|
177
|
-
"package-pprint-name": "ResiliencySrvDriven2",
|
|
178
|
-
},
|
|
179
|
-
"authentication/api-key": {
|
|
180
|
-
"clear-output-folder": "true",
|
|
181
|
-
},
|
|
182
|
-
"authentication/http/custom": {
|
|
183
|
-
"package-name": "authentication-http-custom",
|
|
184
|
-
namespace: "authentication.http.custom",
|
|
185
|
-
"package-pprint-name": "Authentication Http Custom",
|
|
186
|
-
},
|
|
187
|
-
"authentication/union": [
|
|
188
|
-
{
|
|
189
|
-
"package-name": "authentication-union",
|
|
190
|
-
namespace: "authentication.union",
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
"package-name": "setuppy-authentication-union",
|
|
194
|
-
namespace: "setuppy.authentication.union",
|
|
195
|
-
"keep-setup-py": "true",
|
|
196
|
-
},
|
|
197
|
-
],
|
|
55
|
+
...BASE_EMITTER_OPTIONS,
|
|
198
56
|
"type/array": {
|
|
199
57
|
"package-name": "typetest-array",
|
|
200
58
|
namespace: "typetest.array",
|
|
201
59
|
"use-pyodide": "true",
|
|
202
60
|
},
|
|
203
|
-
"type/dictionary": {
|
|
204
|
-
"package-name": "typetest-dictionary",
|
|
205
|
-
namespace: "typetest.dictionary",
|
|
206
|
-
},
|
|
207
|
-
"type/enum/extensible": {
|
|
208
|
-
"package-name": "typetest-enum-extensible",
|
|
209
|
-
namespace: "typetest.enum.extensible",
|
|
210
|
-
},
|
|
211
|
-
"type/enum/fixed": {
|
|
212
|
-
"package-name": "typetest-enum-fixed",
|
|
213
|
-
namespace: "typetest.enum.fixed",
|
|
214
|
-
},
|
|
215
|
-
"type/model/empty": {
|
|
216
|
-
"package-name": "typetest-model-empty",
|
|
217
|
-
namespace: "typetest.model.empty",
|
|
218
|
-
},
|
|
219
|
-
"type/model/inheritance/enum-discriminator": {
|
|
220
|
-
"package-name": "typetest-model-enumdiscriminator",
|
|
221
|
-
namespace: "typetest.model.enumdiscriminator",
|
|
222
|
-
},
|
|
223
|
-
"type/model/inheritance/nested-discriminator": {
|
|
224
|
-
"package-name": "typetest-model-nesteddiscriminator",
|
|
225
|
-
namespace: "typetest.model.nesteddiscriminator",
|
|
226
|
-
},
|
|
227
|
-
"type/model/inheritance/not-discriminated": {
|
|
228
|
-
"package-name": "typetest-model-notdiscriminated",
|
|
229
|
-
namespace: "typetest.model.notdiscriminated",
|
|
230
|
-
},
|
|
231
|
-
"type/model/inheritance/single-discriminator": {
|
|
232
|
-
"package-name": "typetest-model-singlediscriminator",
|
|
233
|
-
namespace: "typetest.model.singlediscriminator",
|
|
234
|
-
},
|
|
235
61
|
"type/model/inheritance/recursive": {
|
|
236
62
|
"package-name": "typetest-model-recursive",
|
|
237
63
|
namespace: "typetest.model.recursive",
|
|
238
64
|
"use-pyodide": "true",
|
|
239
65
|
},
|
|
240
|
-
"type/model/usage": {
|
|
241
|
-
"package-name": "typetest-model-usage",
|
|
242
|
-
namespace: "typetest.model.usage",
|
|
243
|
-
},
|
|
244
|
-
"type/model/visibility": [
|
|
245
|
-
{
|
|
246
|
-
"package-name": "typetest-model-visibility",
|
|
247
|
-
namespace: "typetest.model.visibility",
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
"package-name": "headasbooleantrue",
|
|
251
|
-
namespace: "headasbooleantrue",
|
|
252
|
-
"head-as-boolean": "true",
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
"package-name": "headasbooleanfalse",
|
|
256
|
-
namespace: "headasbooleanfalse",
|
|
257
|
-
"head-as-boolean": "false",
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
"type/property/nullable": {
|
|
261
|
-
"package-name": "typetest-property-nullable",
|
|
262
|
-
namespace: "typetest.property.nullable",
|
|
263
|
-
},
|
|
264
|
-
"type/property/optionality": {
|
|
265
|
-
"package-name": "typetest-property-optional",
|
|
266
|
-
namespace: "typetest.property.optional",
|
|
267
|
-
},
|
|
268
|
-
"type/property/additional-properties": {
|
|
269
|
-
"package-name": "typetest-property-additionalproperties",
|
|
270
|
-
namespace: "typetest.property.additionalproperties",
|
|
271
|
-
},
|
|
272
|
-
"type/scalar": {
|
|
273
|
-
"package-name": "typetest-scalar",
|
|
274
|
-
namespace: "typetest.scalar",
|
|
275
|
-
},
|
|
276
|
-
"type/property/value-types": {
|
|
277
|
-
"package-name": "typetest-property-valuetypes",
|
|
278
|
-
namespace: "typetest.property.valuetypes",
|
|
279
|
-
},
|
|
280
|
-
"type/union": {
|
|
281
|
-
"package-name": "typetest-union",
|
|
282
|
-
namespace: "typetest.union",
|
|
283
|
-
},
|
|
284
|
-
"type/union/discriminated": {
|
|
285
|
-
"package-name": "typetest-discriminatedunion",
|
|
286
|
-
namespace: "typetest.discriminatedunion",
|
|
287
|
-
},
|
|
288
|
-
"type/file": {
|
|
289
|
-
"package-name": "typetest-file",
|
|
290
|
-
namespace: "typetest.file",
|
|
291
|
-
},
|
|
292
|
-
documentation: {
|
|
293
|
-
"package-name": "specs-documentation",
|
|
294
|
-
namespace: "specs.documentation",
|
|
295
|
-
},
|
|
296
66
|
};
|
|
297
67
|
|
|
298
|
-
function toPosix(dir: string): string {
|
|
299
|
-
return dir.replace(/\\/g, "/");
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function getEmitterOption(spec: string, flavor: string): Record<string, string>[] {
|
|
303
|
-
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
|
|
304
|
-
const relativeSpec = toPosix(relative(specDir, spec));
|
|
305
|
-
const key = relativeSpec.includes("resiliency/srv-driven/old.tsp")
|
|
306
|
-
? relativeSpec
|
|
307
|
-
: dirname(relativeSpec);
|
|
308
|
-
const emitter_options = EMITTER_OPTIONS[key] ||
|
|
309
|
-
(flavor === "azure" ? AZURE_EMITTER_OPTIONS[key] : [{}]) || [{}];
|
|
310
|
-
return Array.isArray(emitter_options) ? emitter_options : [emitter_options];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
68
|
// Function to execute CLI commands asynchronously
|
|
314
69
|
async function executeCommand(tspCommand: TspCommand): Promise<void> {
|
|
70
|
+
const cmd = tspCommand.command as string[];
|
|
315
71
|
const execFileAsync = promisify(execFile);
|
|
316
72
|
try {
|
|
317
|
-
console.log(chalk.green(`start tsp ${
|
|
318
|
-
await execFileAsync("tsp",
|
|
319
|
-
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`));
|
|
320
76
|
} catch (err) {
|
|
321
77
|
rmSync(tspCommand.outputDir, { recursive: true, force: true });
|
|
322
78
|
console.error(chalk.red(`exec error: ${err}`));
|
|
@@ -324,153 +80,6 @@ async function executeCommand(tspCommand: TspCommand): Promise<void> {
|
|
|
324
80
|
}
|
|
325
81
|
}
|
|
326
82
|
|
|
327
|
-
interface RegenerateFlagsInput {
|
|
328
|
-
flavor?: string;
|
|
329
|
-
debug?: boolean;
|
|
330
|
-
name?: string;
|
|
331
|
-
pyodide?: boolean;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
interface RegenerateFlags {
|
|
335
|
-
flavor: string;
|
|
336
|
-
debug: boolean;
|
|
337
|
-
name?: string;
|
|
338
|
-
pyodide?: boolean;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const SpecialFlags: Record<string, Record<string, any>> = {
|
|
342
|
-
azure: {
|
|
343
|
-
"generate-test": true,
|
|
344
|
-
"generate-sample": true,
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promise<string[]> {
|
|
349
|
-
const subdirectories: string[] = [];
|
|
350
|
-
|
|
351
|
-
async function searchDir(currentDir: string) {
|
|
352
|
-
const items = await promises.readdir(currentDir, { withFileTypes: true });
|
|
353
|
-
|
|
354
|
-
const promisesArray = items.map(async (item) => {
|
|
355
|
-
const subDirPath = join(currentDir, item.name);
|
|
356
|
-
if (item.isDirectory()) {
|
|
357
|
-
const mainTspPath = join(subDirPath, "main.tsp");
|
|
358
|
-
const clientTspPath = join(subDirPath, "client.tsp");
|
|
359
|
-
|
|
360
|
-
const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath));
|
|
361
|
-
|
|
362
|
-
// Replace the individual skip checks with:
|
|
363
|
-
if (SKIP_SPECS.some((skipSpec) => mainTspRelativePath.includes(skipSpec))) return;
|
|
364
|
-
|
|
365
|
-
const hasMainTsp = await promises
|
|
366
|
-
.access(mainTspPath)
|
|
367
|
-
.then(() => true)
|
|
368
|
-
.catch(() => false);
|
|
369
|
-
const hasClientTsp = await promises
|
|
370
|
-
.access(clientTspPath)
|
|
371
|
-
.then(() => true)
|
|
372
|
-
.catch(() => false);
|
|
373
|
-
|
|
374
|
-
if (mainTspRelativePath.toLowerCase().includes(flags.name || "")) {
|
|
375
|
-
if (mainTspRelativePath.includes("resiliency/srv-driven")) {
|
|
376
|
-
subdirectories.push(resolve(subDirPath, "old.tsp"));
|
|
377
|
-
}
|
|
378
|
-
if (hasClientTsp) {
|
|
379
|
-
subdirectories.push(resolve(subDirPath, "client.tsp"));
|
|
380
|
-
} else if (hasMainTsp) {
|
|
381
|
-
subdirectories.push(resolve(subDirPath, "main.tsp"));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Recursively search in the subdirectory
|
|
386
|
-
await searchDir(subDirPath);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
await Promise.all(promisesArray);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
await searchDir(baseDir);
|
|
394
|
-
return subdirectories;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function defaultPackageName(spec: string): string {
|
|
398
|
-
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
|
|
399
|
-
return toPosix(relative(specDir, dirname(spec)))
|
|
400
|
-
.replace(/\//g, "-")
|
|
401
|
-
.toLowerCase();
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
interface EmitterConfig {
|
|
405
|
-
options: string[];
|
|
406
|
-
outputDir: string;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function addOptions(
|
|
410
|
-
spec: string,
|
|
411
|
-
generatedFolder: string,
|
|
412
|
-
flags: RegenerateFlags,
|
|
413
|
-
): EmitterConfig[] {
|
|
414
|
-
const emitterConfigs: EmitterConfig[] = [];
|
|
415
|
-
for (const config of getEmitterOption(spec, flags.flavor)) {
|
|
416
|
-
const options: Record<string, string> = { ...config };
|
|
417
|
-
if (flags.pyodide) {
|
|
418
|
-
options["use-pyodide"] = "true";
|
|
419
|
-
}
|
|
420
|
-
options["flavor"] = flags.flavor;
|
|
421
|
-
for (const [k, v] of Object.entries(SpecialFlags[flags.flavor] ?? {})) {
|
|
422
|
-
options[k] = v;
|
|
423
|
-
}
|
|
424
|
-
if (options["emitter-output-dir"] === undefined) {
|
|
425
|
-
const packageName = options["package-name"] || defaultPackageName(spec);
|
|
426
|
-
options["emitter-output-dir"] = toPosix(
|
|
427
|
-
`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`,
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
if (flags.debug) {
|
|
431
|
-
options["debug"] = "true";
|
|
432
|
-
}
|
|
433
|
-
options["examples-dir"] = toPosix(join(dirname(spec), "examples"));
|
|
434
|
-
const configs = Object.entries(options).flatMap(([k, v]) => {
|
|
435
|
-
return [
|
|
436
|
-
"--option",
|
|
437
|
-
`${argv.values.emitterName || "@typespec/http-client-python"}.${k}="${v}"`,
|
|
438
|
-
];
|
|
439
|
-
});
|
|
440
|
-
emitterConfigs.push({
|
|
441
|
-
options: configs,
|
|
442
|
-
outputDir: options["emitter-output-dir"],
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
return emitterConfigs;
|
|
446
|
-
}
|
|
447
|
-
function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
|
|
448
|
-
return addOptions(spec, GENERATED_FOLDER, flags).map((option) => {
|
|
449
|
-
return {
|
|
450
|
-
outputDir: option.outputDir,
|
|
451
|
-
command: ["compile", spec, "--emit", toPosix(PLUGIN_DIR), ...option.options],
|
|
452
|
-
};
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
|
|
457
|
-
async function worker(start: number, end: number) {
|
|
458
|
-
while (start < end) {
|
|
459
|
-
await tasks[start]();
|
|
460
|
-
start++;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
const workers = [];
|
|
465
|
-
let start = 0;
|
|
466
|
-
while (start < tasks.length) {
|
|
467
|
-
const end = Math.min(start + poolLimit, tasks.length);
|
|
468
|
-
workers.push((async () => await worker(start, end))());
|
|
469
|
-
start = end;
|
|
470
|
-
}
|
|
471
|
-
await Promise.all(workers);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
83
|
// create some files before regeneration. After regeneration, these files should be deleted and we will test it
|
|
475
84
|
// in test case
|
|
476
85
|
async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
|
|
@@ -493,36 +102,31 @@ async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
|
|
|
493
102
|
}
|
|
494
103
|
}
|
|
495
104
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
flags.flavor === "azure"
|
|
508
|
-
? [...subdirectoriesForAzure, ...subdirectoriesForNonAzure]
|
|
509
|
-
: subdirectoriesForNonAzure;
|
|
510
|
-
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
|
|
511
|
-
_getCmdList(subdirectory, flagsResolved),
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
// Create tasks as functions for the pool
|
|
515
|
-
const tasks: Array<() => Promise<void>> = cmdList.map((tspCommand) => {
|
|
516
|
-
return () => executeCommand(tspCommand);
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
// Run tasks with a concurrency limit
|
|
520
|
-
await runTaskPool(tasks, 30);
|
|
521
|
-
}
|
|
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
|
+
});
|
|
522
116
|
}
|
|
523
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
|
+
|
|
524
128
|
const start = performance.now();
|
|
525
|
-
regenerate(argv.values)
|
|
129
|
+
regenerate(argv.values, config)
|
|
526
130
|
.then(() =>
|
|
527
131
|
console.log(
|
|
528
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
|
|
|
@@ -296,11 +296,11 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
296
296
|
|
|
297
297
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
298
298
|
file_import = FileImport(self.code_model)
|
|
299
|
-
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.
|
|
299
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
|
|
300
300
|
|
|
301
301
|
response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
|
|
302
302
|
if len(set(response_types)) > 1:
|
|
303
|
-
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.
|
|
303
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
|
|
304
304
|
if self.added_on:
|
|
305
305
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
306
306
|
file_import.add_submodule_import(
|
|
@@ -406,9 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
406
406
|
ImportType.SDKCORE,
|
|
407
407
|
)
|
|
408
408
|
file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
|
|
409
|
-
file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.
|
|
410
|
-
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.
|
|
411
|
-
file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.
|
|
409
|
+
file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.REGULAR)
|
|
410
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.REGULAR)
|
|
411
|
+
file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.REGULAR)
|
|
412
412
|
if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
|
|
413
413
|
file_import.add_submodule_import(
|
|
414
414
|
"azure.core.tracing.decorator",
|