litagin's picture
Bump ver
83d190a
raw
history blame
1.83 kB
import subprocess
import sys
from typing import Any, Callable
from style_bert_vits2.logging import logger
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT
def run_script_with_log(
cmd: list[str], ignore_warning: bool = False
) -> tuple[bool, str]:
"""
ๆŒ‡ๅฎšใ•ใ‚ŒใŸใ‚ณใƒžใƒณใƒ‰ใ‚’ๅฎŸ่กŒใ—ใ€ใใฎใƒญใ‚ฐใ‚’่จ˜้Œฒใ™ใ‚‹ใ€‚
Args:
cmd: ๅฎŸ่กŒใ™ใ‚‹ใ‚ณใƒžใƒณใƒ‰ใฎใƒชใ‚นใƒˆ
ignore_warning: ่ญฆๅ‘Šใ‚’็„ก่ฆ–ใ™ใ‚‹ใ‹ใฉใ†ใ‹ใฎใƒ•ใƒฉใ‚ฐ
Returns:
tuple[bool, str]: ๅฎŸ่กŒใŒๆˆๅŠŸใ—ใŸใ‹ใฉใ†ใ‹ใฎใƒ–ใƒผใƒซๅ€คใจใ€ใ‚จใƒฉใƒผใพใŸใฏ่ญฆๅ‘Šใฎใƒกใƒƒใ‚ปใƒผใ‚ธ๏ผˆใ‚ใ‚‹ๅ ดๅˆ๏ผ‰
"""
logger.info(f"Running: {' '.join(cmd)}")
result = subprocess.run(
[sys.executable] + cmd,
stdout=SAFE_STDOUT,
stderr=subprocess.PIPE,
text=True,
encoding="utf-8",
check=False,
)
if result.returncode != 0:
logger.error(f"Error: {' '.join(cmd)}\n{result.stderr}")
return False, result.stderr
elif result.stderr and not ignore_warning:
logger.warning(f"Warning: {' '.join(cmd)}\n{result.stderr}")
return True, result.stderr
logger.success(f"Success: {' '.join(cmd)}")
return True, ""
def second_elem_of(
original_function: Callable[..., tuple[Any, Any]]
) -> Callable[..., Any]:
"""
ไธŽใˆใ‚‰ใ‚ŒใŸ้–ขๆ•ฐใ‚’ใƒฉใƒƒใƒ—ใ—ใ€ใใฎๆˆปใ‚Šๅ€คใฎ 2 ็•ช็›ฎใฎ่ฆ็ด ใฎใฟใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’็”Ÿๆˆใ™ใ‚‹ใ€‚
Args:
original_function (Callable[..., tuple[Any, Any]])): ใƒฉใƒƒใƒ—ใ™ใ‚‹ๅ…ƒใฎ้–ขๆ•ฐ
Returns:
Callable[..., Any]: ๅ…ƒใฎ้–ขๆ•ฐใฎๆˆปใ‚Šๅ€คใฎ 2 ็•ช็›ฎใฎ่ฆ็ด ใฎใฟใ‚’่ฟ”ใ™้–ขๆ•ฐ
"""
def inner_function(*args, **kwargs) -> Any: # type: ignore
return original_function(*args, **kwargs)[1]
return inner_function