diff --git a/build_util/make_docs.py b/build_util/make_docs.py index e36295bf6..14bf53f75 100644 --- a/build_util/make_docs.py +++ b/build_util/make_docs.py @@ -4,7 +4,7 @@ from voicevox_engine.dev.core.mock import MockCoreWrapper from voicevox_engine.dev.tts_engine.mock import MockTTSEngine from voicevox_engine.preset.PresetManager import PresetManager -from voicevox_engine.setting.SettingLoader import USER_SETTING_PATH, SettingLoader +from voicevox_engine.setting.SettingLoader import USER_SETTING_PATH, SettingHandler from voicevox_engine.tts_pipeline.tts_engine import CoreAdapter from voicevox_engine.utility.path_utility import engine_root @@ -41,7 +41,7 @@ def generate_api_docs_html(schema: str) -> str: tts_engines={"mock": MockTTSEngine()}, cores={"mock": CoreAdapter(mock_core)}, latest_core_version="mock", - setting_loader=SettingLoader(USER_SETTING_PATH), + setting_loader=SettingHandler(USER_SETTING_PATH), preset_manager=PresetManager( # FIXME: impl MockPresetManager preset_path=engine_root() / "presets.yaml", ), diff --git a/run.py b/run.py index 3dc1f23bb..34671965a 100644 --- a/run.py +++ b/run.py @@ -71,7 +71,7 @@ from voicevox_engine.preset.PresetError import PresetError from voicevox_engine.preset.PresetManager import PresetManager from voicevox_engine.setting.Setting import CorsPolicyMode, Setting -from voicevox_engine.setting.SettingLoader import USER_SETTING_PATH, SettingLoader +from voicevox_engine.setting.SettingLoader import USER_SETTING_PATH, SettingHandler from voicevox_engine.tts_pipeline.kana_converter import create_kana, parse_kana from voicevox_engine.tts_pipeline.tts_engine import ( TTSEngine, @@ -135,7 +135,7 @@ def generate_app( tts_engines: dict[str, TTSEngine], cores: dict[str, CoreAdapter], latest_core_version: str, - setting_loader: SettingLoader, + setting_loader: SettingHandler, preset_manager: PresetManager, cancellable_engine: CancellableEngine | None = None, root_dir: Optional[Path] = None, @@ -1310,7 +1310,7 @@ def setting_get(request: Request) -> Response: """ 設定ページを返します。 """ - settings = setting_loader.load_setting_file() + settings = setting_loader.load() brand_name = engine_manifest_data.brand_name cors_policy_mode = settings.cors_policy_mode @@ -1348,7 +1348,7 @@ def setting_post( ) # 更新した設定へ上書き - setting_loader.dump_setting_file(settings) + setting_loader.save(settings) return Response(status_code=204) @@ -1552,9 +1552,9 @@ def main() -> None: if root_dir is None: root_dir = engine_root() - setting_loader = SettingLoader(args.setting_file) + setting_loader = SettingHandler(args.setting_file) - settings = setting_loader.load_setting_file() + settings = setting_loader.load() cors_policy_mode: CorsPolicyMode | None = args.cors_policy_mode if cors_policy_mode is None: diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index a2979e3ba..df5bb1744 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -7,7 +7,7 @@ from voicevox_engine.core.core_initializer import initialize_cores from voicevox_engine.preset.PresetManager import PresetManager -from voicevox_engine.setting.SettingLoader import SettingLoader +from voicevox_engine.setting.SettingLoader import SettingHandler from voicevox_engine.tts_pipeline.tts_engine import make_tts_engines_from_cores from voicevox_engine.utility.core_version_utility import get_latest_core_version @@ -17,7 +17,7 @@ def app_params(): cores = initialize_cores(use_gpu=False, enable_mock=True) tts_engines = make_tts_engines_from_cores(cores) latest_core_version = get_latest_core_version(versions=list(tts_engines.keys())) - setting_loader = SettingLoader(Path("./not_exist.yaml")) + setting_loader = SettingHandler(Path("./not_exist.yaml")) preset_manager = PresetManager( # FIXME: impl MockPresetManager preset_path=Path("./presets.yaml"), ) diff --git a/test/setting/test_setting.py b/test/setting/test_setting.py index 0a05083ba..468e76b11 100644 --- a/test/setting/test_setting.py +++ b/test/setting/test_setting.py @@ -3,7 +3,7 @@ from unittest import TestCase from voicevox_engine.setting.Setting import CorsPolicyMode, Setting -from voicevox_engine.setting.SettingLoader import SettingLoader +from voicevox_engine.setting.SettingLoader import SettingHandler class TestSettingLoader(TestCase): @@ -12,8 +12,8 @@ def setUp(self): self.tmp_dir_path = Path(self.tmp_dir.name) def test_loading_1(self): - setting_loader = SettingLoader(Path("not_exist.yaml")) - settings = setting_loader.load_setting_file() + setting_loader = SettingHandler(Path("not_exist.yaml")) + settings = setting_loader.load() self.assertEqual( settings.dict(), @@ -21,10 +21,10 @@ def test_loading_1(self): ) def test_loading_2(self): - setting_loader = SettingLoader( + setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-1.yaml") ) - settings = setting_loader.load_setting_file() + settings = setting_loader.load() self.assertEqual( settings.dict(), @@ -32,10 +32,10 @@ def test_loading_2(self): ) def test_loading_3(self): - setting_loader = SettingLoader( + setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-2.yaml") ) - settings = setting_loader.load_setting_file() + settings = setting_loader.load() self.assertEqual( settings.dict(), @@ -43,10 +43,10 @@ def test_loading_3(self): ) def test_loading_4(self): - setting_loader = SettingLoader( + setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-3.yaml") ) - settings = setting_loader.load_setting_file() + settings = setting_loader.load() self.assertEqual( settings.dict(), @@ -57,15 +57,15 @@ def test_loading_4(self): ) def test_dump(self): - setting_loader = SettingLoader( + setting_loader = SettingHandler( setting_file_path=Path(self.tmp_dir_path / "setting-test-dump.yaml") ) settings = Setting(cors_policy_mode=CorsPolicyMode.localapps) - setting_loader.dump_setting_file(settings) + setting_loader.save(settings) self.assertTrue(setting_loader.setting_file_path.is_file()) self.assertEqual( - setting_loader.load_setting_file().dict(), + setting_loader.load().dict(), {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}, ) diff --git a/voicevox_engine/setting/SettingLoader.py b/voicevox_engine/setting/SettingLoader.py index 0e7e5ca90..da6e82219 100644 --- a/voicevox_engine/setting/SettingLoader.py +++ b/voicevox_engine/setting/SettingLoader.py @@ -8,7 +8,7 @@ USER_SETTING_PATH: Path = get_save_dir() / "setting.yml" -class SettingLoader: +class SettingHandler: def __init__(self, setting_file_path: Path) -> None: """ 設定ファイルの管理 @@ -19,8 +19,8 @@ def __init__(self, setting_file_path: Path) -> None: """ self.setting_file_path = setting_file_path - def load_setting_file(self) -> Setting: - # 設定値の読み込み + def load(self) -> Setting: + """設定値をファイルから読み込む。""" if not self.setting_file_path.is_file(): # 設定ファイルが存在しないためデフォルト値を取得 setting = {"allow_origin": None, "cors_policy_mode": "localapps"} @@ -34,7 +34,8 @@ def load_setting_file(self) -> Setting: allow_origin=setting["allow_origin"], ) - def dump_setting_file(self, settings: Setting) -> None: + def save(self, settings: Setting) -> None: + """設定値をファイルへ書き込む。""" settings_dict = settings.dict() with open(self.setting_file_path, mode="w", encoding="utf-8") as f: