Skip to content

Commit b570129

Browse files
authored
[python] Add logic to clear output folder (#3239)
* add test case * Update dependencies * Add changelog .chronus/changes/auto-microsoft-clear-output-dir-python-2025-9-11-13-42-52.md * Update dependencies (2025-10-11 08:34:33) * Regenerate for typespec-python (2025-10-11 08:39:41) * fix regeneration * fix test case * fix test case * Update dependencies * Update dependencies (2025-10-29 06:18:24) * update dependency * add changelgo --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent 927642e commit b570129

File tree

16 files changed

+83
-424
lines changed

16 files changed

+83
-424
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: feature
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Add logic to clear output folder
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Exclude unnecessary files from pylint checks to improve execution speed

packages/autorest.python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "~0.19.2",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTUxNTI4Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.19.2.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"

packages/typespec-python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"js-yaml": "~4.1.0",
6868
"semver": "~7.6.2",
6969
"tsx": "~4.19.1",
70-
"@typespec/http-client-python": "~0.19.2",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTUxNTI4Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.19.2.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {

packages/typespec-python/scripts/eng/regenerate.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,45 @@ async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number)
431431
await Promise.all(workers);
432432
}
433433

434+
// create some files before regeneration. After regeneration, these files should be deleted and we will test it
435+
// in test case
436+
async function preprocess(flags: RegenerateFlagsInput): Promise<void> {
437+
if (flags.flavor === "azure") {
438+
const generalParts = [PLUGIN_DIR, "test", "azure", "generated"];
439+
await promises.writeFile(
440+
join(
441+
...generalParts,
442+
"authentication-api-key",
443+
"authentication",
444+
"apikey",
445+
"_operations",
446+
"to_be_deleted.py",
447+
),
448+
"# This file is to be deleted after regeneration",
449+
);
450+
451+
const folderParts = [...generalParts, "generation-subdir"];
452+
await promises.writeFile(
453+
join(...folderParts, "generation", "subdir", "_generated", "to_be_deleted.py"),
454+
"# This file is to be deleted after regeneration",
455+
);
456+
await promises.writeFile(
457+
join(...folderParts, "generated_tests", "to_be_deleted.py"),
458+
"# This file is to be kept after regeneration",
459+
);
460+
await promises.writeFile(
461+
join(...folderParts, "generation", "subdir", "to_be_kept.py"),
462+
"# This file is to be kept after regeneration",
463+
);
464+
}
465+
}
466+
434467
async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
435468
if (flags.flavor === undefined) {
436469
await regenerate({ ...flags, flavor: "azure" });
437470
await regenerate({ ...flags, flavor: "unbranded" });
438471
} else {
472+
await preprocess(flags);
439473
const flagsResolved = { debug: false, flavor: flags.flavor, ...flags };
440474
const subdirectoriesForAzure = await getSubdirectories(AZURE_HTTP_SPECS, flagsResolved);
441475
const subdirectoriesForNonAzure = await getSubdirectories(HTTP_SPECS, flagsResolved);

packages/typespec-python/test/azure/generated/azure-payload-pageable/specs/azure/payload/pageable/_validation.py

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file is to be kept after regeneration

packages/typespec-python/test/azure/generated/payload-pageable/generated_tests/test_pageable.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/typespec-python/test/azure/generated/payload-pageable/generated_tests/test_pageable_async.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_operations/__init__.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)