Skip to content

Commit

Permalink
非推奨化されたdistutils.versionへの依存をなくし、python-semverに移行する (#609)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
  • Loading branch information
aoirint and Hiroshiba committed Apr 15, 2023
1 parent fa8ecee commit 69c77cc
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 5 deletions.
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-license.txt
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions run.py
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +75,7 @@
connect_base64_waves,
delete_file,
engine_root,
get_latest_core_version,
get_save_dir,
)

Expand Down Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions 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",
)
4 changes: 2 additions & 2 deletions 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
Expand All @@ -14,6 +13,7 @@

from .model import AudioQuery
from .synthesis_engine import make_synthesis_engines
from .utility 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
3 changes: 3 additions & 0 deletions voicevox_engine/utility/__init__.py
Expand Up @@ -3,13 +3,16 @@
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

__all__ = [
"ConnectBase64WavesException",
"connect_base64_waves",
"decode_base64_waves",
"get_latest_core_version",
"parse_core_version",
"delete_file",
"engine_root",
"get_save_dir",
Expand Down
14 changes: 14 additions & 0 deletions 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)))

0 comments on commit 69c77cc

Please sign in to comment.