diff --git a/tools/azure-sdk-tools/packaging_tools/generate_utils.py b/tools/azure-sdk-tools/packaging_tools/generate_utils.py index a40540573e2b..e42cb7ca5517 100644 --- a/tools/azure-sdk-tools/packaging_tools/generate_utils.py +++ b/tools/azure-sdk-tools/packaging_tools/generate_utils.py @@ -7,7 +7,7 @@ from ci_tools.git_tools import get_add_diff_file_list from pathlib import Path -from subprocess import check_output, CalledProcessError, check_call +from subprocess import check_output, CalledProcessError, check_call, getoutput from typing import Dict, Any from glob import glob import yaml @@ -75,11 +75,9 @@ def call_build_config(package_name: str, folder_name: str): # shell=True, # ) -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(): - call_build_config(package_name, folder_name) +def init_new_service(package_name, folder_name): + if "azure-mgmt-" in package_name: + call_build_config(package_name, folder_name) else: output_path = Path(folder_name) / package_name if not (output_path / CONF_NAME).exists(): @@ -99,16 +97,11 @@ def update_servicemetadata(sdk_folder, data, config, folder_name, package_name, if not package_folder.exists(): _LOGGER.info(f"Fail to save metadata since package folder doesn't exist: {package_folder}") return - if not (package_folder / "_meta.json").exists(): - metadata = {} - else: - with open(str(package_folder / "_meta.json"), "r") as file_in: - metadata = json.load(file_in) - metadata.update({ + metadata = { "commit": data["headSha"], "repository_url": data["repoHttpsUrl"], - }) + } if "meta" in config: readme_file = str(Path(spec_folder, input_readme)) global_conf = config["meta"] @@ -383,7 +376,7 @@ def generate_ci(template_path: Path, folder_path: Path, package_name: str) -> No def gen_typespec(typespec_relative_path: str, spec_folder: str, head_sha: str, rest_repo_url: str) -> Dict[str, Any]: typespec_python = "@azure-tools/typespec-python" - + autorest_python = "@autorest/python" # call scirpt to generate sdk try: check_output(f'pwsh {Path("eng/common/scripts/TypeSpec-Project-Process.ps1")} {(Path(spec_folder) / typespec_relative_path).resolve()} {head_sha} {rest_repo_url}', shell=True) @@ -392,8 +385,12 @@ def gen_typespec(typespec_relative_path: str, spec_folder: str, head_sha: str, r raise e # get version of codegen used in generation + autorest_python_version = getoutput(f"npm show {autorest_python} version") with open(Path("eng/emitter-package.json"), "r") as file_in: data = json.load(file_in) - npm_package_verstion = {typespec_python: data["dependencies"][typespec_python]} + npm_package_verstion = { + typespec_python: data["dependencies"][typespec_python], + autorest_python: autorest_python_version, + } return npm_package_verstion diff --git a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py index 02d6b5cb5ee5..f8acf613b7da 100644 --- a/tools/azure-sdk-tools/packaging_tools/sdk_generator.py +++ b/tools/azure-sdk-tools/packaging_tools/sdk_generator.py @@ -268,7 +268,6 @@ def main(generate_input, generate_output): for input_readme in readme_files: _LOGGER.info(f"[CODEGEN]({input_readme})codegen begin") - is_typespec = False if "resource-manager" in input_readme: relative_path_readme = str(Path(spec_folder, input_readme)) update_metadata_for_multiapi_package(spec_folder, input_readme) @@ -286,7 +285,6 @@ def main(generate_input, generate_output): config = gen_dpg(input_readme, data.get("autorestConfig", ""), dpg_relative_folder(spec_folder)) else: config = gen_typespec(input_readme, spec_folder, data["headSha"], data["repoHttpsUrl"]) - is_typespec = True package_names = get_package_names(sdk_folder) _LOGGER.info(f"[CODEGEN]({input_readme})codegen end. [(packages:{str(package_names)})]") @@ -309,7 +307,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_typespec) + init_new_service(package_name, folder_name) format_samples(sdk_code_path) # Update metadata