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

非推奨化されたdistutils.versionへの依存をなくし、python-semverに移行する #609

Merged
merged 19 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import traceback
import zipfile
from distutils.version import LooseVersion
from functools import lru_cache
from io import TextIOWrapper
from pathlib import Path
Expand Down Expand Up @@ -78,6 +77,7 @@
delete_file,
engine_root,
)
from voicevox_engine.utility.core_version import get_latest_core_version


def b64encode_str(s):
Expand Down Expand Up @@ -1176,7 +1176,7 @@ def setting_post(
load_all_models=args.load_all_models,
)
assert len(synthesis_engines) != 0, "音声合成エンジンがありません。"
latest_core_version = str(max([LooseVersion(ver) for ver in synthesis_engines]))
latest_core_version = get_latest_core_version(versions=synthesis_engines.keys())

cancellable_engine = None
if args.enable_cancellable_synthesis:
Expand Down
31 changes: 31 additions & 0 deletions test/test_core_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from unittest import TestCase

from voicevox_engine.utility.core_version import (
get_latest_core_version,
parse_core_version,
)


class TestCoreVersion(TestCase):
def test_parse_core_version(self):
parse_core_version("0.1.0")
parse_core_version("0.10.preview.1")
parse_core_version("0.10.0")
parse_core_version("0.14.0")
parse_core_version("0.14.0.preview.1")
parse_core_version("0.14.0.preview.10")
aoirint marked this conversation as resolved.
Show resolved Hide resolved

def test_get_latest_core_version(self):
self.assertEqual(
get_latest_core_version(
aoirint marked this conversation as resolved.
Show resolved Hide resolved
versions=[
"0.1.0",
"0.10.preview.1",
"0.10.0",
"0.14.0",
"0.14.0.preview.1",
"0.14.0.preview.10",
]
),
"0.14.0",
)
4 changes: 2 additions & 2 deletions voicevox_engine/cancellable_engine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import asyncio
import queue
from distutils.version import LooseVersion
from multiprocessing import Pipe, Process
from multiprocessing.connection import Connection
from tempfile import NamedTemporaryFile
Expand All @@ -14,6 +13,7 @@

from .model import AudioQuery
from .synthesis_engine import make_synthesis_engines
from .utility.core_version import get_latest_core_version


class CancellableEngine:
Expand Down Expand Up @@ -197,7 +197,7 @@ def start_synthesis_subprocess(
enable_mock=args.enable_mock,
)
assert len(synthesis_engines) != 0, "音声合成エンジンがありません。"
latest_core_version = str(max([LooseVersion(ver) for ver in synthesis_engines]))
latest_core_version = get_latest_core_version(versions=synthesis_engines.keys())
while True:
try:
query, speaker_id, core_version = sub_proc_con.recv()
Expand Down
2 changes: 2 additions & 0 deletions voicevox_engine/utility/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import core_version
from .connect_base64_waves import (
ConnectBase64WavesException,
connect_base64_waves,
Expand All @@ -9,6 +10,7 @@
"ConnectBase64WavesException",
"connect_base64_waves",
"decode_base64_waves",
"core_version",
aoirint marked this conversation as resolved.
Show resolved Hide resolved
"delete_file",
"engine_root",
"get_save_dir",
Expand Down
15 changes: 15 additions & 0 deletions voicevox_engine/utility/core_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Iterable

from packaging.version import Version
from packaging.version import parse as parse_version


def parse_core_version(version: str) -> Version:
return parse_version(version)


def get_latest_core_version(versions: Iterable[str]) -> str:
if len(versions) == 0:
raise Exception("versions must be non-empty.")

return str(max(map(parse_core_version, versions)))