Skip to content

Commit

Permalink
[Dpg] update to use global autorest version (#24970)
Browse files Browse the repository at this point in the history
* code

* fix

* code
  • Loading branch information
msyyc authored Jun 24, 2022
1 parent 41807f0 commit ed8cb17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions scripts/quickstart_tooling_dpg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
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__)

_TEMPLATE = Path(__file__).resolve().parent / "template"
_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(
Expand All @@ -39,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')
Expand Down Expand Up @@ -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")
Expand All @@ -93,17 +102,17 @@ 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
env = Environment(loader=FileSystemLoader(_TEMPLATE), keep_trailing_newline=True)
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 --version=3.8.1 --use=@autorest/[email protected] --use=@autorest/[email protected]'
f' {swagger_readme}', 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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/quickstart_tooling_dpg/template/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
4 changes: 2 additions & 2 deletions swagger_to_sdk_config_dpg.json
Original file line number Diff line number Diff line change
@@ -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": ""
Expand Down

0 comments on commit ed8cb17

Please sign in to comment.