Skip to content

Commit

Permalink
整理: EngineManifest 系モジュールを統合 (VOICEVOX#1255)
Browse files Browse the repository at this point in the history
refactor: EngineManifest 系モジュールを統合

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
tarepan and Hiroshiba authored May 22, 2024
1 parent b57be2d commit d9dd729
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion 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.EngineManifestLoader import load_manifest
from voicevox_engine.engine_manifest.EngineManifest import load_manifest
from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.metas.MetasStore import MetasStore
from voicevox_engine.preset.PresetManager import PresetManager
Expand Down
42 changes: 42 additions & 0 deletions voicevox_engine/engine_manifest/EngineManifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# エラーを吐いて表示が崩壊する可能性がある。これを防止するため、EngineManifest関連の定義を
# 変更する際は、Optionalにする必要があることに留意しなければならない。

import json
from base64 import b64encode
from pathlib import Path

from pydantic import BaseModel, Field


Expand Down Expand Up @@ -68,3 +72,41 @@ class EngineManifest(BaseModel):
title="エンジンが対応するvvlibのバージョン"
)
supported_features: SupportedFeatures = Field(title="エンジンが持つ機能")


def load_manifest(manifest_path: Path) -> EngineManifest:
"""エンジンマニフェストを指定ファイルから読み込む。"""

root_dir = manifest_path.parent
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
return EngineManifest(
manifest_version=manifest["manifest_version"],
name=manifest["name"],
brand_name=manifest["brand_name"],
uuid=manifest["uuid"],
url=manifest["url"],
default_sampling_rate=manifest["default_sampling_rate"],
frame_rate=manifest["frame_rate"],
icon=b64encode((root_dir / manifest["icon"]).read_bytes()).decode("utf-8"),
terms_of_service=(root_dir / manifest["terms_of_service"]).read_text("utf-8"),
update_infos=[
UpdateInfo(**update_info)
for update_info in json.loads(
(root_dir / manifest["update_infos"]).read_text("utf-8")
)
],
# supported_vvlib_manifest_versionを持たないengine_manifestのために
# キーが存在しない場合はNoneを返すgetを使う
supported_vvlib_manifest_version=manifest.get(
"supported_vvlib_manifest_version"
),
dependency_licenses=[
LicenseInfo(**license_info)
for license_info in json.loads(
(root_dir / manifest["dependency_licenses"]).read_text("utf-8")
)
],
supported_features={
key: item["value"] for key, item in manifest["supported_features"].items()
},
)
43 changes: 0 additions & 43 deletions voicevox_engine/engine_manifest/EngineManifestLoader.py

This file was deleted.

0 comments on commit d9dd729

Please sign in to comment.