Apply black formatter
This commit is contained in:
@@ -8,40 +8,35 @@ class StdoutWrapper(TextIO):
|
||||
`sys.stdout` wrapper for both Google Colab and local environment.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.temp_file = tempfile.NamedTemporaryFile(
|
||||
mode="w+", delete=False, encoding="utf-8"
|
||||
)
|
||||
self.original_stdout = sys.stdout
|
||||
|
||||
|
||||
def write(self, message: str) -> int:
|
||||
result = self.temp_file.write(message)
|
||||
self.temp_file.flush()
|
||||
print(message, end="", file=self.original_stdout)
|
||||
return result
|
||||
|
||||
|
||||
def flush(self) -> None:
|
||||
self.temp_file.flush()
|
||||
|
||||
|
||||
def read(self, n: int = -1) -> str:
|
||||
self.temp_file.seek(0)
|
||||
return self.temp_file.read(n)
|
||||
|
||||
|
||||
def close(self) -> None:
|
||||
self.temp_file.close()
|
||||
|
||||
|
||||
def fileno(self) -> int:
|
||||
return self.temp_file.fileno()
|
||||
|
||||
|
||||
try:
|
||||
import google.colab # type: ignore
|
||||
|
||||
SAFE_STDOUT = StdoutWrapper()
|
||||
except ImportError:
|
||||
SAFE_STDOUT = sys.stdout
|
||||
|
||||
@@ -9,27 +9,28 @@ class StrEnum(str, enum.Enum):
|
||||
def __new__(cls, *values: str) -> "StrEnum":
|
||||
"values must already be of type `str`"
|
||||
if len(values) > 3:
|
||||
raise TypeError('too many arguments for str(): %r' % (values, ))
|
||||
raise TypeError("too many arguments for str(): %r" % (values,))
|
||||
if len(values) == 1:
|
||||
# it must be a string
|
||||
if not isinstance(values[0], str): # type: ignore
|
||||
raise TypeError('%r is not a string' % (values[0], ))
|
||||
raise TypeError("%r is not a string" % (values[0],))
|
||||
if len(values) >= 2:
|
||||
# check that encoding argument is a string
|
||||
if not isinstance(values[1], str): # type: ignore
|
||||
raise TypeError('encoding must be a string, not %r' % (values[1], ))
|
||||
raise TypeError("encoding must be a string, not %r" % (values[1],))
|
||||
if len(values) == 3:
|
||||
# check that errors argument is a string
|
||||
if not isinstance(values[2], str): # type: ignore
|
||||
raise TypeError('errors must be a string, not %r' % (values[2]))
|
||||
raise TypeError("errors must be a string, not %r" % (values[2]))
|
||||
value = str(*values)
|
||||
member = str.__new__(cls, value)
|
||||
member._value_ = value
|
||||
return member
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _generate_next_value_(name: str, start: int, count: int, last_values: list[str]) -> str:
|
||||
def _generate_next_value_(
|
||||
name: str, start: int, count: int, last_values: list[str]
|
||||
) -> str:
|
||||
"""
|
||||
Return the lower-cased version of the member name.
|
||||
"""
|
||||
|
||||
@@ -6,7 +6,9 @@ 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]:
|
||||
def run_script_with_log(
|
||||
cmd: list[str], ignore_warning: bool = False
|
||||
) -> tuple[bool, str]:
|
||||
"""
|
||||
指定されたコマンドを実行し、そのログを記録する。
|
||||
|
||||
@@ -21,10 +23,10 @@ def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[b
|
||||
logger.info(f"Running: {' '.join(cmd)}")
|
||||
result = subprocess.run(
|
||||
[sys.executable] + cmd,
|
||||
stdout = SAFE_STDOUT,
|
||||
stderr = subprocess.PIPE,
|
||||
text = True,
|
||||
encoding = "utf-8",
|
||||
stdout=SAFE_STDOUT,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
if result.returncode != 0:
|
||||
logger.error(f"Error: {' '.join(cmd)}\n{result.stderr}")
|
||||
@@ -37,7 +39,9 @@ def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[b
|
||||
return True, ""
|
||||
|
||||
|
||||
def second_elem_of(original_function: Callable[..., tuple[Any, Any]]) -> Callable[..., Any]:
|
||||
def second_elem_of(
|
||||
original_function: Callable[..., tuple[Any, Any]]
|
||||
) -> Callable[..., Any]:
|
||||
"""
|
||||
与えられた関数をラップし、その戻り値の 2 番目の要素のみを返す関数を生成する。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user