From 2abf30cbf82d3348709c678399ff207ce37490eb Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:31:47 +0800 Subject: [PATCH 1/3] code --- scripts/quickstart_tooling_dpg/main.py | 16 ++++++++++++---- scripts/quickstart_tooling_dpg/template/setup.py | 4 ++-- swagger_to_sdk_config_dpg.json | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/quickstart_tooling_dpg/main.py b/scripts/quickstart_tooling_dpg/main.py index bbd407d4d922..8ed805856e8b 100644 --- a/scripts/quickstart_tooling_dpg/main.py +++ b/scripts/quickstart_tooling_dpg/main.py @@ -5,7 +5,8 @@ from jinja2 import Environment, FileSystemLoader from subprocess import check_call import time -from typing import Any, Dict +from typing import Any +import json _LOGGER = logging.getLogger(__name__) @@ -13,6 +14,7 @@ _TEMPLATE_TESTS = Path(__file__).resolve().parent / "template_tests" _TEMPLATE_SAMPLES = Path(__file__).resolve().parent / "template_samples" _TEMPLATE_CI = Path(__file__).resolve().parent / "template_ci" +_CONFIG_FILE = Path(__file__).resolve() / "../../swagger_to_sdk_config_dpg.json" def check_parameters( @@ -75,6 +77,13 @@ def generate_swagger_readme(work_path: str, env: Environment, **kwargs: Any) -> return swagger_readme +def get_autorest_version() -> str: + with open(_CONFIG_FILE, 'r') as file_in: + config = json.load(file_in) + autorest_use = " ".join(["--use=" + item for item in config["meta"]["autorest_options"]["use"]]) + return "--version={} {}".format(config["meta"]["autorest_options"]["version"], autorest_use) + + def build_package(**kwargs) -> None: # prepare template render parameters output_folder = kwargs.get("output_folder") @@ -93,7 +102,7 @@ def build_package(**kwargs) -> None: _LOGGER.info("Build start: %s", package_name) check_parameters(output_folder) - #generate ci + # generate ci generate_ci(_TEMPLATE_CI, Path(output_folder).parent, package_name) # generate swagger readme @@ -102,8 +111,7 @@ def build_package(**kwargs) -> None: # generate code with autorest and swagger readme _LOGGER.info("generate SDK code with autorest") - check_call(f'autorest --version=3.8.1 --use=@autorest/python@5.17.0 --use=@autorest/modelerfour@4.23.5' - f' {swagger_readme}', shell=True) + check_call(f'autorest {swagger_readme} {get_autorest_version()} ', shell=True) # generate necessary file(setup.py, CHANGELOG.md, etc) work_path = Path(output_folder) diff --git a/scripts/quickstart_tooling_dpg/template/setup.py b/scripts/quickstart_tooling_dpg/template/setup.py index 95c4d5588532..6d2785d6f41c 100644 --- a/scripts/quickstart_tooling_dpg/template/setup.py +++ b/scripts/quickstart_tooling_dpg/template/setup.py @@ -60,8 +60,8 @@ ] ), install_requires=[ - "azure-core<2.0.0,>=1.23.0", - "msrest>=0.6.21", + "azure-core<2.0.0,>=1.24.0", + "msrest>=0.7.0", ], python_requires=">=3.6", ) diff --git a/swagger_to_sdk_config_dpg.json b/swagger_to_sdk_config_dpg.json index 4900e744c9e8..373db6608830 100644 --- a/swagger_to_sdk_config_dpg.json +++ b/swagger_to_sdk_config_dpg.json @@ -1,8 +1,8 @@ { "meta": { "autorest_options": { - "version": "3.7.2", - "use": ["@autorest/python@5.16.0", "@autorest/modelerfour@4.19.3"], + "version": "3.8.1", + "use": ["@autorest/python@5.19.0", "@autorest/modelerfour@4.23.5"], "python": "", "sdkrel:python-sdks-folder": "./sdk/.", "version-tolerant": "" From a5939642ddbe14c98151fa08798287a0b2d280f2 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:35:23 +0800 Subject: [PATCH 2/3] fix --- scripts/quickstart_tooling_dpg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/quickstart_tooling_dpg/main.py b/scripts/quickstart_tooling_dpg/main.py index 8ed805856e8b..b287bc3ab582 100644 --- a/scripts/quickstart_tooling_dpg/main.py +++ b/scripts/quickstart_tooling_dpg/main.py @@ -14,7 +14,7 @@ _TEMPLATE_TESTS = Path(__file__).resolve().parent / "template_tests" _TEMPLATE_SAMPLES = Path(__file__).resolve().parent / "template_samples" _TEMPLATE_CI = Path(__file__).resolve().parent / "template_ci" -_CONFIG_FILE = Path(__file__).resolve() / "../../swagger_to_sdk_config_dpg.json" +_CONFIG_FILE = Path(__file__).resolve() / "../../../swagger_to_sdk_config_dpg.json" def check_parameters( From 2e57eb9ce1fa1b4cf9937eff372e84b51805070f Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:47:28 +0800 Subject: [PATCH 3/3] code --- scripts/quickstart_tooling_dpg/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/quickstart_tooling_dpg/main.py b/scripts/quickstart_tooling_dpg/main.py index b287bc3ab582..8b70a4ae0e6b 100644 --- a/scripts/quickstart_tooling_dpg/main.py +++ b/scripts/quickstart_tooling_dpg/main.py @@ -41,7 +41,7 @@ def generate_ci(template_path: Path, folder_path: Path, package_name: str) -> No with open(ci, "r") as file_in: content = file_in.readlines() for line in content: - if f'{package_name}\n' in line: + if f'{package_name}' in line: return content.append(f' - name: {package_name}\n') content.append(f' safeName: {package_name.replace("-", "")}\n') @@ -110,8 +110,9 @@ def build_package(**kwargs) -> None: swagger_readme = generate_swagger_readme(output_folder, env, **kwargs) # generate code with autorest and swagger readme - _LOGGER.info("generate SDK code with autorest") - check_call(f'autorest {swagger_readme} {get_autorest_version()} ', shell=True) + autorest_cmd = f'autorest {swagger_readme} {get_autorest_version()} ' + _LOGGER.info(f"generate SDK code with autorest: {autorest_cmd}") + check_call(autorest_cmd, shell=True) # generate necessary file(setup.py, CHANGELOG.md, etc) work_path = Path(output_folder)