-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dpg] update to use global autorest version (#24970)
* code * fix * code
- Loading branch information
Showing
3 changed files
with
19 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -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') | ||
|
@@ -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,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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters