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 16 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
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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 functools import lru_cache
from io import BytesIO, TextIOWrapper
from pathlib import Path
Expand Down Expand Up @@ -78,6 +77,7 @@
engine_root,
get_save_dir,
)
from voicevox_engine.utility.core_version_utility import get_latest_core_version


def b64encode_str(s):
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
41 changes: 41 additions & 0 deletions test/test_core_version_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from unittest import TestCase

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


class TestCoreVersion(TestCase):
aoirint marked this conversation as resolved.
Show resolved Hide resolved
def test_parse_core_version(self):
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.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.core_version_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
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_utility
aoirint marked this conversation as resolved.
Show resolved Hide resolved
from .connect_base64_waves import (
ConnectBase64WavesException,
connect_base64_waves,
Expand All @@ -10,6 +11,7 @@
"ConnectBase64WavesException",
"connect_base64_waves",
"decode_base64_waves",
"core_version_utility",
"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)))