Skip to content
Merged
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
37 changes: 12 additions & 25 deletions tools/azure-sdk-tools/packaging_tools/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ci_tools.git_tools import get_add_diff_file_list
from pathlib import Path
from subprocess import check_output, CalledProcessError, check_call, STDOUT
from subprocess import check_output, CalledProcessError, check_call, STDOUT, call
from typing import Dict, Any
from glob import glob
import yaml
Expand Down Expand Up @@ -379,34 +379,21 @@ def gen_dpg(rest_readme_path: str, autorest_config: str, spec_folder: str) -> Di


def format_samples_and_tests(sdk_code_path) -> None:
try:
import black
except Exception as e:
try:
call("pip install black", shell=True)
except:
pass
for item in ["generated_samples", "generated_tests"]:
generate_path = Path(sdk_code_path) / item
if not generate_path.exists():
_LOGGER.info(f"not find {generate_path}")
continue

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
files = generate_path.glob("**/*.py")
for path in files:
if generate_path.exists():
try:
with open(path, "r") as fr:
file_content = fr.read()

file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)

with open(path, "w") as fw:
fw.write(file_content)
call(f"black {generate_path} -l 120", shell=True)
_LOGGER.info(f"format {generate_path} successfully")
except Exception as e:
_LOGGER.warning(f"Failed to format {path}: {e}")

_LOGGER.info(f"format {generate_path} successfully")
_LOGGER.info(f"failed to format {generate_path}: {e}")


def generate_ci(template_path: Path, folder_path: Path, package_name: str) -> None:
Expand Down