Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: fix
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

fix import for _validation.py/_types.py when "generation-subdir" is configured
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ celerybeat-schedule
# Environments
.env
.venv
.venv-*
env/
venv*/
ENV/
Expand Down
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyMzY4MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyODg2My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "^4.21.0"
Expand Down
70 changes: 66 additions & 4 deletions packages/typespec-python/eng/scripts/regenerate-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,19 @@ export const BASE_EMITTER_OPTIONS: Record<string, Record<string, string> | Recor
"package-name": "typetest-model-singlediscriminator",
"namespace": "typetest.model.singlediscriminator",
},
"type/model/inheritance/recursive": {
"package-name": "typetest-model-recursive",
"namespace": "typetest.model.recursive",
},
"type/model/inheritance/recursive": [
{
"package-name": "typetest-model-recursive",
"namespace": "typetest.model.recursive",
},
{
// basic test for configuration "generation-subdir"
"package-name": "generation-subdir",
"namespace": "generation.subdir",
"generation-subdir": "_generated",
"clear-output-folder": "true",
},
],
"type/model/usage": {
"package-name": "typetest-model-usage",
"namespace": "typetest.model.usage",
Expand Down Expand Up @@ -262,6 +271,18 @@ export const BASE_EMITTER_OPTIONS: Record<string, Record<string, string> | Recor
"package-name": "specs-documentation",
"namespace": "specs.documentation",
},
"versioning/added": [
{
"package-name": "versioning-added",
"namespace": "versioning.added",
},
// check whether import of _validation.py/_types.py works when "generation-subdir" is configured
{
"package-name": "generation-subdir2",
"namespace": "generation.subdir2",
"generation-subdir": "_generated",
},
],
};

// ---- Shared interfaces ----
Expand Down Expand Up @@ -453,3 +474,44 @@ export async function regenerate(flags: RegenerateFlagsInput, config: Regenerate
await runTaskPool(tasks, poolLimit);
}
}

// Preprocess: create files that should be deleted after regeneration (for testing)
export async function preprocess(flavor: string, generatedFolder: string): Promise<void> {
if (flavor === "azure") {
// Use tests/generated/<flavor>/<package> structure (same as output)
const testsGeneratedDir = resolve(generatedFolder, "../tests/generated/azure");

const DELETE_CONTENT = "# This file is to be deleted after regeneration";
const DELETE_FILE = "to_be_deleted.py";
const entries: { folder: string[]; file: string; content: string }[] = [
{
folder: ["authentication-api-key", "authentication", "apikey", "_operations"],
file: DELETE_FILE,
content: DELETE_CONTENT,
},
{
folder: ["generation-subdir", "generation", "subdir", "_generated"],
file: DELETE_FILE,
content: DELETE_CONTENT,
},
{
folder: ["generation-subdir", "generated_tests"],
file: DELETE_FILE,
content: DELETE_CONTENT,
},
{
folder: ["generation-subdir", "generation", "subdir"],
file: "to_be_kept.py",
content: "# This file is to be kept after regeneration",
},
];

await Promise.all(
entries.map(async ({ folder, file, content }) => {
const targetFolder = join(testsGeneratedDir, ...folder);
await promises.mkdir(targetFolder, { recursive: true });
await promises.writeFile(join(targetFolder, file), content);
}),
);
}
}
50 changes: 4 additions & 46 deletions packages/typespec-python/eng/scripts/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { compile, NodeHost } from "@typespec/compiler";
import { promises, rmSync } from "fs";
import { rmSync } from "fs";
import { platform } from "os";
import { dirname, join, relative, resolve } from "path";
import pc from "picocolors";
Expand All @@ -17,6 +17,7 @@ import {
BASE_AZURE_EMITTER_OPTIONS,
BASE_EMITTER_OPTIONS,
getSubdirectories,
preprocess,
SpecialFlags,
toPosix,
type RegenerateFlags,
Expand Down Expand Up @@ -76,6 +77,7 @@ const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
const PLUGIN_DIR = resolve(SCRIPT_DIR, "../../");
const AZURE_HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@azure-tools/azure-http-specs/specs");
const HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@typespec/http-specs/specs");
const GENERATED_FOLDER = resolve(PLUGIN_DIR, "generator");
const EMITTER_NAME = "@azure-tools/typespec-python";

// Emitter options
Expand All @@ -85,18 +87,6 @@ const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<stri

const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
...BASE_EMITTER_OPTIONS,
"type/model/inheritance/recursive": [
{
"package-name": "typetest-model-recursive",
"namespace": "typetest.model.recursive",
},
{
"package-name": "generation-subdir",
"namespace": "generation.subdir",
"generation-subdir": "_generated",
"clear-output-folder": "true",
},
],
"client/structure/client-operation-group": {
"package-name": "client-structure-clientoperationgroup",
"namespace": "client.structure.clientoperationgroup",
Expand Down Expand Up @@ -259,38 +249,6 @@ async function runParallel(groups: TaskGroup[], maxJobs: number): Promise<Map<st
return results;
}

// Preprocess: create files that should be deleted after regeneration (for testing)
async function preprocess(flavor: string): Promise<void> {
if (flavor === "azure") {
const generalParts = [PLUGIN_DIR, "tests", "generated", "azure"];
await promises.writeFile(
join(
...generalParts,
"authentication-api-key",
"authentication",
"apikey",
"_operations",
"to_be_deleted.py",
),
"# This file is to be deleted after regeneration",
);

const folderParts = [...generalParts, "generation-subdir"];
await promises.writeFile(
join(...folderParts, "generation", "subdir", "_generated", "to_be_deleted.py"),
"# This file is to be deleted after regeneration",
);
await promises.writeFile(
join(...folderParts, "generated_tests", "to_be_deleted.py"),
"# This file is to be kept after regeneration",
);
await promises.writeFile(
join(...folderParts, "generation", "subdir", "to_be_kept.py"),
"# This file is to be kept after regeneration",
);
}
}

async function regenerateFlavor(
flavor: string,
name: string | undefined,
Expand All @@ -304,7 +262,7 @@ async function regenerateFlavor(
const flags: RegenerateFlags = { flavor, debug, name };

// Preprocess
await preprocess(flavor);
await preprocess(flavor, GENERATED_FOLDER);

// Collect specs
const azureSpecs = flavor === "azure" ? await getSubdirectories(AZURE_HTTP_SPECS, flags) : [];
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@typespec/xml": ">=0.81.0 <1.0.0"
},
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyMzY4MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyODg2My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"fs-extra": "~11.2.0",
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
Expand Down
16 changes: 14 additions & 2 deletions packages/typespec-python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,21 @@ def start_server_process():
node_bin = str(ROOT / "node_modules" / ".bin")
env["PATH"] = f"{node_bin}{os.pathsep}{env.get('PATH', '')}"

# Suppress server stdout/stderr to avoid confusing "Request validation failed" warnings
# in test output. Server readiness is validated via HTTP polling in wait_for_server().
if os.name == "nt":
return subprocess.Popen(cmd, shell=True, cwd=str(cwd), env=env)
return subprocess.Popen(cmd, shell=True, cwd=str(cwd), env=env, preexec_fn=os.setsid)
return subprocess.Popen(
cmd, shell=True, cwd=str(cwd), env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
return subprocess.Popen(
cmd,
shell=True,
cwd=str(cwd),
env=env,
preexec_fn=os.setsid,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)


def terminate_server_process(process):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release History

## 1.0.0b1 (1970-01-01)

### Other Changes

- Initial version
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include *.md
include LICENSE
include generation/subdir2/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include generation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generation Subdir2 client library for Python
<!-- write necessary description of service -->

## Getting started

### Install the package

```bash
python -m pip install generation-subdir2
```

#### Prequisites

- Python 3.9 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing Generation Subdir2 instance.


## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
additional questions or comments.

<!-- LINKS -->
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
[azure_identity_pip]: https://pypi.org/project/azure-identity/
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[pip]: https://pypi.org/project/pip/
[azure_sub]: https://azure.microsoft.com/free/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"apiVersion": "v2",
"apiVersions": {
"Versioning.Added": "v2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"CrossLanguagePackageId": "Versioning.Added",
"CrossLanguageDefinitionId": {
"generation.subdir2.models.ModelV1": "Versioning.Added.ModelV1",
"generation.subdir2.models.ModelV2": "Versioning.Added.ModelV2",
"generation.subdir2.models.Versions": "Versioning.Added.Versions",
"generation.subdir2.models.EnumV2": "Versioning.Added.EnumV2",
"generation.subdir2.models.EnumV1": "Versioning.Added.EnumV1",
"generation.subdir2.operations.InterfaceV2Operations.v2_in_interface": "Versioning.Added.InterfaceV2.v2InInterface",
"generation.subdir2.aio.operations.InterfaceV2Operations.v2_in_interface": "Versioning.Added.InterfaceV2.v2InInterface",
"generation.subdir2.AddedClient.v1": "Versioning.Added.v1",
"generation.subdir2.aio.AddedClient.v1": "Versioning.Added.v1",
"generation.subdir2.AddedClient.v2": "Versioning.Added.v2",
"generation.subdir2.aio.AddedClient.v2": "Versioning.Added.v2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e ../../../eng/tools/azure-sdk-tools
../../core/azure-core
aiohttp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import os
import pytest
from dotenv import load_dotenv
from devtools_testutils import (
test_proxy,
add_general_regex_sanitizer,
add_body_key_sanitizer,
add_header_regex_sanitizer,
)

load_dotenv()


# For security, please avoid record sensitive identity information in recordings
@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
added_subscription_id = os.environ.get("ADDED_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
added_tenant_id = os.environ.get("ADDED_TENANT_ID", "00000000-0000-0000-0000-000000000000")
added_client_id = os.environ.get("ADDED_CLIENT_ID", "00000000-0000-0000-0000-000000000000")
added_client_secret = os.environ.get("ADDED_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=added_subscription_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=added_tenant_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=added_client_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=added_client_secret, value="00000000-0000-0000-0000-000000000000")

add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
add_header_regex_sanitizer(key="Cookie", value="cookie;")
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
Loading
Loading