diff --git a/.chronus/changes/mixinImportsFix-2025-6-23-14-18-42.md b/.chronus/changes/mixinImportsFix-2025-6-23-14-18-42.md new file mode 100644 index 00000000000..be9795dc959 --- /dev/null +++ b/.chronus/changes/mixinImportsFix-2025-6-23-14-18-42.md @@ -0,0 +1,8 @@ +--- +changeKind: fix +packages: + - "@autorest/python" + - "@azure-tools/typespec-python" +--- + +Fix regression that ignored patches to mixin operation groups when patched in the `operations` folder \ No newline at end of file diff --git a/packages/autorest.python/package.json b/packages/autorest.python/package.json index f1b085f750e..fec37ff739c 100644 --- a/packages/autorest.python/package.json +++ b/packages/autorest.python/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md", "dependencies": { - "@typespec/http-client-python": "~0.14.1-dev.2", + "@typespec/http-client-python": "~0.14.1", "@autorest/system-requirements": "~1.0.2", "fs-extra": "~11.2.0", "tsx": "~4.19.1" diff --git a/packages/autorest.python/scripts/eng/regenerate.ts b/packages/autorest.python/scripts/eng/regenerate.ts index 48688782a56..7c0702cbda9 100644 --- a/packages/autorest.python/scripts/eng/regenerate.ts +++ b/packages/autorest.python/scripts/eng/regenerate.ts @@ -119,11 +119,6 @@ function getEmitterOption(spec: string): Record[] { // Function to execute CLI commands asynchronously async function executeCommand(tspCommand: TspCommand): Promise { - try { - rmSync(tspCommand.outputDir, { recursive: true, force: true }); - } catch (error) { - console.error(`rm error: ${error}`); - } try { console.log(`exec: ${tspCommand.command}`); const { stdout, stderr } = await exec(tspCommand.command); @@ -131,6 +126,7 @@ async function executeCommand(tspCommand: TspCommand): Promise { if (stderr) console.error(`stderr: ${stderr}`); } catch (error) { console.error(`exec error: ${error}`); + rmSync(tspCommand.outputDir, { recursive: true, force: true }); throw error; } } diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index b33e04e04ac..3aef10394a2 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -67,7 +67,7 @@ "js-yaml": "~4.1.0", "semver": "~7.6.2", "tsx": "~4.19.1", - "@typespec/http-client-python": "~0.14.1-dev.2", + "@typespec/http-client-python": "~0.14.1", "fs-extra": "~11.2.0" }, "devDependencies": { diff --git a/packages/typespec-python/scripts/eng/regenerate.ts b/packages/typespec-python/scripts/eng/regenerate.ts index 9131d3a4f1d..d6d7b81e4bc 100644 --- a/packages/typespec-python/scripts/eng/regenerate.ts +++ b/packages/typespec-python/scripts/eng/regenerate.ts @@ -253,11 +253,6 @@ function getEmitterOption(spec: string, flavor: string): Record[ // Function to execute CLI commands asynchronously async function executeCommand(tspCommand: TspCommand): Promise { - try { - rmSync(tspCommand.outputDir, { recursive: true, force: true }); - } catch (error) { - console.error(`rm error: ${error}`); - } try { console.log(`exec: ${tspCommand.command}`); const { stdout, stderr } = await exec(tspCommand.command); @@ -265,6 +260,7 @@ async function executeCommand(tspCommand: TspCommand): Promise { if (stderr) console.error(`stderr: ${stderr}`); } catch (error) { console.error(`exec error: ${error}`); + rmSync(tspCommand.outputDir, { recursive: true, force: true }); throw error; } } diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_operations/_patch.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_operations/_patch.py index 8bcb627aa47..fc4fac79b3b 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_operations/_patch.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_operations/_patch.py @@ -1,15 +1,30 @@ # coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------- + """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +from ._operations import _ApiKeyClientOperationsMixin as Generated + + +class _ApiKeyClientOperationsMixin(Generated): + + def patch_added_operation(self) -> bool: + """This is a placeholder for the operation that was added in the patch. + + This method is a no-op and does not perform any action. + + :return: Always returns True. + :rtype: bool + """ + return True + + +__all__: List[str] = [ + "_ApiKeyClientOperationsMixin" +] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py index 8bcb627aa47..fc4fac79b3b 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py @@ -1,15 +1,30 @@ # coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------- + """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +from ._operations import _ApiKeyClientOperationsMixin as Generated + + +class _ApiKeyClientOperationsMixin(Generated): + + def patch_added_operation(self) -> bool: + """This is a placeholder for the operation that was added in the patch. + + This method is a no-op and does not perform any action. + + :return: Always returns True. + :rtype: bool + """ + return True + + +__all__: List[str] = [ + "_ApiKeyClientOperationsMixin" +] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_patch.py b/packages/typespec-python/test/generic_mock_api_tests/test_patch.py new file mode 100644 index 00000000000..fc92290a712 --- /dev/null +++ b/packages/typespec-python/test/generic_mock_api_tests/test_patch.py @@ -0,0 +1,12 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + + +def test_patch_mixin_operation_group_in_operations_folder(key_credential): + from authentication.apikey import ApiKeyClient, aio + + assert hasattr(ApiKeyClient(key_credential), "patch_added_operation") + assert hasattr(aio.ApiKeyClient(key_credential), "patch_added_operation") diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_operations/_patch.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_operations/_patch.py index 894b28a174c..fc4fac79b3b 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_operations/_patch.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_operations/_patch.py @@ -6,7 +6,25 @@ """ from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +from ._operations import _ApiKeyClientOperationsMixin as Generated + + +class _ApiKeyClientOperationsMixin(Generated): + + def patch_added_operation(self) -> bool: + """This is a placeholder for the operation that was added in the patch. + + This method is a no-op and does not perform any action. + + :return: Always returns True. + :rtype: bool + """ + return True + + +__all__: List[str] = [ + "_ApiKeyClientOperationsMixin" +] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py index 894b28a174c..fc4fac79b3b 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/aio/_operations/_patch.py @@ -6,7 +6,25 @@ """ from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +from ._operations import _ApiKeyClientOperationsMixin as Generated + + +class _ApiKeyClientOperationsMixin(Generated): + + def patch_added_operation(self) -> bool: + """This is a placeholder for the operation that was added in the patch. + + This method is a no-op and does not perform any action. + + :return: Always returns True. + :rtype: bool + """ + return True + + +__all__: List[str] = [ + "_ApiKeyClientOperationsMixin" +] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24d1c0c02ee..3f73348d8cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,8 +60,8 @@ importers: specifier: ~1.0.2 version: 1.0.2 '@typespec/http-client-python': - specifier: ~0.14.1-dev.2 - version: 0.14.1-dev.2(iurth4uuk4s6znzuuc7ncenk2q) + specifier: ~0.14.1 + version: 0.14.1(iurth4uuk4s6znzuuc7ncenk2q) fs-extra: specifier: ~11.2.0 version: 11.2.0 @@ -82,8 +82,8 @@ importers: packages/typespec-python: dependencies: '@typespec/http-client-python': - specifier: ~0.14.1-dev.2 - version: 0.14.1-dev.2(iurth4uuk4s6znzuuc7ncenk2q) + specifier: ~0.14.1 + version: 0.14.1(iurth4uuk4s6znzuuc7ncenk2q) fs-extra: specifier: ~11.2.0 version: 11.2.0 @@ -1668,8 +1668,8 @@ packages: peerDependencies: '@typespec/compiler': ^1.2.1 - '@typespec/http-client-python@0.14.1-dev.2': - resolution: {integrity: sha512-omocYPyiMA/rkUD7qdcZk24UUQOcWBQgqiKH6nxwOrV9jZMVlt49HWeZS+koVJku0Y6q9lot1NaGsWuxto1yEg==} + '@typespec/http-client-python@0.14.1': + resolution: {integrity: sha512-XCBstfoOFPdAZ9479hb6vwtA1h+mkROjo3bBtCh5ITcy9gECvQK6vOLkjrGywmsaBBFRJhHrUI94MxWFAfJwOQ==} engines: {node: '>=20.0.0'} peerDependencies: '@azure-tools/typespec-autorest': '>=0.58.0 <1.0.0' @@ -6421,7 +6421,7 @@ snapshots: dependencies: '@typespec/compiler': 1.2.1(@types/node@22.13.17) - '@typespec/http-client-python@0.14.1-dev.2(iurth4uuk4s6znzuuc7ncenk2q)': + '@typespec/http-client-python@0.14.1(iurth4uuk4s6znzuuc7ncenk2q)': dependencies: '@azure-tools/typespec-autorest': 0.58.0(vddu6w2yloigenmssnpyjivoim) '@azure-tools/typespec-azure-core': 0.58.0(@typespec/compiler@1.2.1(@types/node@22.13.17))(@typespec/http@1.2.1(@typespec/compiler@1.2.1(@types/node@22.13.17))(@typespec/streams@0.72.1(@typespec/compiler@1.2.1(@types/node@22.13.17))))(@typespec/rest@0.72.1(@typespec/compiler@1.2.1(@types/node@22.13.17))(@typespec/http@1.2.1(@typespec/compiler@1.2.1(@types/node@22.13.17))(@typespec/streams@0.72.1(@typespec/compiler@1.2.1(@types/node@22.13.17)))))