From 62b5a0753d3ab593c4fe3caf74fb0e3c5f50db5f Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:36:36 +0800 Subject: [PATCH] use ruamel.yaml for openutau ustx files --- libresvip/plugins/ustx/ustx_converter.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libresvip/plugins/ustx/ustx_converter.py b/libresvip/plugins/ustx/ustx_converter.py index 5e334fc01..159dde024 100644 --- a/libresvip/plugins/ustx/ustx_converter.py +++ b/libresvip/plugins/ustx/ustx_converter.py @@ -1,6 +1,6 @@ import pathlib -import yaml +from ruamel.yaml import YAML from libresvip.extension import base as plugin_base from libresvip.model.base import Project @@ -11,23 +11,18 @@ from .ustx_generator import UstxGenerator from .ustx_parser import UstxParser +y=YAML(typ='safe') class OpenUtauConverter(plugin_base.SVSConverterBase): def load(self, path: pathlib.Path, options: InputOptions) -> Project: proj_text = to_unicode(path.read_bytes()) ustx_project = USTXProject.model_validate( - yaml.load(proj_text, getattr(yaml, "CSafeLoader", yaml.SafeLoader)) + y.load(proj_text) ) return UstxParser(options).parse_project(ustx_project) def dump(self, path: pathlib.Path, project: Project, options: OutputOptions) -> None: ustx_project = UstxGenerator(options).generate_project(project) proj_dict = ustx_project.model_dump(by_alias=True, exclude_none=True) - proj_text = yaml.dump( - proj_dict, - None, - getattr(yaml, "CSafeDumper", yaml.SafeDumper), - allow_unicode=True, - sort_keys=False, - ) + proj_text = y.dump(proj_dict) path.write_bytes(proj_text.encode("utf-8"))