Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dpg] update to use global autorest version #24970

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, line 17, should be ,

_CONFIG_FILE = Path(__file__).resolve().parent / "../../../swagger_to_sdk_config_dpg.json"

parent should be appended. Why? because without adding .parent this points to file main.py, not a folder.

Error Recieved:
Input

python ./scripts/quickstart_tooling_dpg/main.py --output-folder ./sdk/loadtestservice/azure-developer-loadtest --input-file /mnt/c/Users/niveditjain/Desktop/loadtesting.json --security-scope https://loadtest.azure-dev.com/.default --package-name azure-developer-loadtestservice --package-pprint-name "Azure Developer LoadTestService" --client-name LoadTestClient

Output:

INFO:__main__:Build start: azure-developer-loadtestservice
INFO:__main__:Building swagger readme
Traceback (most recent call last):
  File "./scripts/quickstart_tooling_dpg/main.py", line 186, in <module>
    main(**parameters)
  File "./scripts/quickstart_tooling_dpg/main.py", line 126, in main
    build_package(**kwargs)
  File "./scripts/quickstart_tooling_dpg/main.py", line 105, in build_package
    autorest_cmd = f'autorest {swagger_readme} {get_autorest_version()} '
  File "./scripts/quickstart_tooling_dpg/main.py", line 80, in get_autorest_version
    with open(_CONFIG_FILE, 'r') as file_in:
NotADirectoryError: [Errno 20] Not a directory: '/mnt/c/Users/niveditjain/Desktop/azure-sdk/scripts/quickstart_tooling_dpg/main.py/../../../swagger_to_sdk_config_dpg.json'

Error was resolved by rewriting the line 17 as,

 _CONFIG_FILE = Path(__file__).resolve().parent / "../../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