Skip to content

Commit

Permalink
Merge branch 'master' into refactor/speaker_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
tarepan committed May 22, 2024
2 parents fcc7ec7 + 3d8b1e4 commit 3ca5320
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 109 deletions.
107 changes: 44 additions & 63 deletions build_util/generate_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ def __init__(
# ライセンステキストをローカルのライセンスファイルから抽出する
self.license_text = Path(license_text).read_text(encoding="utf8")
elif license_text_type == "remote_address":
# ライセンステキストをリモートのライセンスファイルから抽出する
with urllib.request.urlopen(license_text) as res:
_license_text: str = res.read().decode()
self.license_text = _license_text
replace_license_text(self, license_text)
else:
raise Exception("型で保護され実行されないはずのパスが実行されました")


def replace_license_text(license: License, text_url: str) -> None:
"""ライセンステキストを URL が指すテキストで置き換える。"""
with urllib.request.urlopen(text_url) as res:
license.license_text = res.read().decode()


def generate_licenses() -> list[License]:
licenses: list[License] = []

Expand Down Expand Up @@ -81,73 +84,51 @@ def generate_licenses() -> list[License]:
raise LicenseError(
f"ライセンス違反: {license.package_name} is {license.license_name}"
)

package_name = license.package_name.lower()

# FIXME: assert license type
if license.license_text == "UNKNOWN":
if (
license.package_name.lower() == "core"
and license.package_version == "0.0.0"
):
if package_name == "core" and license.package_version == "0.0.0":
continue
elif license.package_name.lower() == "future":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/PythonCharmers/python-future/master/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "pefile":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/erocarrera/pefile/master/LICENSE" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "pyopenjtalk":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/LICENSE.md"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "python-multipart":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/andrew-d/python-multipart/master/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "romkan":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/soimort/python-romkan/master/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "distlib":
with urllib.request.urlopen(
"https://bitbucket.org/pypa/distlib/raw/7d93712134b28401407da27382f2b6236c87623a/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "jsonschema":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/python-jsonschema/jsonschema/dbc398245a583cb2366795dc529ae042d10c1577/COPYING"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "lockfile":
with urllib.request.urlopen(
"https://opendev.org/openstack/pylockfile/raw/tag/0.12.2/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "platformdirs":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/platformdirs/platformdirs/aa671aaa97913c7b948567f4d9c77d4f98bfa134/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "webencodings":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/gsnedders/python-webencodings/fa2cb5d75ab41e63ace691bc0825d3432ba7d694/LICENSE"
) as res:
license.license_text = res.read().decode()
elif package_name == "future":
text_url = "https://raw.githubusercontent.com/PythonCharmers/python-future/master/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "pefile":
text_url = "https://raw.githubusercontent.com/erocarrera/pefile/master/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "pyopenjtalk":
text_url = "https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/LICENSE.md" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "python-multipart":
text_url = "https://raw.githubusercontent.com/andrew-d/python-multipart/master/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "romkan":
text_url = "https://raw.githubusercontent.com/soimort/python-romkan/master/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "distlib":
text_url = "https://bitbucket.org/pypa/distlib/raw/7d93712134b28401407da27382f2b6236c87623a/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "jsonschema":
text_url = "https://raw.githubusercontent.com/python-jsonschema/jsonschema/dbc398245a583cb2366795dc529ae042d10c1577/COPYING" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "lockfile":
text_url = "https://opendev.org/openstack/pylockfile/raw/tag/0.12.2/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "platformdirs":
text_url = "https://raw.githubusercontent.com/platformdirs/platformdirs/aa671aaa97913c7b948567f4d9c77d4f98bfa134/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "webencodings":
text_url = "https://raw.githubusercontent.com/gsnedders/python-webencodings/fa2cb5d75ab41e63ace691bc0825d3432ba7d694/LICENSE" # noqa: B950
replace_license_text(license, text_url)
else:
# ライセンスがpypiに無い
raise Exception(f"No License info provided for {license.package_name}")

# soxr
if license.package_name.lower() == "soxr":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/dofuuz/python-soxr/v0.3.6/LICENSE.txt"
) as res:
license.license_text = res.read().decode()
if package_name == "soxr":
text_url = "https://raw.githubusercontent.com/dofuuz/python-soxr/v0.3.6/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)

licenses.append(license)

Expand Down
4 changes: 1 addition & 3 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.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 Expand Up @@ -47,8 +47,6 @@ def generate_app(

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

user_dict.update_dict()

app = FastAPI(
title=engine_manifest_data.name,
description=f"{engine_manifest_data.brand_name} の音声合成エンジンです。",
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.

1 change: 1 addition & 0 deletions voicevox_engine/user_dict/user_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def __init__(
self._default_dict_path = default_dict_path
self._user_dict_path = user_dict_path
self._compiled_dict_path = compiled_dict_path
self.update_dict()

def update_dict(self) -> None:
"""辞書を更新する。"""
Expand Down

0 comments on commit 3ca5320

Please sign in to comment.