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
2 people authored and takana-v committed Sep 17, 2023
1 parent 32d6c5d commit df01f98
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 6 deletions.
16 changes: 14 additions & 2 deletions 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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +67,7 @@
connect_base64_waves,
delete_file,
engine_root,
get_latest_core_version,
get_save_dir,
)

Expand Down Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions test/test_core_version_utility.py
Original file line number Diff line number Diff line change
@@ -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
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 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions voicevox_engine/utility/core_version_utility.py
Original file line number Diff line number Diff line change
@@ -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 df01f98

Please sign in to comment.