From 9e7d787a640ed3e4ffdc52a7f790a0e2a9bff9c2 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 25 May 2024 04:12:00 +0000 Subject: [PATCH 01/10] =?UTF-8?q?refctor:=20`presets.yaml`=20=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- build_util/make_docs.py | 5 ++--- presets.yaml | 10 ---------- run.spec | 1 - test/e2e/conftest.py | 8 +------- test/preset/test_preset.py | 7 ------- voicevox_engine/preset/PresetManager.py | 17 +++++++++++++++++ 7 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 presets.yaml diff --git a/Dockerfile b/Dockerfile index 488d7a586..ae87cfcc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -227,7 +227,7 @@ COPY --from=download-onnxruntime-env /opt/onnxruntime /opt/onnxruntime # Add local files ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine ADD ./docs /opt/voicevox_engine/docs -ADD ./run.py ./presets.yaml ./engine_manifest.json /opt/voicevox_engine/ +ADD ./run.py ./engine_manifest.json /opt/voicevox_engine/ ADD ./resources /opt/voicevox_engine/resources ADD ./build_util/generate_licenses.py /opt/voicevox_engine/build_util/ ADD ./speaker_info /opt/voicevox_engine/speaker_info diff --git a/build_util/make_docs.py b/build_util/make_docs.py index 75dd867aa..6ad03e92d 100644 --- a/build_util/make_docs.py +++ b/build_util/make_docs.py @@ -41,15 +41,14 @@ def generate_api_docs_html(schema: str) -> str: core_manager.register_core(CoreAdapter(MockCoreWrapper()), "mock") tts_engines = TTSEngineManager() tts_engines.register_engine(MockTTSEngine(), "mock") + preset_path = engine_root() / "presets.yaml" # FastAPI の機能を用いて OpenAPI schema を生成する app = generate_app( tts_engines=tts_engines, core_manager=core_manager, latest_core_version="mock", setting_loader=SettingHandler(USER_SETTING_PATH), - preset_manager=PresetManager( # FIXME: impl MockPresetManager - preset_path=engine_root() / "presets.yaml", - ), + preset_manager=PresetManager(preset_path), user_dict=UserDictionary(), ) api_schema = json.dumps(app.openapi()) diff --git a/presets.yaml b/presets.yaml deleted file mode 100644 index 0f554e61c..000000000 --- a/presets.yaml +++ /dev/null @@ -1,10 +0,0 @@ -- id: 1 - name: サンプルプリセット - speaker_uuid: 7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff - style_id: 0 - speedScale: 1 - pitchScale: 0 - intonationScale: 1 - volumeScale: 1 - prePhonemeLength: 0.1 - postPhonemeLength: 0.1 diff --git a/run.spec b/run.spec index 88b160ef4..5dba4e68b 100644 --- a/run.spec +++ b/run.spec @@ -8,7 +8,6 @@ datas = [ ('speaker_info', 'speaker_info'), ('engine_manifest.json', '.'), ('licenses.json', '.'), - ('presets.yaml', '.'), ('ui_template', 'ui_template'), ] datas += collect_data_files('pyopenjtalk') diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 0de2bfc2d..6004344f5 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -1,4 +1,3 @@ -import shutil from pathlib import Path from typing import Any @@ -20,12 +19,7 @@ def app_params(tmp_path: Path) -> dict[str, Any]: tts_engines = make_tts_engines_from_cores(core_manager) latest_core_version = tts_engines.latest_version() setting_loader = SettingHandler(Path("./not_exist.yaml")) - - # 隔離されたプリセットの生成 - original_preset_path = Path("./presets.yaml") - preset_path = tmp_path / "presets.yaml" - shutil.copyfile(original_preset_path, preset_path) - preset_manager = PresetManager(preset_path) + preset_manager = PresetManager(tmp_path / "presets.yaml") user_dict = UserDictionary() return { diff --git a/test/preset/test_preset.py b/test/preset/test_preset.py index 17c66fe16..3e4d68408 100644 --- a/test/preset/test_preset.py +++ b/test/preset/test_preset.py @@ -49,13 +49,6 @@ def test_empty_file() -> None: preset_manager.load_presets() -def test_not_exist_file() -> None: - preset_manager = PresetManager(preset_path=Path("test/presets-dummy.yaml")) - true_msg = "プリセットの設定ファイルが見つかりません" - with pytest.raises(PresetInternalError, match=true_msg): - preset_manager.load_presets() - - def test_add_preset(tmp_path: Path) -> None: temp_path = tmp_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) diff --git a/voicevox_engine/preset/PresetManager.py b/voicevox_engine/preset/PresetManager.py index 2519cbad2..00bb398d6 100644 --- a/voicevox_engine/preset/PresetManager.py +++ b/voicevox_engine/preset/PresetManager.py @@ -21,6 +21,23 @@ def __init__(self, preset_path: Path): self.last_modified_time = 0.0 self.preset_path = preset_path + # 設定ファイルが存在しない場合、デフォルト設定ファイルを指定のパスへ生成する + if not self.preset_path.exists(): + self.preset_path.write_text("[]") + default_preset = Preset( + id=1, + name="サンプルプリセット", + speaker_uuid="7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff", + style_id=0, + speedScale=1, + pitchScale=0, + intonationScale=1, + volumeScale=1, + prePhonemeLength=0.1, + postPhonemeLength=0.1, + ) + self.add_preset(default_preset) + def _refresh_cache(self) -> None: """プリセットの設定ファイルの最新状態をキャッシュへ反映する""" From 426c7b607bae40573503bfb062df5d3ae259ab94 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 25 May 2024 04:48:46 +0000 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20=E3=83=97=E3=83=AA=E3=82=BB?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=AB=E6=9D=A1=E4=BB=B6=E3=82=92=E4=BB=98=E4=B8=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/e2e/conftest.py | 31 ++++++++++++++++++++++++- test/preset/test_preset.py | 7 ++++++ voicevox_engine/preset/PresetManager.py | 8 +++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 6004344f5..fc2d171dc 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -4,6 +4,7 @@ import pytest from fastapi import FastAPI from fastapi.testclient import TestClient +import yaml from voicevox_engine.app.application import generate_app from voicevox_engine.core.core_initializer import initialize_cores @@ -19,7 +20,12 @@ def app_params(tmp_path: Path) -> dict[str, Any]: tts_engines = make_tts_engines_from_cores(core_manager) latest_core_version = tts_engines.latest_version() setting_loader = SettingHandler(Path("./not_exist.yaml")) - preset_manager = PresetManager(tmp_path / "presets.yaml") + + # テスト用に隔離されたプリセットを生成する + preset_path = tmp_path / "presets.yaml" + _generate_preset(preset_path) + preset_manager = PresetManager(preset_path) + user_dict = UserDictionary() return { @@ -40,3 +46,26 @@ def app(app_params: dict) -> FastAPI: @pytest.fixture() def client(app: FastAPI) -> TestClient: return TestClient(app) + + +def _generate_preset(preset_path: Path) -> None: + """指定パス下にプリセットファイルを生成する。""" + contents = [{ + "id": 1, + "name": "サンプルプリセット", + "speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff", + "style_id": 0, + "speedScale": 1, + "pitchScale": 0, + "intonationScale": 1, + "volumeScale": 1, + "prePhonemeLength": 0.1, + "postPhonemeLength": 0.1, + }] + with open(preset_path, mode="w", encoding="utf-8") as f: + yaml.safe_dump( + contents, + f, + allow_unicode=True, + sort_keys=False + ) diff --git a/test/preset/test_preset.py b/test/preset/test_preset.py index 3e4d68408..17c66fe16 100644 --- a/test/preset/test_preset.py +++ b/test/preset/test_preset.py @@ -49,6 +49,13 @@ def test_empty_file() -> None: preset_manager.load_presets() +def test_not_exist_file() -> None: + preset_manager = PresetManager(preset_path=Path("test/presets-dummy.yaml")) + true_msg = "プリセットの設定ファイルが見つかりません" + with pytest.raises(PresetInternalError, match=true_msg): + preset_manager.load_presets() + + def test_add_preset(tmp_path: Path) -> None: temp_path = tmp_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) diff --git a/voicevox_engine/preset/PresetManager.py b/voicevox_engine/preset/PresetManager.py index 00bb398d6..7af6c5a35 100644 --- a/voicevox_engine/preset/PresetManager.py +++ b/voicevox_engine/preset/PresetManager.py @@ -3,6 +3,8 @@ import yaml from pydantic import ValidationError, parse_obj_as +from voicevox_engine.utility.path_utility import engine_root + from .Preset import Preset from .PresetError import PresetInputError, PresetInternalError @@ -21,8 +23,10 @@ def __init__(self, preset_path: Path): self.last_modified_time = 0.0 self.preset_path = preset_path - # 設定ファイルが存在しない場合、デフォルト設定ファイルを指定のパスへ生成する - if not self.preset_path.exists(): + # 設定ファイルが無指定の場合、初期値を生成する + default_path = engine_root() / "presets.yaml" + preset_not_specified = default_path.resolve() == preset_path.resolve() + if not self.preset_path.exists() and preset_not_specified: self.preset_path.write_text("[]") default_preset = Preset( id=1, From 9580187fa2518546568c83c48bb43f6f26106b31 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 25 May 2024 04:49:20 +0000 Subject: [PATCH 03/10] fix: lint --- test/e2e/conftest.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index fc2d171dc..73f9f8417 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -2,9 +2,9 @@ from typing import Any import pytest +import yaml from fastapi import FastAPI from fastapi.testclient import TestClient -import yaml from voicevox_engine.app.application import generate_app from voicevox_engine.core.core_initializer import initialize_cores @@ -50,22 +50,19 @@ def client(app: FastAPI) -> TestClient: def _generate_preset(preset_path: Path) -> None: """指定パス下にプリセットファイルを生成する。""" - contents = [{ - "id": 1, - "name": "サンプルプリセット", - "speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff", - "style_id": 0, - "speedScale": 1, - "pitchScale": 0, - "intonationScale": 1, - "volumeScale": 1, - "prePhonemeLength": 0.1, - "postPhonemeLength": 0.1, - }] + contents = [ + { + "id": 1, + "name": "サンプルプリセット", + "speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff", + "style_id": 0, + "speedScale": 1, + "pitchScale": 0, + "intonationScale": 1, + "volumeScale": 1, + "prePhonemeLength": 0.1, + "postPhonemeLength": 0.1, + } + ] with open(preset_path, mode="w", encoding="utf-8") as f: - yaml.safe_dump( - contents, - f, - allow_unicode=True, - sort_keys=False - ) + yaml.safe_dump(contents, f, allow_unicode=True, sort_keys=False) From 5a7f4f44523f4eb0baa423f2751ca3ad34f1bb60 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sat, 25 May 2024 04:55:14 +0000 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=83=9F=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- voicevox_engine/preset/PresetManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voicevox_engine/preset/PresetManager.py b/voicevox_engine/preset/PresetManager.py index 7af6c5a35..18bd45592 100644 --- a/voicevox_engine/preset/PresetManager.py +++ b/voicevox_engine/preset/PresetManager.py @@ -23,7 +23,7 @@ def __init__(self, preset_path: Path): self.last_modified_time = 0.0 self.preset_path = preset_path - # 設定ファイルが無指定の場合、初期値を生成する + # プリセットファイルが無指定の場合、初期値を生成する default_path = engine_root() / "presets.yaml" preset_not_specified = default_path.resolve() == preset_path.resolve() if not self.preset_path.exists() and preset_not_specified: From f2000fba52a618dcfa7bed62f13b87a11ac55664 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sun, 2 Jun 2024 11:36:50 +0000 Subject: [PATCH 05/10] =?UTF-8?q?delete:=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E3=83=97=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88?= =?UTF-8?q?=E5=80=A4=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- voicevox_engine/preset/preset_manager.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/voicevox_engine/preset/preset_manager.py b/voicevox_engine/preset/preset_manager.py index 862877b0e..0492568ae 100644 --- a/voicevox_engine/preset/preset_manager.py +++ b/voicevox_engine/preset/preset_manager.py @@ -41,19 +41,6 @@ def __init__(self, preset_path: Path): preset_not_specified = default_path.resolve() == preset_path.resolve() if not self.preset_path.exists() and preset_not_specified: self.preset_path.write_text("[]") - default_preset = Preset( - id=1, - name="サンプルプリセット", - speaker_uuid="7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff", - style_id=0, - speedScale=1, - pitchScale=0, - intonationScale=1, - volumeScale=1, - prePhonemeLength=0.1, - postPhonemeLength=0.1, - ) - self.add_preset(default_preset) def _refresh_cache(self) -> None: """プリセットの設定ファイルの最新状態をキャッシュへ反映する""" From cdea545fa19273cf67c6e1c18cd9b75eb426593a Mon Sep 17 00:00:00 2001 From: tarepan Date: Fri, 7 Jun 2024 08:36:39 +0000 Subject: [PATCH 06/10] =?UTF-8?q?fix:=20merge=20=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/e2e/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 93927a3ad..1cb36e879 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -91,6 +91,8 @@ def _generate_preset(preset_path: Path) -> None: "volumeScale": 1, "prePhonemeLength": 0.1, "postPhonemeLength": 0.1, + "pauseLength": None, + "pauseLengthScale": 1, } ] with open(preset_path, mode="w", encoding="utf-8") as f: From eba8296d44482945377762ed8f00ad87cf9b6125 Mon Sep 17 00:00:00 2001 From: tarepan Date: Sun, 16 Jun 2024 02:09:11 +0000 Subject: [PATCH 07/10] =?UTF-8?q?fix:=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E7=84=A1=E6=8C=87=E5=AE=9A=E3=81=8B=E5=90=A6=E3=81=8B?= =?UTF-8?q?=E3=81=AE=E5=88=A4=E5=AE=9A=E3=82=92=E3=83=9E=E3=83=8D=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A3=E3=83=BC=E3=81=AE=E5=A4=96=E3=81=B8=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_util/make_docs.py | 2 +- run.py | 12 ++++++------ test/benchmark/engine_preparation.py | 2 +- voicevox_engine/preset/preset_manager.py | 20 ++++++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/build_util/make_docs.py b/build_util/make_docs.py index e9483d0f0..d2d6423a3 100644 --- a/build_util/make_docs.py +++ b/build_util/make_docs.py @@ -62,7 +62,7 @@ def generate_api_docs_html(schema: str) -> str: tts_engines=tts_engines, core_manager=core_manager, setting_loader=SettingHandler(USER_SETTING_PATH), - preset_manager=PresetManager(preset_path), + preset_manager=PresetManager(preset_path, make_file_if_not_exist=True), user_dict=UserDictionary(), engine_manifest=engine_manifest, library_manager=library_manager, diff --git a/run.py b/run.py index 6589b1bd2..702dd1ca7 100644 --- a/run.py +++ b/run.py @@ -316,12 +316,12 @@ def main() -> None: env_preset_path = Path(env_preset_path_str) else: env_preset_path = None - root_preset_path = engine_root() / "presets.yaml" - preset_path = select_first_not_none( - [arg_preset_path, env_preset_path, root_preset_path] - ) - # ファイルの存在に関わらず指定されたパスをプリセットファイルとして使用する - preset_manager = PresetManager(preset_path) + preset_path = select_first_not_none_or_none([arg_preset_path, env_preset_path]) + if preset_path is not None: + preset_manager = PresetManager(preset_path) + else: + default_preset_path = engine_root() / "presets.yaml" + preset_manager = PresetManager(default_preset_path, make_file_if_not_exist=True) use_dict = UserDictionary() diff --git a/test/benchmark/engine_preparation.py b/test/benchmark/engine_preparation.py index 578b54e40..fdce5ae93 100644 --- a/test/benchmark/engine_preparation.py +++ b/test/benchmark/engine_preparation.py @@ -24,7 +24,7 @@ def _generate_engine_fake_server(root_dir: Path) -> TestClient: ) tts_engines = make_tts_engines_from_cores(core_manager) setting_loader = SettingHandler(Path("./not_exist.yaml")) - preset_manager = PresetManager(Path("./presets.yaml")) + preset_manager = PresetManager(Path("./presets.yaml"), make_file_if_not_exist=True) user_dict = UserDictionary() engine_manifest = load_manifest(engine_manifest_path()) library_manager = LibraryManager( diff --git a/voicevox_engine/preset/preset_manager.py b/voicevox_engine/preset/preset_manager.py index 710fe03a7..76f613db2 100644 --- a/voicevox_engine/preset/preset_manager.py +++ b/voicevox_engine/preset/preset_manager.py @@ -5,8 +5,6 @@ import yaml from pydantic import TypeAdapter, ValidationError -from voicevox_engine.utility.path_utility import engine_root - from .model import Preset @@ -30,16 +28,22 @@ class PresetManager: YAMLファイルをSSoTとする簡易データベース方式により、プリセットの管理をおこなう。 """ - def __init__(self, preset_path: Path): - """プリセットの設定ファイルへのパスからプリセットマネージャーを生成する""" + def __init__(self, preset_path: Path, make_file_if_not_exist: bool = False): + """ + プリセットマネージャーを生成する。 + + Parameters + ---------- + preset_path : + プリセットの設定ファイルへのパス + make_file_if_not_exist : + パスが空のとき、プリセットファイルを自動生成するか否か + """ self.presets: list[Preset] = [] # 全プリセットのキャッシュ self.last_modified_time = 0.0 self.preset_path = preset_path - # プリセットファイルが無指定の場合、初期値を生成する - default_path = engine_root() / "presets.yaml" - preset_not_specified = default_path.resolve() == preset_path.resolve() - if not self.preset_path.exists() and preset_not_specified: + if not self.preset_path.exists() and make_file_if_not_exist: self.preset_path.write_text("[]") def _refresh_cache(self) -> None: From a042dedbbf532fed5abee6f9de83a6fbaac3b583 Mon Sep 17 00:00:00 2001 From: tarepan Date: Thu, 20 Jun 2024 18:16:51 +0000 Subject: [PATCH 08/10] =?UTF-8?q?remove:=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E3=83=97=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ run.py | 9 +++------ test/benchmark/engine_preparation.py | 2 +- tools/make_docs.py | 2 +- voicevox_engine/preset/preset_manager.py | 17 ++++------------- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index bfcae394d..70a8aa797 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ ## Artifact of generating licenses /licenses.json licenses_venv/ +## Presets +presets.yaml # Copied from `https://github.com/github/gitignore/blob/main/Python.gitignore` @2022-01-10 # Byte-compiled / optimized / DLL files diff --git a/run.py b/run.py index 04d7015c6..c5306cc54 100644 --- a/run.py +++ b/run.py @@ -336,12 +336,9 @@ def main() -> None: env_preset_path = Path(env_preset_path_str) else: env_preset_path = None - preset_path = select_first_not_none_or_none([args.preset_file, env_preset_path]) - if preset_path is not None: - preset_manager = PresetManager(preset_path) - else: - default_preset_path = engine_root() / "presets.yaml" - preset_manager = PresetManager(default_preset_path, make_file_if_not_exist=True) + default_preset_path = engine_root() / "presets.yaml" + preset_path = select_first_not_none([args.preset_file, env_preset_path, default_preset_path]) + preset_manager = PresetManager(preset_path) use_dict = UserDictionary() diff --git a/test/benchmark/engine_preparation.py b/test/benchmark/engine_preparation.py index fdce5ae93..578b54e40 100644 --- a/test/benchmark/engine_preparation.py +++ b/test/benchmark/engine_preparation.py @@ -24,7 +24,7 @@ def _generate_engine_fake_server(root_dir: Path) -> TestClient: ) tts_engines = make_tts_engines_from_cores(core_manager) setting_loader = SettingHandler(Path("./not_exist.yaml")) - preset_manager = PresetManager(Path("./presets.yaml"), make_file_if_not_exist=True) + preset_manager = PresetManager(Path("./presets.yaml")) user_dict = UserDictionary() engine_manifest = load_manifest(engine_manifest_path()) library_manager = LibraryManager( diff --git a/tools/make_docs.py b/tools/make_docs.py index d2d6423a3..e9483d0f0 100644 --- a/tools/make_docs.py +++ b/tools/make_docs.py @@ -62,7 +62,7 @@ def generate_api_docs_html(schema: str) -> str: tts_engines=tts_engines, core_manager=core_manager, setting_loader=SettingHandler(USER_SETTING_PATH), - preset_manager=PresetManager(preset_path, make_file_if_not_exist=True), + preset_manager=PresetManager(preset_path), user_dict=UserDictionary(), engine_manifest=engine_manifest, library_manager=library_manager, diff --git a/voicevox_engine/preset/preset_manager.py b/voicevox_engine/preset/preset_manager.py index 76f613db2..7029db043 100644 --- a/voicevox_engine/preset/preset_manager.py +++ b/voicevox_engine/preset/preset_manager.py @@ -28,22 +28,13 @@ class PresetManager: YAMLファイルをSSoTとする簡易データベース方式により、プリセットの管理をおこなう。 """ - def __init__(self, preset_path: Path, make_file_if_not_exist: bool = False): - """ - プリセットマネージャーを生成する。 - - Parameters - ---------- - preset_path : - プリセットの設定ファイルへのパス - make_file_if_not_exist : - パスが空のとき、プリセットファイルを自動生成するか否か - """ + def __init__(self, preset_path: Path): + """プリセットマネージャーを生成する。プリセットファイルが存在しない場合は新規作成する。""" + self.presets: list[Preset] = [] # 全プリセットのキャッシュ self.last_modified_time = 0.0 self.preset_path = preset_path - - if not self.preset_path.exists() and make_file_if_not_exist: + if not self.preset_path.exists(): self.preset_path.write_text("[]") def _refresh_cache(self) -> None: From 4e16414acc26c6096b8a786c1697750977c561ad Mon Sep 17 00:00:00 2001 From: tarepan Date: Thu, 20 Jun 2024 18:17:32 +0000 Subject: [PATCH 09/10] fix: lint --- run.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run.py b/run.py index c5306cc54..cfe38ac6d 100644 --- a/run.py +++ b/run.py @@ -337,7 +337,9 @@ def main() -> None: else: env_preset_path = None default_preset_path = engine_root() / "presets.yaml" - preset_path = select_first_not_none([args.preset_file, env_preset_path, default_preset_path]) + preset_path = select_first_not_none( + [args.preset_file, env_preset_path, default_preset_path] + ) preset_manager = PresetManager(preset_path) use_dict = UserDictionary() From a49d5605f4c39a5a3c33c03ada3ecd330e8f57ea Mon Sep 17 00:00:00 2001 From: tarepan Date: Thu, 20 Jun 2024 18:23:19 +0000 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20test=20=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/preset/test_preset.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/unit/preset/test_preset.py b/test/unit/preset/test_preset.py index 10f983b35..0efbfcfff 100644 --- a/test/unit/preset/test_preset.py +++ b/test/unit/preset/test_preset.py @@ -52,11 +52,10 @@ def test_empty_file() -> None: preset_manager.load_presets() -def test_not_exist_file() -> None: - preset_manager = PresetManager(preset_path=Path("test/presets-dummy.yaml")) - true_msg = "プリセットの設定ファイルが見つかりません" - with pytest.raises(PresetInternalError, match=true_msg): - preset_manager.load_presets() +def test_not_exist_file(tmp_path: Path) -> None: + preset_manager = PresetManager(preset_path=tmp_path / "presets-dummy.yaml") + presets = preset_manager.load_presets() + assert len(presets) == 0 def test_add_preset(tmp_path: Path) -> None: