Skip to content
Merged
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
20 changes: 16 additions & 4 deletions tools/azure-sdk-tools/packaging_tools/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from azure_devtools.ci_tools.git_tools import get_add_diff_file_list
from pathlib import Path
from subprocess import check_call, getoutput
from subprocess import check_call
from typing import List, Dict, Any
from glob import glob
import yaml
Expand Down Expand Up @@ -329,9 +329,21 @@ def format_samples(sdk_code_path) -> None:

_LOGGER.info(f"format generated_samples successfully")

def get_npm_package_version(package: str) -> Dict[any, any]:
temp_file = "python_temp.json"
check_call(f"npm list {package} -json > {temp_file}", shell=True)
with open(temp_file, "r") as file_in:
data = json.load(file_in)
if "dependencies" not in data:
_LOGGER.info(f"can not find {package}: {data}")
return {}

return data["dependencies"]

def gen_cadl(cadl_relative_path: str, spec_folder: str) -> Dict[str, Any]:
# update config file
cadl_python = "@azure-tools/cadl-python"
autorest_python = "@autorest/python"
project_yaml_path = Path(spec_folder) / cadl_relative_path / "cadl-project.yaml"
with open(project_yaml_path, "r") as file_in:
project_yaml = yaml.safe_load(file_in)
Expand All @@ -358,10 +370,10 @@ def gen_cadl(cadl_relative_path: str, spec_folder: str) -> Dict[str, Any]:
if Path(output_path / "output.yaml").exists():
os.remove(Path(output_path / "output.yaml"))

# get version of @azure-tools/cadl-python used in generation
cadl_python_version = getoutput(f"npm view {cadl_python} version").split('\n')[-1]
# get version of codegen used in generation
npm_package_verstion = get_npm_package_version(autorest_python)

# return to original folder
os.chdir(origin_path)

return {cadl_python: cadl_python_version}
return npm_package_verstion