Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: エンジンマニフェストをマージするためのスクリプトを追加 #1482

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions tools/merge_engine_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
エンジンマニフェストをマージする。
"""

import argparse
import json
from pathlib import Path

JsonValue = str | int | float


def merge_json_string(src: str, dst: str) -> str:
src_json: dict[str, JsonValue | dict[str, dict]] = json.loads(src)
dst_json: dict[str, JsonValue | dict[str, dict]] = json.loads(dst)

for key, dst_value in dst_json.items():
assert key in src_json, f"Key {key} is not found in src_json"

# `manage_library` のみdictなので特別に処理
if key == "supported_features":
assert isinstance(dst_value, dict)

src_value = src_json[key]
assert isinstance(src_value, dict)
src_value.update(dst_value)

else:
src_value = src_json[key]
assert isinstance(src_value, JsonValue)
assert isinstance(dst_value, JsonValue)
src_json[key] = dst_value

return json.dumps(src_json, ensure_ascii=False)


def merge_engine_manifest(src_path: Path, dst_path: Path, output_path: Path) -> None:
src = src_path.read_text(encoding="utf-8")
dst = dst_path.read_text(encoding="utf-8")
merged = merge_json_string(src, dst)
output_path.write_text(merged, encoding="utf-8")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("src_path", type=Path)
parser.add_argument("dst_path", type=Path)
parser.add_argument("output_path", type=Path)
args = parser.parse_args()
merge_engine_manifest(args.src_path, args.dst_path, args.output_path)
4 changes: 2 additions & 2 deletions tools/merge_update_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def merge_json_string(src: str, dst: str) -> str:
# 異なるものがあった場合だけ後ろに付け足す
src_item[key] = list(OrderedDict.fromkeys(src_value + dst_value))

return json.dumps(src_json)
return json.dumps(src_json, ensure_ascii=False)


def merge_update_infos(src_path: Path, dst_path: Path, output_path: Path) -> None:
src = src_path.read_text(encoding="utf-8")
dst = dst_path.read_text(encoding="utf-8")
merged = merge_json_string(src, dst)
output_path.write_text(merged)
output_path.write_text(merged, encoding="utf-8")


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions tools/process_voicevox_resource.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ cp -r "${DOWNLOAD_RESOURCE_PATH}/character_info" resources/character_info
python "${DOWNLOAD_RESOURCE_PATH}/scripts/clean_character_info.py" \
--character_info_dir resources/character_info/

# エンジンマニフェストに含まれるダミーの情報を上書きする
jq -s '.[0] * .[1]' engine_manifest.json "${DOWNLOAD_RESOURCE_PATH}/engine/engine_manifest.json" \
> engine_manifest.json.tmp
mv engine_manifest.json.tmp engine_manifest.json
# エンジンマニフェストを統合する
python tools/merge_engine_manifest.py \
engine_manifest.json \
"${DOWNLOAD_RESOURCE_PATH}/engine/engine_manifest.json" \
engine_manifest.json

# エンジンとリソースの更新情報を統合する
python tools/merge_update_infos.py \
Expand Down