Skip to content

Commit

Permalink
整理: エンジンマニフェストを generate_app() 引数へ切り出し (#1257)
Browse files Browse the repository at this point in the history
refactor: engine_manifest を引数へ切り出し
  • Loading branch information
tarepan authored May 25, 2024
1 parent 2f22130 commit 7d59cfb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions build_util/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from voicevox_engine.core.core_initializer import CoreManager
from voicevox_engine.dev.core.mock import MockCoreWrapper
from voicevox_engine.dev.tts_engine.mock import MockTTSEngine
from voicevox_engine.engine_manifest.EngineManifest import load_manifest
from voicevox_engine.preset.PresetManager import PresetManager
from voicevox_engine.setting.Setting import USER_SETTING_PATH, SettingHandler
from voicevox_engine.tts_pipeline.tts_engine import TTSEngineManager
Expand Down Expand Up @@ -51,6 +52,7 @@ def generate_api_docs_html(schema: str) -> str:
preset_path=engine_root() / "presets.yaml",
),
user_dict=UserDictionary(),
engine_manifest=load_manifest(engine_root() / "engine_manifest.json"),
)
api_schema = json.dumps(app.openapi())

Expand Down
4 changes: 4 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from voicevox_engine.app.application import generate_app
from voicevox_engine.cancellable_engine import CancellableEngine
from voicevox_engine.core.core_initializer import initialize_cores
from voicevox_engine.engine_manifest.EngineManifest import load_manifest
from voicevox_engine.preset.PresetManager import PresetManager
from voicevox_engine.setting.Setting import (
USER_SETTING_PATH,
Expand Down Expand Up @@ -322,6 +323,8 @@ def main() -> None:

use_dict = UserDictionary()

engine_manifest = load_manifest(engine_root() / "engine_manifest.json")

if arg_disable_mutable_api:
disable_mutable_api = True
else:
Expand All @@ -335,6 +338,7 @@ def main() -> None:
setting_loader,
preset_manager,
use_dict,
engine_manifest,
cancellable_engine,
root_dir,
cors_policy_mode,
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

from voicevox_engine.app.application import generate_app
from voicevox_engine.core.core_initializer import initialize_cores
from voicevox_engine.engine_manifest.EngineManifest import load_manifest
from voicevox_engine.preset.PresetManager import PresetManager
from voicevox_engine.setting.Setting import SettingHandler
from voicevox_engine.tts_pipeline.tts_engine import make_tts_engines_from_cores
from voicevox_engine.user_dict.user_dict import UserDictionary
from voicevox_engine.utility.path_utility import engine_root


@pytest.fixture()
Expand All @@ -26,7 +28,9 @@ def app_params(tmp_path: Path) -> dict[str, Any]:
preset_path = tmp_path / "presets.yaml"
shutil.copyfile(original_preset_path, preset_path)
preset_manager = PresetManager(preset_path)

user_dict = UserDictionary()
engine_manifest = load_manifest(engine_root() / "engine_manifest.json")

return {
"tts_engines": tts_engines,
Expand All @@ -35,6 +39,7 @@ def app_params(tmp_path: Path) -> dict[str, Any]:
"setting_loader": setting_loader,
"preset_manager": preset_manager,
"user_dict": user_dict,
"engine_manifest": engine_manifest,
}


Expand Down
29 changes: 13 additions & 16 deletions voicevox_engine/app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from voicevox_engine.app.routers.user_dict import generate_user_dict_router
from voicevox_engine.cancellable_engine import CancellableEngine
from voicevox_engine.core.core_initializer import CoreManager
from voicevox_engine.engine_manifest.EngineManifest import load_manifest
from voicevox_engine.engine_manifest.EngineManifest import EngineManifest
from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.metas.MetasStore import MetasStore
from voicevox_engine.preset.PresetManager import PresetManager
Expand All @@ -34,6 +34,7 @@ def generate_app(
setting_loader: SettingHandler,
preset_manager: PresetManager,
user_dict: UserDictionary,
engine_manifest: EngineManifest,
cancellable_engine: CancellableEngine | None = None,
root_dir: Path | None = None,
cors_policy_mode: CorsPolicyMode = CorsPolicyMode.localapps,
Expand All @@ -44,11 +45,9 @@ def generate_app(
if root_dir is None:
root_dir = engine_root()

engine_manifest_data = load_manifest(engine_root() / "engine_manifest.json")

app = FastAPI(
title=engine_manifest_data.name,
description=f"{engine_manifest_data.brand_name} の音声合成エンジンです。",
title=engine_manifest.name,
description=f"{engine_manifest.brand_name} の音声合成エンジンです。",
version=__version__,
)
app = configure_middlewares(app, cors_policy_mode, allow_origin)
Expand All @@ -58,10 +57,10 @@ def generate_app(

library_manager = LibraryManager(
get_save_dir() / "installed_libraries",
engine_manifest_data.supported_vvlib_manifest_version,
engine_manifest_data.brand_name,
engine_manifest_data.name,
engine_manifest_data.uuid,
engine_manifest.supported_vvlib_manifest_version,
engine_manifest.brand_name,
engine_manifest.name,
engine_manifest.uuid,
)

metas_store = MetasStore(root_dir / "speaker_info")
Expand All @@ -74,14 +73,12 @@ def generate_app(
app.include_router(generate_morphing_router(tts_engines, core_manager, metas_store))
app.include_router(generate_preset_router(preset_manager))
app.include_router(generate_speaker_router(core_manager, metas_store, root_dir))
if engine_manifest_data.supported_features.manage_library:
app.include_router(
generate_library_router(engine_manifest_data, library_manager)
)
if engine_manifest.supported_features.manage_library:
app.include_router(generate_library_router(engine_manifest, library_manager))
app.include_router(generate_user_dict_router(user_dict))
app.include_router(generate_engine_info_router(core_manager, engine_manifest_data))
app.include_router(generate_setting_router(setting_loader, engine_manifest_data))
app.include_router(generate_portal_page_router(engine_manifest_data))
app.include_router(generate_engine_info_router(core_manager, engine_manifest))
app.include_router(generate_setting_router(setting_loader, engine_manifest))
app.include_router(generate_portal_page_router(engine_manifest))

app = configure_openapi_schema(app)

Expand Down

0 comments on commit 7d59cfb

Please sign in to comment.