Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] migrate cadl-ranch to spector #5389

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -56,7 +56,7 @@ try {
Write-Host 'tox tests passed'
}
catch {
Write-Error "Cadl ranch tests failed: $_"
Write-Error "Spector tests failed: $_"
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const exec = promisify(execCallback);
const PLUGIN_DIR = argv.values.pluginDir
? resolve(argv.values.pluginDir)
: resolve(fileURLToPath(import.meta.url), "../../../../");
const CADL_RANCH_DIR = resolve(PLUGIN_DIR, "node_modules/@azure-tools/cadl-ranch-specs/http");
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 = argv.values.generatedFolder
? resolve(argv.values.generatedFolder)
: resolve(PLUGIN_DIR, "generator");
Expand Down Expand Up @@ -128,7 +129,8 @@ function toPosix(dir: string): string {
}

function getEmitterOption(spec: string): Record<string, string>[] {
const relativeSpec = toPosix(relative(CADL_RANCH_DIR, spec));
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
const relativeSpec = toPosix(relative(specDir, spec));
const key = relativeSpec.includes("resiliency/srv-driven/old.tsp")
? relativeSpec
: dirname(relativeSpec);
Expand Down Expand Up @@ -224,7 +226,8 @@ async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promi
}

function defaultPackageName(spec: string): string {
return toPosix(relative(CADL_RANCH_DIR, dirname(spec)))
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
return toPosix(relative(specDir, dirname(spec)))
.replace(/\//g, "-")
.toLowerCase();
}
Expand Down Expand Up @@ -284,8 +287,9 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
await regenerate({ ...flags, flavor: "unbranded" });
} else {
const flagsResolved = { debug: false, flavor: flags.flavor, ...flags };
const CADL_RANCH_DIR = resolve(PLUGIN_DIR, "node_modules/@azure-tools/cadl-ranch-specs/http");
const subdirectories = await getSubdirectories(CADL_RANCH_DIR, flagsResolved);
const subdirectoriesForAzure = await getSubdirectories(AZURE_HTTP_SPECS, flagsResolved);
const subdirectoriesForNonAzure = await getSubdirectories(HTTP_SPECS, flagsResolved);
const subdirectories = [...subdirectoriesForAzure, ...subdirectoriesForNonAzure];
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
_getCmdList(subdirectory, flagsResolved),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def client():
yield client


# ========== test for cadl-ranch ==========
# ========== test for spector ==========


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# --------------------------------------------------------------------------
import pytest
from payload.pageable.aio import PageableClient
from specs.azure.payload.pageable.aio import PageableClient


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http --coverageFile ./cadl-ranch-coverage-python-standard.json"
azure_http_path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/azure-http-specs")
http_path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@typespec/http-specs")
os.chdir(azure_http_path.resolve())
cmd = f"tsp-spector serve ./specs {(http_path / 'specs').resolve()}"
if os.name == "nt":
return subprocess.Popen(cmd, shell=True)
return subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
Expand All @@ -30,7 +31,7 @@ def terminate_server_process(process):

@pytest.fixture(scope="session", autouse=True)
def testserver():
"""Start cadl ranch mock api tests"""
"""Start spector ranch mock api tests"""
server = start_server_process()
yield
terminate_server_process(server)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def client():
yield client


# ========== test for cadl-ranch ==========
# ========== test for spector ==========


def test_put_flatten_model(client: FlattenPropertyClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# --------------------------------------------------------------------------
import pytest
from payload.pageable import PageableClient
from specs.azure.payload.pageable import PageableClient


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mypy==1.13.0
-e ./generated/azure-example-basic
-e ./generated/azure-resource-manager-common-properties
-e ./generated/azure-resource-manager-resources
-e ./generated/azure-payload-pageable

# common test case
-e ./generated/authentication-api-key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http"
azure_http_path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@azure-tools/azure-http-specs")
http_path = Path(os.path.dirname(__file__)) / Path("../../../node_modules/@typespec/http-specs")
os.chdir(azure_http_path.resolve())
cmd = f"tsp-spector serve ./specs {(http_path / 'specs').resolve()}"
if os.name == "nt":
return subprocess.Popen(cmd, shell=True)
return subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
Expand All @@ -32,7 +33,7 @@ def terminate_server_process(process):

@pytest.fixture(scope="session", autouse=True)
def testserver():
"""Start cadl ranch mock api tests"""
"""Start spector mock api tests"""
server = start_server_process()
yield
terminate_server_process(server)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@


def start_server_process():
path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/cadl-ranch-specs")
os.chdir(path.resolve())
cmd = "cadl-ranch serve ./http"
azure_http_path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@azure-tools/azure-http-specs")
http_path = Path(os.path.dirname(__file__)) / Path("../../../../node_modules/@typespec/http-specs")
os.chdir(azure_http_path.resolve())
cmd = f"tsp-spector serve ./specs {(http_path / 'specs').resolve()}"
if os.name == "nt":
return subprocess.Popen(cmd, shell=True)
return subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
Expand All @@ -29,7 +30,7 @@ def terminate_server_process(process):

@pytest.fixture(scope="session", autouse=True)
def testserver():
"""Start cadl ranch mock api tests"""
"""Start spector mock api tests"""
server = start_server_process()
yield
terminate_server_process(server)
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ def check_sensitive_word(folder: Path, word: str) -> str:
def test_sensitive_word():
check_folder = (Path(os.path.dirname(__file__)) / "../generated").resolve()
assert [] == check_sensitive_word(check_folder, "azure")
# after update cadl-ranch, it shall also equal to []
# after update spector, it shall also equal to []
assert ["authentication-oauth2", "authentication-union"] == check_sensitive_word(check_folder, "microsoft")
Loading
Loading