From df01f98e1765fd612b83866928f6600e7cb9ac3b Mon Sep 17 00:00:00 2001 From: aoirint Date: Sat, 15 Apr 2023 09:10:25 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E6=8E=A8=E5=A5=A8=E5=8C=96=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9Fdistutils.version=E3=81=B8=E3=81=AE=E4=BE=9D?= =?UTF-8?q?=E5=AD=98=E3=82=92=E3=81=AA=E3=81=8F=E3=81=97=E3=80=81python-se?= =?UTF-8?q?mver=E3=81=AB=E7=A7=BB=E8=A1=8C=E3=81=99=E3=82=8B=20(#609)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hiroshiba --- poetry.lock | 16 +++++++- pyproject.toml | 1 + requirements-dev.txt | 1 + requirements-license.txt | 1 + requirements-test.txt | 1 + requirements.txt | 1 + run.py | 4 +- test/test_core_version_utility.py | 40 +++++++++++++++++++ voicevox_engine/cancellable_engine.py | 4 +- voicevox_engine/utility/__init__.py | 3 ++ .../utility/core_version_utility.py | 14 +++++++ 11 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 test/test_core_version_utility.py create mode 100644 voicevox_engine/utility/core_version_utility.py diff --git a/poetry.lock b/poetry.lock index 4265a41..f86ac75 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "aiofiles" @@ -2669,6 +2669,18 @@ files = [ cryptography = ">=2.0" jeepney = ">=0.6" +[[package]] +name = "semver" +version = "3.0.1" +description = "Python helper for Semantic Versioning (https://semver.org)" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "semver-3.0.1-py3-none-any.whl", hash = "sha256:2a23844ba1647362c7490fe3995a86e097bb590d16f0f32dfc383008f19e4cdf"}, + {file = "semver-3.0.1.tar.gz", hash = "sha256:9ec78c5447883c67b97f98c3b6212796708191d22e4ad30f4570f840171cbce1"}, +] + [[package]] name = "sentencepiece" version = "0.1.97" @@ -3198,4 +3210,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "~3.8,>=3.8.1" -content-hash = "27d4e42a1892db0eee918e34ca89f3a41fd06286d87f46727270456597d5388a" +content-hash = "1419dcaf985eef7a4e96856f63752006f556cc0dcbe508897569600fbd9ebb18" diff --git a/pyproject.toml b/pyproject.toml index d79d107..c71a4ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,7 @@ requests = "^2.28.1" jinja2 = "^3.1.2" pyopenjtalk = {git = "https://github.com/VOICEVOX/pyopenjtalk", rev = "f4ade29ef9a4f43d8605103cb5bacc29e0b2ccae"} espnet = {git = "https://github.com/voicevox-bridge/espnet", rev = "d7633eb0eec9b00646847abdee3d34e5a62d2dea"} +semver = "^3.0.1" [tool.poetry.group.dev.dependencies] cython = "^0.29.24" diff --git a/requirements-dev.txt b/requirements-dev.txt index 8b42328..2e670fc 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -91,6 +91,7 @@ resampy==0.4.2 ; python_full_version >= "3.8.1" and python_version < "3.9" scikit-learn==1.2.0 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.7.1 ; python_full_version >= "3.8.1" and python_version < "3.9" secretstorage==3.3.3 ; python_full_version >= "3.8.1" and python_version < "3.9" and sys_platform == "linux" +semver==3.0.1 ; python_full_version >= "3.8.1" and python_version < "3.9" sentencepiece==0.1.97 ; python_full_version >= "3.8.1" and python_version < "3.9" setuptools==65.6.3 ; python_full_version >= "3.8.1" and python_version < "3.9" shellingham==1.5.0.post1 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements-license.txt b/requirements-license.txt index 0d21bde..98b7295 100644 --- a/requirements-license.txt +++ b/requirements-license.txt @@ -58,6 +58,7 @@ requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" resampy==0.4.2 ; python_full_version >= "3.8.1" and python_version < "3.9" scikit-learn==1.2.0 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.7.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.1 ; python_full_version >= "3.8.1" and python_version < "3.9" sentencepiece==0.1.97 ; python_full_version >= "3.8.1" and python_version < "3.9" setuptools==65.6.3 ; python_full_version >= "3.8.1" and python_version < "3.9" six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements-test.txt b/requirements-test.txt index 8b4e7ed..6f7c5ff 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -81,6 +81,7 @@ requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" resampy==0.4.2 ; python_full_version >= "3.8.1" and python_version < "3.9" scikit-learn==1.2.0 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.7.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.1 ; python_full_version >= "3.8.1" and python_version < "3.9" sentencepiece==0.1.97 ; python_full_version >= "3.8.1" and python_version < "3.9" setuptools==65.6.3 ; python_full_version >= "3.8.1" and python_version < "3.9" six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements.txt b/requirements.txt index 38f4065..050b073 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,6 +56,7 @@ requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" resampy==0.4.2 ; python_full_version >= "3.8.1" and python_version < "3.9" scikit-learn==1.2.0 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.7.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.1 ; python_full_version >= "3.8.1" and python_version < "3.9" sentencepiece==0.1.97 ; python_full_version >= "3.8.1" and python_version < "3.9" setuptools==65.6.3 ; python_full_version >= "3.8.1" and python_version < "3.9" six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/run.py b/run.py index ec8dc42..ee2e9c4 100644 --- a/run.py +++ b/run.py @@ -8,7 +8,6 @@ import sys import traceback import zipfile -from distutils.version import LooseVersion from io import BytesIO, TextIOWrapper from pathlib import Path from tempfile import NamedTemporaryFile, TemporaryFile @@ -68,6 +67,7 @@ connect_base64_waves, delete_file, engine_root, + get_latest_core_version, get_save_dir, ) @@ -1143,7 +1143,7 @@ def setting_post( bridge_config_loader=bridge_config_loader, ) 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 diff --git a/test/test_core_version_utility.py b/test/test_core_version_utility.py new file mode 100644 index 0000000..e96ba80 --- /dev/null +++ b/test/test_core_version_utility.py @@ -0,0 +1,40 @@ +from unittest import TestCase + +from voicevox_engine.utility import get_latest_core_version, parse_core_version + + +class TestCoreVersion(TestCase): + def test_parse_core_version(self): + parse_core_version("0.0.0") + parse_core_version("0.1.0") + parse_core_version("0.10.0") + parse_core_version("0.10.0-preview.1") + parse_core_version("0.14.0") + parse_core_version("0.14.0-preview.1") + parse_core_version("0.14.0-preview.10") + + def test_get_latest_core_version(self): + self.assertEqual( + get_latest_core_version( + versions=[ + "0.0.0", + "0.1.0", + "0.10.0", + "0.10.0-preview.1", + "0.14.0", + "0.14.0-preview.1", + "0.14.0-preview.10", + ] + ), + "0.14.0", + ) + + self.assertEqual( + get_latest_core_version( + versions=[ + "0.14.0", + "0.15.0-preview.1", + ] + ), + "0.15.0-preview.1", + ) diff --git a/voicevox_engine/cancellable_engine.py b/voicevox_engine/cancellable_engine.py index db8ccbd..1bedb3f 100644 --- a/voicevox_engine/cancellable_engine.py +++ b/voicevox_engine/cancellable_engine.py @@ -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 @@ -14,6 +13,7 @@ from .model import AudioQuery from .synthesis_engine import make_synthesis_engines +from .utility import get_latest_core_version class CancellableEngine: @@ -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() diff --git a/voicevox_engine/utility/__init__.py b/voicevox_engine/utility/__init__.py index e7dcd9e..a5d0f0a 100644 --- a/voicevox_engine/utility/__init__.py +++ b/voicevox_engine/utility/__init__.py @@ -3,6 +3,7 @@ connect_base64_waves, decode_base64_waves, ) +from .core_version_utility import get_latest_core_version, parse_core_version from .mutex_utility import mutex_wrapper from .path_utility import delete_file, engine_root from .save_dir import get_save_dir @@ -11,6 +12,8 @@ "ConnectBase64WavesException", "connect_base64_waves", "decode_base64_waves", + "get_latest_core_version", + "parse_core_version", "delete_file", "engine_root", "get_save_dir", diff --git a/voicevox_engine/utility/core_version_utility.py b/voicevox_engine/utility/core_version_utility.py new file mode 100644 index 0000000..25f2d3a --- /dev/null +++ b/voicevox_engine/utility/core_version_utility.py @@ -0,0 +1,14 @@ +from typing import Iterable + +from semver.version import Version + + +def parse_core_version(version: str) -> Version: + return Version.parse(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)))