From 1b336c834e667540c016fe23f8f3c2be4833a187 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 21 Mar 2023 16:56:05 -0700 Subject: [PATCH 1/3] switch tooling over to typespec --- .gitignore | 2 +- eng/common/scripts/Cadl-Project-Generate.ps1 | 101 -------------- eng/common/scripts/Cadl-Project-Sync.ps1 | 127 ------------------ eng/emitter-package.json | 12 +- eng/scripts/Language-Settings.ps1 | 64 ++++----- .../README.md | 2 +- .../main.py | 4 +- .../packaging_tools/generate_utils.py | 28 ++-- .../packaging_tools/sdk_generator.py | 32 ++--- 9 files changed, 67 insertions(+), 305 deletions(-) delete mode 100644 eng/common/scripts/Cadl-Project-Generate.ps1 delete mode 100644 eng/common/scripts/Cadl-Project-Sync.ps1 rename scripts/{cadl_refresh_sdk => typespec_refresh_sdk}/README.md (75%) rename scripts/{cadl_refresh_sdk => typespec_refresh_sdk}/main.py (77%) diff --git a/.gitignore b/.gitignore index 20d4e6c71e79..6dd4c847a340 100644 --- a/.gitignore +++ b/.gitignore @@ -147,4 +147,4 @@ sdk/cosmos/azure-cosmos/test/test_config.py *_python.json # temporary folder to refresh SDK with cadl -TempCadlFiles/ \ No newline at end of file +TempTypeSpecFiles/ \ No newline at end of file diff --git a/eng/common/scripts/Cadl-Project-Generate.ps1 b/eng/common/scripts/Cadl-Project-Generate.ps1 deleted file mode 100644 index 3e7ee781b053..000000000000 --- a/eng/common/scripts/Cadl-Project-Generate.ps1 +++ /dev/null @@ -1,101 +0,0 @@ -# For details see https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/Cadl-Project-Scripts.md - -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [ValidateNotNullOrEmpty()] - [string] $ProjectDirectory, - [Parameter(Position=1)] - [string] $CadlAdditionalOptions ## addtional cadl emitter options, separated by semicolon if more than one, e.g. option1=value1;option2=value2 -) - -$ErrorActionPreference = "Stop" -. $PSScriptRoot/Helpers/PSModule-Helpers.ps1 -. $PSScriptRoot/common.ps1 -Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module - -function NpmInstallForProject([string]$workingDirectory) { - Push-Location $workingDirectory - try { - $currentDur = Resolve-Path "." - Write-Host "Generating from $currentDur" - - if (Test-Path "package.json") { - Remove-Item -Path "package.json" -Force - } - - if (Test-Path ".npmrc") { - Remove-Item -Path ".npmrc" -Force - } - - if (Test-Path "node_modules") { - Remove-Item -Path "node_modules" -Force -Recurse - } - - if (Test-Path "package-lock.json") { - Remove-Item -Path "package-lock.json" -Force - } - - #default to root/eng/emitter-package.json but you can override by writing - #Get-${Language}-EmitterPackageJsonPath in your Language-Settings.ps1 - $replacementPackageJson = "$PSScriptRoot/../../emitter-package.json" - if (Test-Path "Function:$GetEmitterPackageJsonPathFn") { - $replacementPackageJson = &$GetEmitterPackageJsonPathFn - } - - Write-Host("Copying package.json from $replacementPackageJson") - Copy-Item -Path $replacementPackageJson -Destination "package.json" -Force - npm install --no-lock-file - if ($LASTEXITCODE) { exit $LASTEXITCODE } - } - finally { - Pop-Location - } -} - -$resolvedProjectDirectory = Resolve-Path $ProjectDirectory -$emitterName = &$GetEmitterNameFn -$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/cadl-location.yaml" - -Write-Host "Reading configuration from $cadlConfigurationFile" -$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml - -$specSubDirectory = $configuration["directory"] -$innerFolder = Split-Path $specSubDirectory -Leaf - -$tempFolder = "$ProjectDirectory/TempCadlFiles" -$npmWorkingDir = Resolve-Path $tempFolder/$innerFolder -$mainCadlFile = If (Test-Path "$npmWorkingDir/client.cadl") { Resolve-Path "$npmWorkingDir/client.cadl" } Else { Resolve-Path "$npmWorkingDir/main.cadl"} - -try { - Push-Location $npmWorkingDir - NpmInstallForProject $npmWorkingDir - - if ($LASTEXITCODE) { exit $LASTEXITCODE } - - if (Test-Path "Function:$GetEmitterAdditionalOptionsFn") { - $emitterAdditionalOptions = &$GetEmitterAdditionalOptionsFn $resolvedProjectDirectory - if ($emitterAdditionalOptions.Length -gt 0) { - $emitterAdditionalOptions = " $emitterAdditionalOptions" - } - } - $cadlCompileCommand = "npx cadl compile $mainCadlFile --emit $emitterName$emitterAdditionalOptions" - if ($CadlAdditionalOptions) { - $options = $CadlAdditionalOptions.Split(";"); - foreach ($option in $options) { - $cadlCompileCommand += " --option $emitterName.$option" - } - } - Write-Host($cadlCompileCommand) - Invoke-Expression $cadlCompileCommand - - if ($LASTEXITCODE) { exit $LASTEXITCODE } -} -finally { - Pop-Location -} - -$shouldCleanUp = $configuration["cleanup"] ?? $true -if ($shouldCleanUp) { - Remove-Item $tempFolder -Recurse -Force -} \ No newline at end of file diff --git a/eng/common/scripts/Cadl-Project-Sync.ps1 b/eng/common/scripts/Cadl-Project-Sync.ps1 deleted file mode 100644 index c6e8cf5ce531..000000000000 --- a/eng/common/scripts/Cadl-Project-Sync.ps1 +++ /dev/null @@ -1,127 +0,0 @@ -# For details see https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/Cadl-Project-Scripts.md - -[CmdletBinding()] -param ( - [Parameter(Position=0)] - [ValidateNotNullOrEmpty()] - [string] $ProjectDirectory -) - -$ErrorActionPreference = "Stop" -. $PSScriptRoot/Helpers/PSModule-Helpers.ps1 -Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module -$sparseCheckoutFile = ".git/info/sparse-checkout" - -function AddSparseCheckoutPath([string]$subDirectory) { - if (!(Test-Path $sparseCheckoutFile) -or !((Get-Content $sparseCheckoutFile).Contains($subDirectory))) { - Write-Output $subDirectory >> .git/info/sparse-checkout - } -} - -function CopySpecToProjectIfNeeded([string]$specCloneRoot, [string]$mainSpecDir, [string]$dest, [string[]]$specAdditionalSubDirectories) { - $source = "$specCloneRoot/$mainSpecDir" - Copy-Item -Path $source -Destination $dest -Recurse -Force - Write-Host "Copying spec from $source to $dest" - - foreach ($additionalDir in $specAdditionalSubDirectories) { - $source = "$specCloneRoot/$additionalDir" - Write-Host "Copying spec from $source to $dest" - Copy-Item -Path $source -Destination $dest -Recurse -Force - } -} - -function UpdateSparseCheckoutFile([string]$mainSpecDir, [string[]]$specAdditionalSubDirectories) { - AddSparseCheckoutPath $mainSpecDir - foreach ($subDir in $specAdditionalSubDirectories) { - AddSparseCheckoutPath $subDir - } -} - -function GetGitRemoteValue([string]$repo) { - Push-Location $ProjectDirectory - $result = "" - try { - $gitRemotes = (git remote -v) - foreach ($remote in $gitRemotes) { - if ($remote.StartsWith("origin")) { - if ($remote -match 'https://github.com/\S+') { - $result = "https://github.com/$repo.git" - break - } elseif ($remote -match "git@github.com:\S+"){ - $result = "git@github.com:$repo.git" - break - } else { - throw "Unknown git remote format found: $remote" - } - } - } - } - finally { - Pop-Location - } - - return $result -} - -function InitializeSparseGitClone([string]$repo) { - git clone --no-checkout --filter=tree:0 $repo . - if ($LASTEXITCODE) { exit $LASTEXITCODE } - git sparse-checkout init - if ($LASTEXITCODE) { exit $LASTEXITCODE } - Remove-Item $sparseCheckoutFile -Force -} - -function GetSpecCloneDir([string]$projectName) { - Push-Location $ProjectDirectory - try { - $root = git rev-parse --show-toplevel - } - finally { - Pop-Location - } - - $sparseSpecCloneDir = "$root/../sparse-spec/$projectName" - New-Item $sparseSpecCloneDir -Type Directory -Force | Out-Null - $createResult = Resolve-Path $sparseSpecCloneDir - return $createResult -} - -$cadlConfigurationFile = Resolve-Path "$ProjectDirectory/cadl-location.yaml" -Write-Host "Reading configuration from $cadlConfigurationFile" -$configuration = Get-Content -Path $cadlConfigurationFile -Raw | ConvertFrom-Yaml - -$pieces = $cadlConfigurationFile.Path.Replace("\","/").Split("/") -$projectName = $pieces[$pieces.Count - 2] - -$specSubDirectory = $configuration["directory"] - -if ( $configuration["repo"] -and $configuration["commit"]) { - $specCloneDir = GetSpecCloneDir $projectName - $gitRemoteValue = GetGitRemoteValue $configuration["repo"] - - Write-Host "Setting up sparse clone for $projectName at $specCloneDir" - - Push-Location $specCloneDir.Path - try { - if (!(Test-Path ".git")) { - InitializeSparseGitClone $gitRemoteValue - UpdateSparseCheckoutFile $specSubDirectory $configuration["additionalDirectories"] - } - git checkout $configuration["commit"] - if ($LASTEXITCODE) { exit $LASTEXITCODE } - } - finally { - Pop-Location - } -} elseif ( $configuration["spec-root-dir"] ) { - $specCloneDir = $configuration["spec-root-dir"] -} - - -$tempCadlDir = "$ProjectDirectory/TempCadlFiles" -New-Item $tempCadlDir -Type Directory -Force | Out-Null -CopySpecToProjectIfNeeded ` - -specCloneRoot $specCloneDir ` - -mainSpecDir $specSubDirectory ` - -dest $tempCadlDir ` - -specAdditionalSubDirectories $configuration["additionalDirectories"] diff --git a/eng/emitter-package.json b/eng/emitter-package.json index dff2777dea78..eb88b644e45d 100644 --- a/eng/emitter-package.json +++ b/eng/emitter-package.json @@ -1,16 +1,6 @@ { "main": "dist/src/index.js", "dependencies": { - "@azure-tools/cadl-python": "0.4.25", - "@autorest/python": "6.4.0", - "@azure-tools/cadl-autorest": "0.26.0", - "@azure-tools/cadl-azure-core": "0.26.0", - "@azure-tools/cadl-dpg": "0.26.0", - "@azure-tools/cadl-azure-resource-manager": "0.26.0", - "@cadl-lang/compiler": "0.40.0", - "@cadl-lang/eslint-config-cadl": "0.5.0", - "@cadl-lang/openapi": "0.40.0", - "@cadl-lang/rest": "0.40.0", - "@cadl-lang/versioning": "0.40.0" + "@azure-tools/typespec-python": "0.7.0" } } diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 34c7f5de7ad2..8c1baf5fa534 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -169,14 +169,14 @@ function ValidatePackage { Param( [Parameter(Mandatory=$true)] - [string]$packageName, + [string]$packageName, [Parameter(Mandatory=$true)] [string]$packageVersion, [Parameter(Mandatory=$false)] [string]$PackageSourceOverride, [Parameter(Mandatory=$false)] [string]$DocValidationImageId - ) + ) $installValidationFolder = Join-Path ([System.IO.Path]::GetTempPath()) "validation" if (!(Test-Path $installValidationFolder)) { New-Item -ItemType Directory -Force -Path $installValidationFolder | Out-Null @@ -187,7 +187,7 @@ function ValidatePackage if (!$DocValidationImageId) { Write-Host "Validating using pip command directly on $packageName." FallbackValidation -packageName "$packageName" -packageVersion "$packageVersion" -workingDirectory $installValidationFolder -PackageSourceOverride $PackageSourceOverride - } + } else { Write-Host "Validating using $DocValidationImageId on $packageName." DockerValidation -packageName "$packageName" -packageVersion "$packageVersion" ` @@ -197,7 +197,7 @@ function ValidatePackage function DockerValidation{ Param( [Parameter(Mandatory=$true)] - [string]$packageName, + [string]$packageName, [Parameter(Mandatory=$true)] [string]$packageVersion, [Parameter(Mandatory=$false)] @@ -206,11 +206,11 @@ function DockerValidation{ [string]$DocValidationImageId, [Parameter(Mandatory=$false)] [string]$workingDirectory - ) + ) if ($PackageSourceOverride) { Write-Host "docker run -v ${workingDirectory}:/workdir/out -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -e EXTRA_INDEX_URL=$PackageSourceOverride -t $DocValidationImageId" $commandLine = docker run -v "${workingDirectory}:/workdir/out" -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion ` - -e EXTRA_INDEX_URL=$PackageSourceOverride -t $DocValidationImageId 2>&1 + -e EXTRA_INDEX_URL=$PackageSourceOverride -t $DocValidationImageId 2>&1 } else { Write-Host "docker run -v ${workingDirectory}:/workdir/out -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -t $DocValidationImageId" @@ -218,15 +218,15 @@ function DockerValidation{ -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -t $DocValidationImageId 2>&1 } # The docker exit codes: https://docs.docker.com/engine/reference/run/#exit-status - # If the docker failed because of docker itself instead of the application, - # we should skip the validation and keep the packages. - - if ($LASTEXITCODE -eq 125 -Or $LASTEXITCODE -eq 126 -Or $LASTEXITCODE -eq 127) { + # If the docker failed because of docker itself instead of the application, + # we should skip the validation and keep the packages. + + if ($LASTEXITCODE -eq 125 -Or $LASTEXITCODE -eq 126 -Or $LASTEXITCODE -eq 127) { $commandLine | ForEach-Object { Write-Debug $_ } LogWarning "The `docker` command does not work with exit code $LASTEXITCODE. Fall back to npm install $packageName directly." FallbackValidation -packageName "$packageName" -packageVersion "$packageVersion" -workingDirectory $workingDirectory -PackageSourceOverride $PackageSourceOverride } - elseif ($LASTEXITCODE -ne 0) { + elseif ($LASTEXITCODE -ne 0) { $commandLine | ForEach-Object { Write-Debug $_ } LogWarning "Package $packageName ref docs validation failed." return $false @@ -238,14 +238,14 @@ function FallbackValidation { Param( [Parameter(Mandatory=$true)] - [string]$packageName, + [string]$packageName, [Parameter(Mandatory=$true)] [string]$packageVersion, [Parameter(Mandatory=$true)] [string]$workingDirectory, [Parameter(Mandatory=$false)] [string]$PackageSourceOverride - ) + ) $installTargetFolder = Join-Path $workingDirectory $packageName New-Item -ItemType Directory -Force -Path $installTargetFolder | Out-Null $packageExpression = "$packageName$packageVersion" @@ -334,13 +334,13 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour $outputPackages = @() foreach ($package in $packageConfig.packages) { $packageName = $package.package_info.name - if (!$packageName) { + if (!$packageName) { Write-Host "Keeping package with no name: $($package.package_info)" $outputPackages += $package continue } - if ($package.package_info.install_type -ne 'pypi') { + if ($package.package_info.install_type -ne 'pypi') { Write-Host "Keeping package with install_type not 'pypi': $($package.package_info.name)" $outputPackages += $package continue @@ -359,19 +359,19 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour continue } - if ($matchingPublishedPackageArray.Count -gt 1) { + if ($matchingPublishedPackageArray.Count -gt 1) { LogWarning "Found more than one matching published package in metadata for $packageName; only updating first entry" } $matchingPublishedPackage = $matchingPublishedPackageArray[0] - if ($Mode -eq 'preview' -and !$matchingPublishedPackage.VersionPreview.Trim()) { + if ($Mode -eq 'preview' -and !$matchingPublishedPackage.VersionPreview.Trim()) { # If we are in preview mode and the package does not have a superseding - # preview version, remove the package from the list. + # preview version, remove the package from the list. Write-Host "Remove superseded preview package: $packageName" continue } - if ($Mode -eq 'latest' -and !$matchingPublishedPackage.VersionGA.Trim()) { + if ($Mode -eq 'latest' -and !$matchingPublishedPackage.VersionGA.Trim()) { LogWarning "Metadata is missing GA version for GA package $packageName. Keeping existing package." $outputPackages += $package continue @@ -379,7 +379,7 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour $packageVersion = "==$($matchingPublishedPackage.VersionGA)" if ($Mode -eq 'preview') { - if (!$matchingPublishedPackage.VersionPreview.Trim()) { + if (!$matchingPublishedPackage.VersionPreview.Trim()) { LogWarning "Metadata is missing preview version for preview package $packageName. Keeping existing package." $outputPackages += $package continue @@ -402,7 +402,7 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour -Name 'version' ` -Value $packageVersion ` -PassThru ` - -Force + -Force if ($PackageSourceOverride) { $package.package_info = Add-Member ` -InputObject $package.package_info ` @@ -410,7 +410,7 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour -Name 'extra_index_url' ` -Value $PackageSourceOverride ` -PassThru ` - -Force + -Force } } @@ -420,15 +420,15 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSour $outputPackagesHash = @{} foreach ($package in $outputPackages) { - # In some cases there is no $package.package_info.name, only hash if the + # In some cases there is no $package.package_info.name, only hash if the # name is set. - if ($package.package_info.name) { + if ($package.package_info.name) { $outputPackagesHash[$package.package_info.name] = $true } } - $remainingPackages = @() - if ($Mode -eq 'preview') { + $remainingPackages = @() + if ($Mode -eq 'preview') { $remainingPackages = $DocsMetadata.Where({ $_.VersionPreview.Trim() -and !$outputPackagesHash.ContainsKey($_.Package) }) @@ -536,7 +536,7 @@ function GetExistingPackageVersions ($PackageName, $GroupId=$null) } catch { - if ($_.Exception.Response.StatusCode -ne 404) + if ($_.Exception.Response.StatusCode -ne 404) { LogError "Failed to retrieve package versions for ${PackageName}. $($_.Exception.Message)" } @@ -544,15 +544,15 @@ function GetExistingPackageVersions ($PackageName, $GroupId=$null) } } -function Get-python-DocsMsMetadataForPackage($PackageInfo) { +function Get-python-DocsMsMetadataForPackage($PackageInfo) { $readmeName = $PackageInfo.Name.ToLower() Write-Host "Docs.ms Readme name: $($readmeName)" # Readme names (which are used in the URL) should not include redundant terms - # when viewed in URL form. For example: + # when viewed in URL form. For example: # https://docs.microsoft.com/en-us/dotnet/api/overview/azure/storage-blobs-readme # Note how the end of the URL doesn't look like: - # ".../azure/azure-storage-blobs-readme" + # ".../azure/azure-storage-blobs-readme" # This logic eliminates a preceeding "azure." in the readme filename. # "azure-storage-blobs" -> "storage-blobs" @@ -591,9 +591,9 @@ function Validate-Python-DocMsPackages ($PackageInfo, $PackageInfos, $PackageSou } function Get-python-EmitterName() { - return "@azure-tools/cadl-python" + return "@azure-tools/typespec-python" } function Get-python-EmitterAdditionalOptions([string]$projectDirectory) { - return "--option @azure-tools/cadl-python.emitter-output-dir=$projectDirectory/" + return "--option @azure-tools/typespec-python.emitter-output-dir=$projectDirectory/" } diff --git a/scripts/cadl_refresh_sdk/README.md b/scripts/typespec_refresh_sdk/README.md similarity index 75% rename from scripts/cadl_refresh_sdk/README.md rename to scripts/typespec_refresh_sdk/README.md index 75f38aaeba27..cb7ab550bcc8 100644 --- a/scripts/cadl_refresh_sdk/README.md +++ b/scripts/typespec_refresh_sdk/README.md @@ -12,5 +12,5 @@ The script is to refresh SDK code Step into root folder of this repo and run cmd with sdk folder: ```powershell -D:\azure-sdk-for-python> python .\scripts\cadl_refresh_sdk\main.py .\sdk\contosowidgetmanager\azure-contosowidgetmanager +D:\azure-sdk-for-python> python .\scripts\typespec_refresh_sdk\main.py .\sdk\contosowidgetmanager\azure-contosowidgetmanager ``` \ No newline at end of file diff --git a/scripts/cadl_refresh_sdk/main.py b/scripts/typespec_refresh_sdk/main.py similarity index 77% rename from scripts/cadl_refresh_sdk/main.py rename to scripts/typespec_refresh_sdk/main.py index 0ab4474779c3..0d930bd65fe0 100644 --- a/scripts/cadl_refresh_sdk/main.py +++ b/scripts/typespec_refresh_sdk/main.py @@ -6,11 +6,11 @@ def main(sdk_folder: str): # install package.json - script = Path("eng/common/scripts/Cadl-Project-Sync.ps1") + script = Path("eng/common/scripts/TypeSpec-Project-Sync.ps1") check_call(f"pwsh {script} {Path(sdk_folder)}", shell=True) # generate SDK - cmd = Path("eng/common/scripts/Cadl-Project-Generate.ps1") + cmd = Path("eng/common/scripts/TypeSpec-Project-Generate.ps1") check_call(f"pwsh {cmd} {Path(sdk_folder)}", shell=True) if __name__ == '__main__': diff --git a/tools/azure-sdk-tools/packaging_tools/generate_utils.py b/tools/azure-sdk-tools/packaging_tools/generate_utils.py index 740efb56e177..1baaf27e3876 100644 --- a/tools/azure-sdk-tools/packaging_tools/generate_utils.py +++ b/tools/azure-sdk-tools/packaging_tools/generate_utils.py @@ -34,8 +34,8 @@ def get_package_names(sdk_folder): return package_names -def init_new_service(package_name, folder_name, is_cadl = False): - if not is_cadl: +def init_new_service(package_name, folder_name, is_typespec = False): + if not is_typespec: setup = Path(folder_name, package_name, "setup.py") if not setup.exists(): check_call( @@ -90,7 +90,7 @@ def update_servicemetadata(sdk_folder, data, config, folder_name, package_name, "readme": input_readme, }) else: - metadata["cadl_src"] = input_readme + metadata["typespec_src"] = input_readme metadata.update(config) _LOGGER.info("Metadata json:\n {}".format(json.dumps(metadata, indent=2))) @@ -127,7 +127,7 @@ def update_servicemetadata(sdk_folder, data, config, folder_name, package_name, f.write("".join(includes)) -def update_cadl_location(sdk_folder, data, config, folder_name, package_name, input_readme): +def update_typespec_location(sdk_folder, data, config, folder_name, package_name, input_readme): if "meta" in config: return @@ -138,14 +138,14 @@ def update_cadl_location(sdk_folder, data, config, folder_name, package_name, in "cleanup": False, } - _LOGGER.info("cadl-location:\n {}".format(json.dumps(metadata, indent=2))) + _LOGGER.info("tsp-location:\n {}".format(json.dumps(metadata, indent=2))) package_folder = Path(sdk_folder) / folder_name / package_name if not package_folder.exists(): _LOGGER.info(f"Package folder doesn't exist: {package_folder}") return - metadata_file_path = package_folder / "cadl-location.yaml" + metadata_file_path = package_folder / "tsp-location.yaml" with open(metadata_file_path, "w") as writer: yaml.safe_dump(metadata, writer) _LOGGER.info(f"Saved metadata to {metadata_file_path}") @@ -361,7 +361,7 @@ def get_npm_package_version(package: str) -> Dict[any, any]: if "dependencies" not in data: _LOGGER.info(f"can not find {package}: {data}") return {} - + return data["dependencies"] def generate_ci(template_path: Path, folder_path: Path, package_name: str) -> None: @@ -383,22 +383,22 @@ def generate_ci(template_path: Path, folder_path: Path, package_name: str) -> No with open(ci, "w") as file_out: file_out.writelines(content) -def gen_cadl(cadl_relative_path: str, spec_folder: str) -> Dict[str, Any]: - cadl_python = "@azure-tools/cadl-python" +def gen_typespec(typespec_relative_path: str, spec_folder: str) -> Dict[str, Any]: + typespec_python = "@azure-tools/typespec-python" autorest_python = "@autorest/python" # npm install tool origin_path = os.getcwd() with open(Path("eng/emitter-package.json"), "r") as file_in: - cadl_python_dep = json.load(file_in) - os.chdir(Path(spec_folder) / cadl_relative_path) + typespec_python_dep = json.load(file_in) + os.chdir(Path(spec_folder) / typespec_relative_path) with open("package.json", "w") as file_out: - json.dump(cadl_python_dep, file_out) + json.dump(typespec_python_dep, file_out) check_call("npm install", shell=True) # generate code - cadl_file = "client.cadl" if Path("client.cadl").exists() else "." - check_call(f"npx cadl compile {cadl_file} --emit {cadl_python} --arg \"python-sdk-folder={origin_path}\" ", shell=True) + typespec_file = "client.tsp" if Path("client.tsp").exists() else "." + check_call(f"npx typespec compile {typespec_file} --emit {typespec_python} --arg \"python-sdk-folder={origin_path}\" ", shell=True) # get version of codegen used in generation npm_package_verstion = get_npm_package_version(autorest_python) diff --git a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py index af1f5bf544d6..dd708bf07edf 100644 --- a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py +++ b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py @@ -18,8 +18,8 @@ format_samples, gen_dpg, dpg_relative_folder, - gen_cadl, - update_cadl_location, + gen_typespec, + update_typespec_location, ) _LOGGER = logging.getLogger(__name__) @@ -40,7 +40,7 @@ def del_outdated_folder(readme: str): if all(p in line for p in pattern): # remove generated_samples sdk_folder = re.findall("[a-z]+/[a-z]+-[a-z]+-[a-z]+", line)[0] - sample_folder = Path(f"sdk/{sdk_folder}/generated_samples") + sample_folder = Path(f"sdk/{sdk_folder}/generated_samples") if sample_folder.exists(): shutil.rmtree(sample_folder) _LOGGER.info(f"remove sample folder: {sample_folder}") @@ -48,7 +48,7 @@ def del_outdated_folder(readme: str): _LOGGER.info(f"sample folder does not exist: {sample_folder}") # remove old generated SDK code sdk_folder = re.findall("[a-z]+/[a-z]+-[a-z]+-[a-z]+/[a-z]+/[a-z]+/[a-z]+", line)[0] - code_folder = Path(f"sdk/{sdk_folder}") + code_folder = Path(f"sdk/{sdk_folder}") if is_multiapi and code_folder.exists(): if any(item in str(sdk_folder) for item in special_service): for folder in code_folder.iterdir(): @@ -85,15 +85,15 @@ def main(generate_input, generate_output): readme_files = [input_readme] else: # ["specification/confidentialledger/ConfientialLedger"] - if isinstance(data["relatedCadlProjectFolder"], str): - readme_files = [data["relatedCadlProjectFolder"]] + if isinstance(data["relatedTypeSpecProjectFolder"], str): + readme_files = [data["relatedTypeSpecProjectFolder"]] else: - readme_files = data["relatedCadlProjectFolder"] - spec_word = "cadlProject" + readme_files = data["relatedTypeSpecProjectFolder"] + spec_word = "tspProject" for input_readme in readme_files: _LOGGER.info(f"[CODEGEN]({input_readme})codegen begin") - is_cadl = False + is_typespec = False if "resource-manager" in input_readme: relative_path_readme = str(Path(spec_folder, input_readme)) del_outdated_folder(relative_path_readme) @@ -109,8 +109,8 @@ def main(generate_input, generate_output): elif "data-plane" in input_readme: config = gen_dpg(input_readme, data.get("autorestConfig", ""), dpg_relative_folder(spec_folder)) else: - config = gen_cadl(input_readme, spec_folder) - is_cadl = True + config = gen_typespec(input_readme, spec_folder) + is_typespec = True package_names = get_package_names(sdk_folder) _LOGGER.info(f"[CODEGEN]({input_readme})codegen end. [(packages:{str(package_names)})]") @@ -132,7 +132,7 @@ def main(generate_input, generate_output): result[package_name][spec_word].append(input_readme) # Generate some necessary file for new service - init_new_service(package_name, folder_name, is_cadl) + init_new_service(package_name, folder_name, is_typespec) format_samples(sdk_code_path) # Update metadata @@ -148,10 +148,10 @@ def main(generate_input, generate_output): ) except Exception as e: _LOGGER.info(f"fail to update meta: {str(e)}") - - # update cadl-location.yaml + + # update tsp-location.yaml try: - update_cadl_location( + update_typespec_location( sdk_folder, data, config, @@ -160,7 +160,7 @@ def main(generate_input, generate_output): input_readme, ) except Exception as e: - _LOGGER.info(f"fail to update cadl-location: {str(e)}") + _LOGGER.info(f"fail to update tsp-location: {str(e)}") # Setup package locally check_call( From c961bd02e6d7489b56c1d159df094a1028aa3355 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 23 Mar 2023 16:41:49 +0800 Subject: [PATCH 2/3] Update sdk_generator.py --- tools/azure-sdk-tools/packaging_tools/sdk_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py index dd708bf07edf..98b6af4ae8ef 100644 --- a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py +++ b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py @@ -89,7 +89,7 @@ def main(generate_input, generate_output): readme_files = [data["relatedTypeSpecProjectFolder"]] else: readme_files = data["relatedTypeSpecProjectFolder"] - spec_word = "tspProject" + spec_word = "typeSpecProject" for input_readme in readme_files: _LOGGER.info(f"[CODEGEN]({input_readme})codegen begin") From b9d6f64f8c85dccbb93129c48e893bcf9deff7e9 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Thu, 23 Mar 2023 17:26:06 +0800 Subject: [PATCH 3/3] fix --- tools/azure-sdk-tools/packaging_tools/generate_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/azure-sdk-tools/packaging_tools/generate_utils.py b/tools/azure-sdk-tools/packaging_tools/generate_utils.py index 1baaf27e3876..906111c2478c 100644 --- a/tools/azure-sdk-tools/packaging_tools/generate_utils.py +++ b/tools/azure-sdk-tools/packaging_tools/generate_utils.py @@ -398,7 +398,7 @@ def gen_typespec(typespec_relative_path: str, spec_folder: str) -> Dict[str, Any # generate code typespec_file = "client.tsp" if Path("client.tsp").exists() else "." - check_call(f"npx typespec compile {typespec_file} --emit {typespec_python} --arg \"python-sdk-folder={origin_path}\" ", shell=True) + check_call(f"npx tsp compile {typespec_file} --emit {typespec_python} --arg \"python-sdk-folder={origin_path}\" ", shell=True) # get version of codegen used in generation npm_package_verstion = get_npm_package_version(autorest_python)