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

[Tool] format generate samples #25233

Merged
merged 52 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f1aeb2f
Merge pull request #1 from Azure/master
BigCat20196 Jun 7, 2021
89cb1ee
Merge pull request #2 from Azure/main
BigCat20196 Jun 21, 2021
ceb1300
Merge pull request #3 from Azure/main
BigCat20196 Jul 1, 2021
23da66e
Merge pull request #4 from Azure/main
BigCat20196 Jul 7, 2021
25145b5
Merge pull request #5 from Azure/main
BigCat20196 Jul 9, 2021
b24885e
Merge pull request #6 from Azure/main
BigCat20196 Jul 12, 2021
2ef256c
Merge pull request #7 from Azure/main
BigCat20196 Jul 27, 2021
10a97e5
Merge pull request #8 from Azure/main
BigCat20196 Aug 4, 2021
24f65c3
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Oct 9, 2021
3fdba01
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Oct 12, 2021
3e8eb8e
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Oct 13, 2021
92b06a6
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Oct 28, 2021
40ce8cc
Merge branch 'main' of https://github.com/BigCat20196/azure-sdk-for-p…
BigCat20196 Jun 22, 2022
675245f
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jun 22, 2022
b0b6c17
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jun 29, 2022
71a41f2
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jun 30, 2022
246c7bf
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jul 5, 2022
4d20deb
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jul 6, 2022
268bbd8
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jul 13, 2022
c61de8f
format generate sample
BigCat20196 Jul 15, 2022
f28ce2b
test
BigCat20196 Jul 15, 2022
7e2c7ce
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jul 15, 2022
2dd3328
test
BigCat20196 Jul 15, 2022
038d916
test
BigCat20196 Jul 15, 2022
077c5af
test
BigCat20196 Jul 15, 2022
516b03e
test
BigCat20196 Jul 15, 2022
404d182
test
BigCat20196 Jul 15, 2022
f985f92
test
BigCat20196 Jul 15, 2022
a058098
test
BigCat20196 Jul 18, 2022
3fa9519
change
BigCat20196 Jul 18, 2022
59af9f1
test
BigCat20196 Jul 18, 2022
ccbc2f2
test
BigCat20196 Jul 18, 2022
fab2e91
test
BigCat20196 Jul 19, 2022
cbdaeb3
reset
BigCat20196 Jul 19, 2022
d68ff22
update format samples
BigCat20196 Jul 19, 2022
b89ece3
update
BigCat20196 Jul 19, 2022
dce9130
update
BigCat20196 Jul 19, 2022
e04bac4
update
BigCat20196 Jul 19, 2022
e473025
update
BigCat20196 Jul 19, 2022
d6adaac
update
BigCat20196 Jul 19, 2022
9849665
update
BigCat20196 Jul 19, 2022
1596ba7
update
BigCat20196 Jul 19, 2022
016d972
delete test code
BigCat20196 Jul 20, 2022
bf11bae
delete test code
BigCat20196 Jul 20, 2022
831e205
format
BigCat20196 Jul 20, 2022
41e4602
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
BigCat20196 Jul 20, 2022
1055403
debug
BigCat20196 Jul 20, 2022
c4f4fdf
rollback
BigCat20196 Jul 20, 2022
07aaeef
Update tools/azure-sdk-tools/packaging_tools/generate_utils.py
BigCat20196 Jul 22, 2022
b4bf47b
Update tools/azure-sdk-tools/packaging_tools/generate_utils.py
BigCat20196 Jul 22, 2022
f4c100c
Update tools/azure-sdk-tools/packaging_tools/generate_utils.py
BigCat20196 Jul 22, 2022
e256a03
Update tools/azure-sdk-tools/packaging_tools/generate_utils.py
msyyc Jul 22, 2022
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
4 changes: 3 additions & 1 deletion tools/azure-sdk-tools/packaging_tools/auto_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from .swaggertosdk.SwaggerToSdkCore import CONFIG_FILE, CONFIG_FILE_DPG
from .generate_sdk import generate
from .generate_utils import get_package_names, init_new_service, update_servicemetadata, judge_tag_preview
from .generate_utils import (get_package_names, init_new_service, update_servicemetadata, judge_tag_preview,
format_samples)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,6 +48,7 @@ def main(generate_input, generate_output):

# Generate some necessary file for new service
init_new_service(package_name, folder_name)
format_samples(sdk_code_path)

# Update metadata
try:
Expand Down
29 changes: 29 additions & 0 deletions tools/azure-sdk-tools/packaging_tools/generate_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import suppress
import json
import logging
import os
Expand Down Expand Up @@ -126,3 +127,31 @@ def judge_tag_preview(path: str) -> bool:

_LOGGER.info(f'find single api version:{api_version}')
return 'preview' in api_version


def format_samples(sdk_code_path) -> None:
generate_sample_path = Path(sdk_code_path) / 'generated_samples'
if not generate_sample_path.exists():
_LOGGER.info(f'not find generated_samples')
return

try:
import black
except Exception as e:
check_call('pip install black', shell=True)
import black

_BLACK_MODE = black.Mode()
_BLACK_MODE.line_length = 120
msyyc marked this conversation as resolved.
Show resolved Hide resolved
files = generate_sample_path.glob('**/*.py')
for path in files:
with open(path, 'r') as fr:
file_content = fr.read()

with suppress(black.NothingChanged):
msyyc marked this conversation as resolved.
Show resolved Hide resolved
file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)

with open(path, 'w') as fw:
fw.write(file_content)

_LOGGER.info(f'format generated_samples successfully')
1 change: 1 addition & 0 deletions tools/azure-sdk-tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"wheel",
"Jinja2",
"MarkupSafe==2.0.1",
# black,
msyyc marked this conversation as resolved.
Show resolved Hide resolved
"pytoml",
"json-delta>=2.0",
# Tests
Expand Down