From 69c77cce444c6f68f9d75e80b36fee08c800bfc0 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 | 14 ++++++- 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, 79 insertions(+), 5 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 c81248fc1..a94be0b7b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2062,6 +2062,18 @@ files = [ cryptography = ">=2.0" jeepney = ">=0.6" +[[package]] +name = "semver" +version = "3.0.0" +description = "Python helper for Semantic Versioning (https://semver.org)" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "semver-3.0.0-py3-none-any.whl", hash = "sha256:ab4f69fb1d1ecfb5d81f96411403d7a611fa788c45d252cf5b408025df3ab6ce"}, + {file = "semver-3.0.0.tar.gz", hash = "sha256:94df43924c4521ec7d307fc86da1531db6c2c33d9d5cdc3e64cca0eb68569269"}, +] + [[package]] name = "setuptools" version = "65.6.3" @@ -2433,4 +2445,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "~3.8,>=3.8.1" -content-hash = "158fac100f2abb9798b82d98da795ca62c7f0933b668cc92a6ee018aa0ddcc31" +content-hash = "9e8c131481abd5ada5277fb236b418d9925e62a4a5f781b0476b872cff8b3083" diff --git a/pyproject.toml b/pyproject.toml index c9e48ea9f..1a7631bb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ appdirs = "^1.4.4" requests = "^2.28.1" jinja2 = "^3.1.2" pyopenjtalk = {git = "https://github.com/VOICEVOX/pyopenjtalk", rev = "827a3fc5c7dda7bbe832c0c69da98e39cc8cb2c3"} +semver = "^3.0.0" [tool.poetry.group.dev.dependencies] cython = "^0.29.24" diff --git a/requirements-dev.txt b/requirements-dev.txt index b8b5247c0..71ce3b6bb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -65,6 +65,7 @@ requests-toolbelt==0.10.1 ; python_full_version >= "3.8.1" and python_version < requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.10.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.0 ; 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" six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements-license.txt b/requirements-license.txt index 5dc77f684..d829cf97b 100644 --- a/requirements-license.txt +++ b/requirements-license.txt @@ -24,6 +24,7 @@ pyworld==0.3.2 ; python_full_version >= "3.8.1" and python_version < "3.9" pyyaml==6.0 ; python_full_version >= "3.8.1" and python_version < "3.9" requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.10.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.0 ; 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" sniffio==1.3.0 ; python_full_version >= "3.8.1" and python_version < "3.9" soundfile==0.10.3.post1 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements-test.txt b/requirements-test.txt index c0996f4a7..1ec27d138 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -48,6 +48,7 @@ pyworld==0.3.2 ; python_full_version >= "3.8.1" and python_version < "3.9" pyyaml==6.0 ; python_full_version >= "3.8.1" and python_version < "3.9" requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.10.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.0 ; 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" smmap==5.0.0 ; python_full_version >= "3.8.1" and python_version < "3.9" sniffio==1.3.0 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/requirements.txt b/requirements.txt index eaff7128a..9b4799f72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ pyworld==0.3.2 ; python_full_version >= "3.8.1" and python_version < "3.9" pyyaml==6.0 ; python_full_version >= "3.8.1" and python_version < "3.9" requests==2.28.1 ; python_full_version >= "3.8.1" and python_version < "3.9" scipy==1.10.1 ; python_full_version >= "3.8.1" and python_version < "3.9" +semver==3.0.0 ; 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" sniffio==1.3.0 ; python_full_version >= "3.8.1" and python_version < "3.9" soundfile==0.10.3.post1 ; python_full_version >= "3.8.1" and python_version < "3.9" diff --git a/run.py b/run.py index f3d78941f..f989d9266 100644 --- a/run.py +++ b/run.py @@ -8,7 +8,6 @@ import sys import traceback import zipfile -from distutils.version import LooseVersion from functools import lru_cache from io import BytesIO, TextIOWrapper from pathlib import Path @@ -76,6 +75,7 @@ connect_base64_waves, delete_file, engine_root, + get_latest_core_version, get_save_dir, ) @@ -1205,7 +1205,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: diff --git a/test/test_core_version_utility.py b/test/test_core_version_utility.py new file mode 100644 index 000000000..e96ba8009 --- /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 db8ccbd76..1bedb3ff3 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 867134648..d40fea3e6 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, get_save_dir @@ -10,6 +11,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 000000000..25f2d3a3e --- /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)))