@azure-tools/typespec-python 0.61.1 → 0.61.3
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/README.md +4 -4
- package/dist/{scripts/eng → eng/scripts/ci}/format.d.ts.map +1 -1
- package/dist/eng/scripts/ci/format.js +140 -0
- package/dist/eng/scripts/ci/format.js.map +1 -0
- package/dist/eng/scripts/ci/lint.d.ts +2 -0
- package/dist/eng/scripts/ci/lint.d.ts.map +1 -0
- package/dist/eng/scripts/ci/lint.js +96 -0
- package/dist/eng/scripts/ci/lint.js.map +1 -0
- package/dist/eng/scripts/ci/run-tests.d.ts.map +1 -0
- package/dist/eng/scripts/ci/run-tests.js +226 -0
- package/dist/eng/scripts/ci/run-tests.js.map +1 -0
- package/dist/{scripts/eng → eng/scripts}/regenerate-common.d.ts +1 -0
- package/dist/eng/scripts/regenerate-common.d.ts.map +1 -0
- package/dist/{scripts/eng → eng/scripts}/regenerate-common.js +15 -14
- package/dist/{scripts/eng → eng/scripts}/regenerate-common.js.map +1 -1
- package/dist/eng/scripts/regenerate.d.ts +8 -0
- package/dist/eng/scripts/regenerate.d.ts.map +1 -0
- package/dist/eng/scripts/regenerate.js +288 -0
- package/dist/eng/scripts/regenerate.js.map +1 -0
- package/dist/eng/scripts/setup/run-python3.d.ts.map +1 -0
- package/dist/eng/scripts/setup/run-python3.js.map +1 -0
- package/dist/eng/scripts/setup/system-requirements.d.ts.map +1 -0
- package/dist/{scripts → eng/scripts/setup}/system-requirements.js +6 -2
- package/dist/eng/scripts/setup/system-requirements.js.map +1 -0
- package/{scripts → eng/scripts/setup}/__pycache__/package_manager.cpython-310.pyc +0 -0
- package/{scripts → eng/scripts/setup}/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/{scripts → eng/scripts/setup}/prepare.py +1 -1
- package/{scripts → eng/scripts/setup}/run_tsp.py +7 -7
- package/{scripts → eng/scripts/setup}/system-requirements.ts +6 -2
- package/package.json +52 -49
- package/dist/scripts/eng/format.js +0 -4
- package/dist/scripts/eng/format.js.map +0 -1
- package/dist/scripts/eng/lint.d.ts +0 -5
- package/dist/scripts/eng/lint.d.ts.map +0 -1
- package/dist/scripts/eng/lint.js +0 -95
- package/dist/scripts/eng/lint.js.map +0 -1
- package/dist/scripts/eng/regenerate-common.d.ts.map +0 -1
- package/dist/scripts/eng/regenerate.d.ts +0 -2
- package/dist/scripts/eng/regenerate.d.ts.map +0 -1
- package/dist/scripts/eng/regenerate.js +0 -123
- package/dist/scripts/eng/regenerate.js.map +0 -1
- package/dist/scripts/eng/run-tests.d.ts.map +0 -1
- package/dist/scripts/eng/run-tests.js +0 -91
- package/dist/scripts/eng/run-tests.js.map +0 -1
- package/dist/scripts/eng/utils.d.ts +0 -3
- package/dist/scripts/eng/utils.d.ts.map +0 -1
- package/dist/scripts/eng/utils.js +0 -39
- package/dist/scripts/eng/utils.js.map +0 -1
- package/dist/scripts/run-python3.d.ts.map +0 -1
- package/dist/scripts/run-python3.js.map +0 -1
- package/dist/scripts/system-requirements.d.ts.map +0 -1
- package/dist/scripts/system-requirements.js.map +0 -1
- package/scripts/eng/format.ts +0 -5
- package/scripts/eng/lint.ts +0 -102
- package/scripts/eng/mypy.ini +0 -40
- package/scripts/eng/pylintrc +0 -59
- package/scripts/eng/pyrightconfig.json +0 -7
- package/scripts/eng/regenerate-common.ts +0 -449
- package/scripts/eng/regenerate.ts +0 -159
- package/scripts/eng/run-tests.ts +0 -101
- package/scripts/eng/utils.ts +0 -38
- /package/dist/{scripts/eng → eng/scripts/ci}/format.d.ts +0 -0
- /package/dist/{scripts/eng → eng/scripts/ci}/run-tests.d.ts +0 -0
- /package/dist/{scripts → eng/scripts/setup}/run-python3.d.ts +0 -0
- /package/dist/{scripts → eng/scripts/setup}/run-python3.js +0 -0
- /package/dist/{scripts → eng/scripts/setup}/system-requirements.d.ts +0 -0
- /package/{scripts → eng/scripts/setup}/install.py +0 -0
- /package/{scripts → eng/scripts/setup}/package_manager.py +0 -0
- /package/{scripts → eng/scripts/setup}/run-python3.ts +0 -0
- /package/{scripts → eng/scripts/setup}/venvtools.py +0 -0
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
import { promises } from "fs";
|
|
2
|
-
import { dirname, join, relative, resolve } from "path";
|
|
3
|
-
|
|
4
|
-
// ---- Shared constants ----
|
|
5
|
-
|
|
6
|
-
export const SKIP_SPECS: string[] = ["type/file"];
|
|
7
|
-
|
|
8
|
-
export const SpecialFlags: Record<string, Record<string, any>> = {
|
|
9
|
-
azure: {
|
|
10
|
-
"generate-test": true,
|
|
11
|
-
"generate-sample": true,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// ---- Base emitter options (shared across repos) ----
|
|
16
|
-
|
|
17
|
-
export const BASE_AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
18
|
-
"azure/client-generator-core/access": {
|
|
19
|
-
namespace: "specs.azure.clientgenerator.core.access",
|
|
20
|
-
},
|
|
21
|
-
"azure/client-generator-core/alternate-type": {
|
|
22
|
-
namespace: "specs.azure.clientgenerator.core.alternatetype",
|
|
23
|
-
},
|
|
24
|
-
"azure/client-generator-core/api-version": {
|
|
25
|
-
namespace: "specs.azure.clientgenerator.core.apiversion",
|
|
26
|
-
},
|
|
27
|
-
"azure/client-generator-core/client-initialization/default": {
|
|
28
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.default",
|
|
29
|
-
},
|
|
30
|
-
"azure/client-generator-core/client-initialization/individually": {
|
|
31
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.individually",
|
|
32
|
-
},
|
|
33
|
-
"azure/client-generator-core/client-initialization/individuallyParent": {
|
|
34
|
-
namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent",
|
|
35
|
-
},
|
|
36
|
-
"azure/client-generator-core/client-location": {
|
|
37
|
-
namespace: "specs.azure.clientgenerator.core.clientlocation",
|
|
38
|
-
},
|
|
39
|
-
"azure/client-generator-core/deserialize-empty-string-as-null": {
|
|
40
|
-
namespace: "specs.azure.clientgenerator.core.emptystring",
|
|
41
|
-
},
|
|
42
|
-
"azure/client-generator-core/flatten-property": {
|
|
43
|
-
namespace: "specs.azure.clientgenerator.core.flattenproperty",
|
|
44
|
-
},
|
|
45
|
-
"azure/client-generator-core/usage": {
|
|
46
|
-
namespace: "specs.azure.clientgenerator.core.usage",
|
|
47
|
-
},
|
|
48
|
-
"azure/client-generator-core/override": {
|
|
49
|
-
namespace: "specs.azure.clientgenerator.core.override",
|
|
50
|
-
},
|
|
51
|
-
"azure/client-generator-core/hierarchy-building": {
|
|
52
|
-
namespace: "specs.azure.clientgenerator.core.hierarchybuilding",
|
|
53
|
-
},
|
|
54
|
-
"azure/core/basic": {
|
|
55
|
-
namespace: "specs.azure.core.basic",
|
|
56
|
-
},
|
|
57
|
-
"azure/core/lro/rpc": {
|
|
58
|
-
namespace: "specs.azure.core.lro.rpc",
|
|
59
|
-
},
|
|
60
|
-
"azure/core/lro/standard": {
|
|
61
|
-
namespace: "specs.azure.core.lro.standard",
|
|
62
|
-
},
|
|
63
|
-
"azure/core/model": {
|
|
64
|
-
namespace: "specs.azure.core.model",
|
|
65
|
-
},
|
|
66
|
-
"azure/core/page": {
|
|
67
|
-
namespace: "specs.azure.core.page",
|
|
68
|
-
},
|
|
69
|
-
"azure/core/scalar": {
|
|
70
|
-
namespace: "specs.azure.core.scalar",
|
|
71
|
-
},
|
|
72
|
-
"azure/core/traits": {
|
|
73
|
-
namespace: "specs.azure.core.traits",
|
|
74
|
-
},
|
|
75
|
-
"azure/encode/duration": {
|
|
76
|
-
namespace: "specs.azure.encode.duration",
|
|
77
|
-
},
|
|
78
|
-
"azure/example/basic": {
|
|
79
|
-
namespace: "specs.azure.example.basic",
|
|
80
|
-
},
|
|
81
|
-
"azure/payload/pageable": {
|
|
82
|
-
namespace: "specs.azure.payload.pageable",
|
|
83
|
-
},
|
|
84
|
-
"azure/versioning/previewVersion": {
|
|
85
|
-
namespace: "specs.azure.versioning.previewversion",
|
|
86
|
-
},
|
|
87
|
-
"client/structure/default": {
|
|
88
|
-
namespace: "client.structure.service",
|
|
89
|
-
},
|
|
90
|
-
"client/structure/multi-client": {
|
|
91
|
-
"package-name": "client-structure-multiclient",
|
|
92
|
-
"namespace": "client.structure.multiclient",
|
|
93
|
-
},
|
|
94
|
-
"client/structure/renamed-operation": {
|
|
95
|
-
"package-name": "client-structure-renamedoperation",
|
|
96
|
-
"namespace": "client.structure.renamedoperation",
|
|
97
|
-
},
|
|
98
|
-
"client/structure/two-operation-group": {
|
|
99
|
-
"package-name": "client-structure-twooperationgroup",
|
|
100
|
-
"namespace": "client.structure.twooperationgroup",
|
|
101
|
-
},
|
|
102
|
-
"client/naming": {
|
|
103
|
-
namespace: "client.naming.main",
|
|
104
|
-
},
|
|
105
|
-
"client/overload": {
|
|
106
|
-
namespace: "client.overload",
|
|
107
|
-
},
|
|
108
|
-
"encode/duration": {
|
|
109
|
-
namespace: "encode.duration",
|
|
110
|
-
},
|
|
111
|
-
"encode/numeric": {
|
|
112
|
-
namespace: "encode.numeric",
|
|
113
|
-
},
|
|
114
|
-
"parameters/basic": {
|
|
115
|
-
namespace: "parameters.basic",
|
|
116
|
-
},
|
|
117
|
-
"parameters/spread": {
|
|
118
|
-
namespace: "parameters.spread",
|
|
119
|
-
},
|
|
120
|
-
"payload/content-negotiation": {
|
|
121
|
-
namespace: "payload.contentnegotiation",
|
|
122
|
-
},
|
|
123
|
-
"payload/multipart": {
|
|
124
|
-
namespace: "payload.multipart",
|
|
125
|
-
},
|
|
126
|
-
"serialization/encoded-name/json": {
|
|
127
|
-
namespace: "serialization.encodedname.json",
|
|
128
|
-
},
|
|
129
|
-
"special-words": {
|
|
130
|
-
namespace: "specialwords",
|
|
131
|
-
},
|
|
132
|
-
"service/multi-service": {
|
|
133
|
-
namespace: "service.multiservice",
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const BASE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
138
|
-
"resiliency/srv-driven/old.tsp": {
|
|
139
|
-
"package-name": "resiliency-srv-driven1",
|
|
140
|
-
"namespace": "resiliency.srv.driven1",
|
|
141
|
-
"package-mode": "azure-dataplane",
|
|
142
|
-
"package-pprint-name": "ResiliencySrvDriven1",
|
|
143
|
-
},
|
|
144
|
-
"resiliency/srv-driven": {
|
|
145
|
-
"package-name": "resiliency-srv-driven2",
|
|
146
|
-
"namespace": "resiliency.srv.driven2",
|
|
147
|
-
"package-mode": "azure-dataplane",
|
|
148
|
-
"package-pprint-name": "ResiliencySrvDriven2",
|
|
149
|
-
},
|
|
150
|
-
"authentication/api-key": {
|
|
151
|
-
"clear-output-folder": "true",
|
|
152
|
-
},
|
|
153
|
-
"authentication/http/custom": {
|
|
154
|
-
"package-name": "authentication-http-custom",
|
|
155
|
-
"namespace": "authentication.http.custom",
|
|
156
|
-
"package-pprint-name": "Authentication Http Custom",
|
|
157
|
-
},
|
|
158
|
-
"authentication/union": [
|
|
159
|
-
{
|
|
160
|
-
"package-name": "authentication-union",
|
|
161
|
-
"namespace": "authentication.union",
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
"package-name": "setuppy-authentication-union",
|
|
165
|
-
"namespace": "setuppy.authentication.union",
|
|
166
|
-
"keep-setup-py": "true",
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
"type/array": {
|
|
170
|
-
"package-name": "typetest-array",
|
|
171
|
-
"namespace": "typetest.array",
|
|
172
|
-
},
|
|
173
|
-
"type/dictionary": {
|
|
174
|
-
"package-name": "typetest-dictionary",
|
|
175
|
-
"namespace": "typetest.dictionary",
|
|
176
|
-
},
|
|
177
|
-
"type/enum/extensible": {
|
|
178
|
-
"package-name": "typetest-enum-extensible",
|
|
179
|
-
"namespace": "typetest.enum.extensible",
|
|
180
|
-
},
|
|
181
|
-
"type/enum/fixed": {
|
|
182
|
-
"package-name": "typetest-enum-fixed",
|
|
183
|
-
"namespace": "typetest.enum.fixed",
|
|
184
|
-
},
|
|
185
|
-
"type/model/empty": {
|
|
186
|
-
"package-name": "typetest-model-empty",
|
|
187
|
-
"namespace": "typetest.model.empty",
|
|
188
|
-
},
|
|
189
|
-
"type/model/inheritance/enum-discriminator": {
|
|
190
|
-
"package-name": "typetest-model-enumdiscriminator",
|
|
191
|
-
"namespace": "typetest.model.enumdiscriminator",
|
|
192
|
-
},
|
|
193
|
-
"type/model/inheritance/nested-discriminator": {
|
|
194
|
-
"package-name": "typetest-model-nesteddiscriminator",
|
|
195
|
-
"namespace": "typetest.model.nesteddiscriminator",
|
|
196
|
-
},
|
|
197
|
-
"type/model/inheritance/not-discriminated": {
|
|
198
|
-
"package-name": "typetest-model-notdiscriminated",
|
|
199
|
-
"namespace": "typetest.model.notdiscriminated",
|
|
200
|
-
},
|
|
201
|
-
"type/model/inheritance/single-discriminator": {
|
|
202
|
-
"package-name": "typetest-model-singlediscriminator",
|
|
203
|
-
"namespace": "typetest.model.singlediscriminator",
|
|
204
|
-
},
|
|
205
|
-
"type/model/inheritance/recursive": {
|
|
206
|
-
"package-name": "typetest-model-recursive",
|
|
207
|
-
"namespace": "typetest.model.recursive",
|
|
208
|
-
},
|
|
209
|
-
"type/model/usage": {
|
|
210
|
-
"package-name": "typetest-model-usage",
|
|
211
|
-
"namespace": "typetest.model.usage",
|
|
212
|
-
},
|
|
213
|
-
"type/model/visibility": [
|
|
214
|
-
{
|
|
215
|
-
"package-name": "typetest-model-visibility",
|
|
216
|
-
"namespace": "typetest.model.visibility",
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
"package-name": "headasbooleantrue",
|
|
220
|
-
"namespace": "headasbooleantrue",
|
|
221
|
-
"head-as-boolean": "true",
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
"package-name": "headasbooleanfalse",
|
|
225
|
-
"namespace": "headasbooleanfalse",
|
|
226
|
-
"head-as-boolean": "false",
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
"type/property/nullable": {
|
|
230
|
-
"package-name": "typetest-property-nullable",
|
|
231
|
-
"namespace": "typetest.property.nullable",
|
|
232
|
-
},
|
|
233
|
-
"type/property/optionality": {
|
|
234
|
-
"package-name": "typetest-property-optional",
|
|
235
|
-
"namespace": "typetest.property.optional",
|
|
236
|
-
},
|
|
237
|
-
"type/property/additional-properties": {
|
|
238
|
-
"package-name": "typetest-property-additionalproperties",
|
|
239
|
-
"namespace": "typetest.property.additionalproperties",
|
|
240
|
-
},
|
|
241
|
-
"type/scalar": {
|
|
242
|
-
"package-name": "typetest-scalar",
|
|
243
|
-
"namespace": "typetest.scalar",
|
|
244
|
-
},
|
|
245
|
-
"type/property/value-types": {
|
|
246
|
-
"package-name": "typetest-property-valuetypes",
|
|
247
|
-
"namespace": "typetest.property.valuetypes",
|
|
248
|
-
},
|
|
249
|
-
"type/union": {
|
|
250
|
-
"package-name": "typetest-union",
|
|
251
|
-
"namespace": "typetest.union",
|
|
252
|
-
},
|
|
253
|
-
"type/union/discriminated": {
|
|
254
|
-
"package-name": "typetest-discriminatedunion",
|
|
255
|
-
"namespace": "typetest.discriminatedunion",
|
|
256
|
-
},
|
|
257
|
-
"type/file": {
|
|
258
|
-
"package-name": "typetest-file",
|
|
259
|
-
"namespace": "typetest.file",
|
|
260
|
-
},
|
|
261
|
-
"documentation": {
|
|
262
|
-
"package-name": "specs-documentation",
|
|
263
|
-
"namespace": "specs.documentation",
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// ---- Shared interfaces ----
|
|
268
|
-
|
|
269
|
-
export interface TspCommand {
|
|
270
|
-
outputDir: string;
|
|
271
|
-
command: string | string[];
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface RegenerateFlagsInput {
|
|
275
|
-
flavor?: string;
|
|
276
|
-
debug?: boolean;
|
|
277
|
-
name?: string;
|
|
278
|
-
pyodide?: boolean;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export interface RegenerateFlags {
|
|
282
|
-
flavor: string;
|
|
283
|
-
debug: boolean;
|
|
284
|
-
name?: string;
|
|
285
|
-
pyodide?: boolean;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export interface ProcessedEmitterOption {
|
|
289
|
-
options: Record<string, string>;
|
|
290
|
-
outputDir: string;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export interface RegenerateConfig {
|
|
294
|
-
azureHttpSpecs: string;
|
|
295
|
-
httpSpecs: string;
|
|
296
|
-
emitterOptions: Record<string, Record<string, string> | Record<string, string>[]>;
|
|
297
|
-
azureEmitterOptions: Record<string, Record<string, string> | Record<string, string>[]>;
|
|
298
|
-
preprocess: (flags: RegenerateFlagsInput) => Promise<void>;
|
|
299
|
-
getCmdList: (spec: string, flags: RegenerateFlags) => TspCommand[];
|
|
300
|
-
executeCommand: (cmd: TspCommand) => Promise<void>;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// ---- Shared utility functions ----
|
|
304
|
-
|
|
305
|
-
export function toPosix(dir: string): string {
|
|
306
|
-
return dir.replace(/\\/g, "/");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export function getEmitterOption(spec: string, flavor: string, config: RegenerateConfig): Record<string, string>[] {
|
|
310
|
-
const specDir = spec.includes("azure") ? config.azureHttpSpecs : config.httpSpecs;
|
|
311
|
-
const relativeSpec = toPosix(relative(specDir, spec));
|
|
312
|
-
const key = relativeSpec.includes("resiliency/srv-driven/old.tsp") ? relativeSpec : dirname(relativeSpec);
|
|
313
|
-
const emitter_options = config.emitterOptions[key] ||
|
|
314
|
-
(flavor === "azure" ? config.azureEmitterOptions[key] : [{}]) || [{}];
|
|
315
|
-
return Array.isArray(emitter_options) ? emitter_options : [emitter_options];
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promise<string[]> {
|
|
319
|
-
const subdirectories: string[] = [];
|
|
320
|
-
|
|
321
|
-
async function searchDir(currentDir: string) {
|
|
322
|
-
const items = await promises.readdir(currentDir, { withFileTypes: true });
|
|
323
|
-
|
|
324
|
-
const promisesArray = items.map(async (item) => {
|
|
325
|
-
const subDirPath = join(currentDir, item.name);
|
|
326
|
-
if (item.isDirectory()) {
|
|
327
|
-
const mainTspPath = join(subDirPath, "main.tsp");
|
|
328
|
-
const clientTspPath = join(subDirPath, "client.tsp");
|
|
329
|
-
|
|
330
|
-
const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath));
|
|
331
|
-
|
|
332
|
-
if (SKIP_SPECS.some((skipSpec) => mainTspRelativePath.includes(skipSpec))) return;
|
|
333
|
-
|
|
334
|
-
const hasMainTsp = await promises
|
|
335
|
-
.access(mainTspPath)
|
|
336
|
-
.then(() => true)
|
|
337
|
-
.catch(() => false);
|
|
338
|
-
const hasClientTsp = await promises
|
|
339
|
-
.access(clientTspPath)
|
|
340
|
-
.then(() => true)
|
|
341
|
-
.catch(() => false);
|
|
342
|
-
|
|
343
|
-
if (mainTspRelativePath.toLowerCase().includes(flags.name || "")) {
|
|
344
|
-
if (mainTspRelativePath.includes("resiliency/srv-driven")) {
|
|
345
|
-
subdirectories.push(resolve(subDirPath, "old.tsp"));
|
|
346
|
-
}
|
|
347
|
-
if (hasClientTsp) {
|
|
348
|
-
subdirectories.push(resolve(subDirPath, "client.tsp"));
|
|
349
|
-
} else if (hasMainTsp) {
|
|
350
|
-
subdirectories.push(resolve(subDirPath, "main.tsp"));
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// Recursively search in the subdirectory
|
|
355
|
-
await searchDir(subDirPath);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
await Promise.all(promisesArray);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
await searchDir(baseDir);
|
|
363
|
-
return subdirectories;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export function defaultPackageName(spec: string, config: RegenerateConfig): string {
|
|
367
|
-
const specDir = spec.includes("azure") ? config.azureHttpSpecs : config.httpSpecs;
|
|
368
|
-
return toPosix(relative(specDir, dirname(spec)))
|
|
369
|
-
.replace(/\//g, "-")
|
|
370
|
-
.toLowerCase();
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function buildOptions(
|
|
374
|
-
spec: string,
|
|
375
|
-
generatedFolder: string,
|
|
376
|
-
flags: RegenerateFlags,
|
|
377
|
-
config: RegenerateConfig,
|
|
378
|
-
): ProcessedEmitterOption[] {
|
|
379
|
-
const results: ProcessedEmitterOption[] = [];
|
|
380
|
-
for (const emitterConfig of getEmitterOption(spec, flags.flavor, config)) {
|
|
381
|
-
const options: Record<string, string> = { ...emitterConfig };
|
|
382
|
-
if (flags.pyodide) {
|
|
383
|
-
options["use-pyodide"] = "true";
|
|
384
|
-
}
|
|
385
|
-
options["flavor"] = flags.flavor;
|
|
386
|
-
for (const [k, v] of Object.entries(SpecialFlags[flags.flavor] ?? {})) {
|
|
387
|
-
options[k] = v;
|
|
388
|
-
}
|
|
389
|
-
if (options["emitter-output-dir"] === undefined) {
|
|
390
|
-
const packageName = options["package-name"] || defaultPackageName(spec, config);
|
|
391
|
-
options["emitter-output-dir"] = toPosix(`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`);
|
|
392
|
-
}
|
|
393
|
-
if (flags.debug) {
|
|
394
|
-
options["debug"] = "true";
|
|
395
|
-
}
|
|
396
|
-
options["examples-dir"] = toPosix(join(dirname(spec), "examples"));
|
|
397
|
-
results.push({
|
|
398
|
-
options,
|
|
399
|
-
outputDir: options["emitter-output-dir"],
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
return results;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
|
|
406
|
-
async function worker(start: number, end: number) {
|
|
407
|
-
while (start < end) {
|
|
408
|
-
await tasks[start]();
|
|
409
|
-
start++;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const workers = [];
|
|
414
|
-
let start = 0;
|
|
415
|
-
while (start < tasks.length) {
|
|
416
|
-
const end = Math.min(start + poolLimit, tasks.length);
|
|
417
|
-
workers.push((async () => await worker(start, end))());
|
|
418
|
-
start = end;
|
|
419
|
-
}
|
|
420
|
-
await Promise.all(workers);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export async function regenerate(flags: RegenerateFlagsInput, config: RegenerateConfig): Promise<void> {
|
|
424
|
-
if (flags.flavor === undefined) {
|
|
425
|
-
await regenerate({ flavor: "azure", ...flags }, config);
|
|
426
|
-
await regenerate({ flavor: "unbranded", ...flags }, config);
|
|
427
|
-
} else {
|
|
428
|
-
await config.preprocess(flags);
|
|
429
|
-
|
|
430
|
-
const flagsResolved: RegenerateFlags = { debug: false, flavor: flags.flavor, ...flags };
|
|
431
|
-
const subdirectoriesForAzure = await getSubdirectories(config.azureHttpSpecs, flagsResolved);
|
|
432
|
-
const subdirectoriesForNonAzure = await getSubdirectories(config.httpSpecs, flagsResolved);
|
|
433
|
-
const subdirectories =
|
|
434
|
-
flags.flavor === "azure"
|
|
435
|
-
? [...subdirectoriesForAzure, ...subdirectoriesForNonAzure]
|
|
436
|
-
: subdirectoriesForNonAzure;
|
|
437
|
-
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
|
|
438
|
-
config.getCmdList(subdirectory, flagsResolved),
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
// Create tasks as functions for the pool
|
|
442
|
-
const tasks: Array<() => Promise<void>> = cmdList.map((tspCommand) => {
|
|
443
|
-
return () => config.executeCommand(tspCommand);
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
// Run tasks with a concurrency limit
|
|
447
|
-
await runTaskPool(tasks, 30);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { exec as execCallback } from "child_process";
|
|
3
|
-
import { promisify } from "util";
|
|
4
|
-
import yargs from "yargs";
|
|
5
|
-
import { hideBin } from "yargs/helpers";
|
|
6
|
-
import { join, resolve } from "path";
|
|
7
|
-
import { promises, rmSync } from "fs";
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
9
|
-
import {
|
|
10
|
-
BASE_AZURE_EMITTER_OPTIONS,
|
|
11
|
-
BASE_EMITTER_OPTIONS,
|
|
12
|
-
buildOptions,
|
|
13
|
-
regenerate,
|
|
14
|
-
toPosix,
|
|
15
|
-
type RegenerateConfig,
|
|
16
|
-
type RegenerateFlags,
|
|
17
|
-
type RegenerateFlagsInput,
|
|
18
|
-
type TspCommand,
|
|
19
|
-
} from "./regenerate-common.js";
|
|
20
|
-
|
|
21
|
-
// Promisify the exec function
|
|
22
|
-
const exec = promisify(execCallback);
|
|
23
|
-
|
|
24
|
-
// Get the directory of the current file
|
|
25
|
-
const PLUGIN_DIR = resolve(fileURLToPath(import.meta.url), "../../../");
|
|
26
|
-
const AZURE_HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@azure-tools/azure-http-specs/specs");
|
|
27
|
-
const HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@typespec/http-specs/specs");
|
|
28
|
-
const EMITTER_NAME = "@azure-tools/typespec-python";
|
|
29
|
-
|
|
30
|
-
const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
31
|
-
...BASE_AZURE_EMITTER_OPTIONS,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
|
|
35
|
-
...BASE_EMITTER_OPTIONS,
|
|
36
|
-
"type/model/inheritance/recursive": [
|
|
37
|
-
{
|
|
38
|
-
"package-name": "typetest-model-recursive",
|
|
39
|
-
"namespace": "typetest.model.recursive",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"package-name": "generation-subdir",
|
|
43
|
-
"namespace": "generation.subdir",
|
|
44
|
-
"generation-subdir": "_generated",
|
|
45
|
-
"clear-output-folder": "true",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
"client/structure/client-operation-group": {
|
|
49
|
-
"package-name": "client-structure-clientoperationgroup",
|
|
50
|
-
"namespace": "client.structure.clientoperationgroup",
|
|
51
|
-
},
|
|
52
|
-
"client/structure/multi-client": {
|
|
53
|
-
"package-name": "client-structure-multiclient",
|
|
54
|
-
"namespace": "client.structure.multiclient",
|
|
55
|
-
},
|
|
56
|
-
"client/structure/renamed-operation": {
|
|
57
|
-
"package-name": "client-structure-renamedoperation",
|
|
58
|
-
"namespace": "client.structure.renamedoperation",
|
|
59
|
-
},
|
|
60
|
-
"client/structure/two-operation-group": {
|
|
61
|
-
"package-name": "client-structure-twooperationgroup",
|
|
62
|
-
"namespace": "client.structure.twooperationgroup",
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Function to execute CLI commands asynchronously
|
|
67
|
-
async function executeCommand(tspCommand: TspCommand): Promise<void> {
|
|
68
|
-
try {
|
|
69
|
-
const cmd = tspCommand.command as string;
|
|
70
|
-
console.log(`exec: ${cmd}`);
|
|
71
|
-
const { stdout, stderr } = await exec(cmd);
|
|
72
|
-
if (stdout) console.log(`stdout: ${stdout}`);
|
|
73
|
-
if (stderr) console.error(`stderr: ${stderr}`);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(`exec error: ${error}`);
|
|
76
|
-
rmSync(tspCommand.outputDir, { recursive: true, force: true });
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// create some files before regeneration. After regeneration, these files should be deleted and we will test it
|
|
82
|
-
// in test case
|
|
83
|
-
async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
|
|
84
|
-
if (flags.flavor === "azure") {
|
|
85
|
-
const generalParts = [PLUGIN_DIR, "test", "azure", "generated"];
|
|
86
|
-
await promises.writeFile(
|
|
87
|
-
join(
|
|
88
|
-
...generalParts,
|
|
89
|
-
"authentication-api-key",
|
|
90
|
-
"authentication",
|
|
91
|
-
"apikey",
|
|
92
|
-
"_operations",
|
|
93
|
-
"to_be_deleted.py",
|
|
94
|
-
),
|
|
95
|
-
"# This file is to be deleted after regeneration",
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const folderParts = [...generalParts, "generation-subdir"];
|
|
99
|
-
await promises.writeFile(
|
|
100
|
-
join(...folderParts, "generation", "subdir", "_generated", "to_be_deleted.py"),
|
|
101
|
-
"# This file is to be deleted after regeneration",
|
|
102
|
-
);
|
|
103
|
-
await promises.writeFile(
|
|
104
|
-
join(...folderParts, "generated_tests", "to_be_deleted.py"),
|
|
105
|
-
"# This file is to be kept after regeneration",
|
|
106
|
-
);
|
|
107
|
-
await promises.writeFile(
|
|
108
|
-
join(...folderParts, "generation", "subdir", "to_be_kept.py"),
|
|
109
|
-
"# This file is to be kept after regeneration",
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
|
|
115
|
-
return buildOptions(spec, PLUGIN_DIR, flags, config).map((po) => {
|
|
116
|
-
const optionsStr = Object.entries(po.options)
|
|
117
|
-
.flatMap(([k, v]) => {
|
|
118
|
-
return `--option ${EMITTER_NAME}.${k}=${typeof v === "string" && v.indexOf(" ") > -1 ? `"${v}"` : v}`;
|
|
119
|
-
})
|
|
120
|
-
.join(" ");
|
|
121
|
-
return {
|
|
122
|
-
outputDir: po.outputDir,
|
|
123
|
-
command: `tsp compile ${spec} --emit=${toPosix(PLUGIN_DIR)} ${optionsStr}`,
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const config: RegenerateConfig = {
|
|
129
|
-
azureHttpSpecs: AZURE_HTTP_SPECS,
|
|
130
|
-
httpSpecs: HTTP_SPECS,
|
|
131
|
-
emitterOptions: EMITTER_OPTIONS,
|
|
132
|
-
azureEmitterOptions: AZURE_EMITTER_OPTIONS,
|
|
133
|
-
preprocess,
|
|
134
|
-
getCmdList: _getCmdList,
|
|
135
|
-
executeCommand,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// PARSE INPUT ARGUMENTS
|
|
139
|
-
const argv = yargs(hideBin(process.argv))
|
|
140
|
-
.option("flavor", {
|
|
141
|
-
type: "string",
|
|
142
|
-
choices: ["azure", "unbranded"],
|
|
143
|
-
description: "Specify the flavor",
|
|
144
|
-
})
|
|
145
|
-
.option("debug", {
|
|
146
|
-
alias: "d",
|
|
147
|
-
type: "boolean",
|
|
148
|
-
description: "Debug mode",
|
|
149
|
-
})
|
|
150
|
-
.option("name", {
|
|
151
|
-
alias: "n",
|
|
152
|
-
type: "string",
|
|
153
|
-
description: "Specify filename if you only want to generate a subset",
|
|
154
|
-
}).argv;
|
|
155
|
-
|
|
156
|
-
const start = performance.now();
|
|
157
|
-
regenerate(argv as RegenerateFlags, config)
|
|
158
|
-
.then(() => console.log(`Regeneration successful, time taken: ${Math.round((performance.now() - start) / 1000)} s`))
|
|
159
|
-
.catch((error) => console.error(`Regeneration failed: ${error.message}`));
|