Skip to content

Commit

Permalink
Enable mgmt from tsp (#34805)
Browse files Browse the repository at this point in the history
* optimization for meta

* optimize for packaging files
  • Loading branch information
msyyc authored Mar 18, 2024
1 parent aa03c97 commit 5934b3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
27 changes: 12 additions & 15 deletions tools/azure-sdk-tools/packaging_tools/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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"]
Expand Down Expand Up @@ -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)
Expand All @@ -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
4 changes: 1 addition & 3 deletions tools/azure-sdk-tools/packaging_tools/sdk_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)})]")

Expand All @@ -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
Expand Down

0 comments on commit 5934b3c

Please sign in to comment.