From 3f3bfbea107daf29d88a5b1634bf3070a70cb36f Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sun, 21 Jan 2024 17:00:39 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"BLD:=20PyInstaller=E3=82=92v6?= =?UTF-8?q?=E3=81=B8=E6=9B=B4=E6=96=B0=20(#857)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4ef4218822de666ea1272338061a14ffd8f690a3. --- .github/workflows/build.yml | 8 +-- poetry.lock | 61 +++++++++-------- pyproject.toml | 2 +- requirements-dev.txt | 10 +-- run.py | 3 +- run.spec | 88 ++++++++++--------------- voicevox_engine/user_dict.py | 4 +- voicevox_engine/utility/__init__.py | 5 +- voicevox_engine/utility/path_utility.py | 51 ++++---------- 9 files changed, 94 insertions(+), 138 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45cde827c..d16170dd6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -464,10 +464,10 @@ jobs: LIBONNXRUNTIME_PATH=download/onnxruntime/lib/libonnxruntime.so fi - pyinstaller --noconfirm run.spec -- \ - --libcore_path="$LIBCORE_PATH" \ - --libonnxruntime_path="$LIBONNXRUNTIME_PATH" \ - --core_model_dir_path="download/core/model" + CORE_MODEL_DIR_PATH="download/core/model" \ + LIBCORE_PATH="$LIBCORE_PATH" \ + LIBONNXRUNTIME_PATH="$LIBONNXRUNTIME_PATH" \ + pyinstaller --noconfirm run.spec - name: Gather DLL dependencies to dist/run/ (Windows) if: startsWith(matrix.os, 'windows-') diff --git a/poetry.lock b/poetry.lock index c36d1a59d..f32b58cd3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "altgraph" -version = "0.17.4" +version = "0.17.3" description = "Python graph (network) package" optional = false python-versions = "*" files = [ - {file = "altgraph-0.17.4-py2.py3-none-any.whl", hash = "sha256:642743b4750de17e655e6711601b077bc6598dbfa3ba5fa2b2a35ce12b508dff"}, - {file = "altgraph-0.17.4.tar.gz", hash = "sha256:1b5afbb98f6c4dcadb2e2ae6ab9fa994bbb8c1d75f4fa96d340f9437ae454406"}, + {file = "altgraph-0.17.3-py2.py3-none-any.whl", hash = "sha256:c8ac1ca6772207179ed8003ce7687757c04b0b71536f81e2ac5755c6226458fe"}, + {file = "altgraph-0.17.3.tar.gz", hash = "sha256:ad33358114df7c9416cdb8fa1eaa5852166c505118717021c6a8c7c7abbd03dd"}, ] [[package]] @@ -1009,13 +1009,13 @@ testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", [[package]] name = "macholib" -version = "1.16.3" +version = "1.16.2" description = "Mach-O header analysis and editing" optional = false python-versions = "*" files = [ - {file = "macholib-1.16.3-py2.py3-none-any.whl", hash = "sha256:0e315d7583d38b8c77e815b1ecbdbf504a8258d8b3e17b61165c6feb60d18f2c"}, - {file = "macholib-1.16.3.tar.gz", hash = "sha256:07ae9e15e8e4cd9a788013d81f5908b3609aa76f9b1421bae9c4d7606ec86a30"}, + {file = "macholib-1.16.2-py2.py3-none-any.whl", hash = "sha256:44c40f2cd7d6726af8fa6fe22549178d3a4dfecc35a9cd15ea916d9c83a688e0"}, + {file = "macholib-1.16.2.tar.gz", hash = "sha256:557bbfa1bb255c20e9abafe7ed6cd8046b48d9525db2f9b77d3122a63a2a8bf8"}, ] [package.dependencies] @@ -1601,47 +1601,46 @@ files = [ [[package]] name = "pyinstaller" -version = "6.2.0" +version = "5.13.2" description = "PyInstaller bundles a Python application and all its dependencies into a single package." optional = false -python-versions = "<3.13,>=3.8" +python-versions = "<3.13,>=3.7" files = [ - {file = "pyinstaller-6.2.0-py3-none-macosx_10_13_universal2.whl", hash = "sha256:a1adbd3cf25dc90926d783eae0f444d65cdfecc7bcdf6da522c3ae3ff47b4c25"}, - {file = "pyinstaller-6.2.0-py3-none-manylinux2014_aarch64.whl", hash = "sha256:29d164394f1e949072f78a64c1e040f1c47b7f4aff08514c7666a031c8b44996"}, - {file = "pyinstaller-6.2.0-py3-none-manylinux2014_i686.whl", hash = "sha256:ba602a38d7403de89c38b8956b221ce6de0280730d269bab522492fcad82ee33"}, - {file = "pyinstaller-6.2.0-py3-none-manylinux2014_ppc64le.whl", hash = "sha256:ebac06d99b80d2035594c3cc2fb5f2612d86289edd0510dbcbeb20a873f51d5a"}, - {file = "pyinstaller-6.2.0-py3-none-manylinux2014_s390x.whl", hash = "sha256:fcfabc0ff1d38a4262c051dea3fdc1f7f106405c1f1b491b4c79cd28df19cab6"}, - {file = "pyinstaller-6.2.0-py3-none-manylinux2014_x86_64.whl", hash = "sha256:104430686149b2f1c135b2c17aa2967c85d54ef77dc92feb4e179ec846c0c467"}, - {file = "pyinstaller-6.2.0-py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:e87fd60292b53bb9965cb5a84122875469a2bd475fd0d0db0052a3f1be351f75"}, - {file = "pyinstaller-6.2.0-py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:8ec9d6c98972bb922cedb16a6638257aa66e5deadd79e2953f3464696237c413"}, - {file = "pyinstaller-6.2.0-py3-none-win32.whl", hash = "sha256:e5561e9a9b946d835c8dbc11ae4c16cc21e62bc77d10cc043406dc2992dfb4c6"}, - {file = "pyinstaller-6.2.0-py3-none-win_amd64.whl", hash = "sha256:3b586196277c4c54b69880650984c39c28bb6258c2b4b64200032e6ac69d53a0"}, - {file = "pyinstaller-6.2.0-py3-none-win_arm64.whl", hash = "sha256:d0c87b605bf13c3a04dfaa1d2fa7cd36765b8137000eeadccba865e1d6a19bf0"}, - {file = "pyinstaller-6.2.0.tar.gz", hash = "sha256:1ce77043929bf525be38289d78feecde0fcf15506215eda6500176a8715c5047"}, + {file = "pyinstaller-5.13.2-py3-none-macosx_10_13_universal2.whl", hash = "sha256:16cbd66b59a37f4ee59373a003608d15df180a0d9eb1a29ff3bfbfae64b23d0f"}, + {file = "pyinstaller-5.13.2-py3-none-manylinux2014_aarch64.whl", hash = "sha256:8f6dd0e797ae7efdd79226f78f35eb6a4981db16c13325e962a83395c0ec7420"}, + {file = "pyinstaller-5.13.2-py3-none-manylinux2014_i686.whl", hash = "sha256:65133ed89467edb2862036b35d7c5ebd381670412e1e4361215e289c786dd4e6"}, + {file = "pyinstaller-5.13.2-py3-none-manylinux2014_ppc64le.whl", hash = "sha256:7d51734423685ab2a4324ab2981d9781b203dcae42839161a9ee98bfeaabdade"}, + {file = "pyinstaller-5.13.2-py3-none-manylinux2014_s390x.whl", hash = "sha256:2c2fe9c52cb4577a3ac39626b84cf16cf30c2792f785502661286184f162ae0d"}, + {file = "pyinstaller-5.13.2-py3-none-manylinux2014_x86_64.whl", hash = "sha256:c63ef6133eefe36c4b2f4daf4cfea3d6412ece2ca218f77aaf967e52a95ac9b8"}, + {file = "pyinstaller-5.13.2-py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:aadafb6f213549a5906829bb252e586e2cf72a7fbdb5731810695e6516f0ab30"}, + {file = "pyinstaller-5.13.2-py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:b2e1c7f5cceb5e9800927ddd51acf9cc78fbaa9e79e822c48b0ee52d9ce3c892"}, + {file = "pyinstaller-5.13.2-py3-none-win32.whl", hash = "sha256:421cd24f26144f19b66d3868b49ed673176765f92fa9f7914cd2158d25b6d17e"}, + {file = "pyinstaller-5.13.2-py3-none-win_amd64.whl", hash = "sha256:ddcc2b36052a70052479a9e5da1af067b4496f43686ca3cdda99f8367d0627e4"}, + {file = "pyinstaller-5.13.2-py3-none-win_arm64.whl", hash = "sha256:27cd64e7cc6b74c5b1066cbf47d75f940b71356166031deb9778a2579bb874c6"}, + {file = "pyinstaller-5.13.2.tar.gz", hash = "sha256:c8e5d3489c3a7cc5f8401c2d1f48a70e588f9967e391c3b06ddac1f685f8d5d2"}, ] [package.dependencies] altgraph = "*" macholib = {version = ">=1.8", markers = "sys_platform == \"darwin\""} -packaging = ">=22.0" pefile = {version = ">=2022.5.30", markers = "sys_platform == \"win32\""} pyinstaller-hooks-contrib = ">=2021.4" pywin32-ctypes = {version = ">=0.2.1", markers = "sys_platform == \"win32\""} setuptools = ">=42.0.0" [package.extras] -completion = ["argcomplete"] +encryption = ["tinyaes (>=1.0.0)"] hook-testing = ["execnet (>=1.5.0)", "psutil", "pytest (>=2.7.3)"] [[package]] name = "pyinstaller-hooks-contrib" -version = "2023.10" +version = "2023.7" description = "Community maintained hooks for PyInstaller" optional = false python-versions = ">=3.7" files = [ - {file = "pyinstaller-hooks-contrib-2023.10.tar.gz", hash = "sha256:4b4a998036abb713774cb26534ca06b7e6e09e4c628196017a10deb11a48747f"}, - {file = "pyinstaller_hooks_contrib-2023.10-py2.py3-none-any.whl", hash = "sha256:6dc1786a8f452941245d5bb85893e2a33632ebdcbc4c23eea41f2ee08281b0c0"}, + {file = "pyinstaller-hooks-contrib-2023.7.tar.gz", hash = "sha256:0c436a4c3506020e34116a8a7ddfd854c1ad6ddca9a8cd84500bd6e69c9e68f9"}, + {file = "pyinstaller_hooks_contrib-2023.7-py2.py3-none-any.whl", hash = "sha256:3c10df14c0f71ab388dfbf1625375b087e7330d9444cbfd2b310ba027fa0cff0"}, ] [[package]] @@ -2034,19 +2033,19 @@ files = [ [[package]] name = "setuptools" -version = "69.0.2" +version = "68.1.2" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.0.2-py3-none-any.whl", hash = "sha256:1e8fdff6797d3865f37397be788a4e3cba233608e9b509382a2777d25ebde7f2"}, - {file = "setuptools-69.0.2.tar.gz", hash = "sha256:735896e78a4742605974de002ac60562d286fa8051a7e2299445e8e8fbb01aa6"}, + {file = "setuptools-68.1.2-py3-none-any.whl", hash = "sha256:3d8083eed2d13afc9426f227b24fd1659489ec107c0e86cec2ffdde5c92e790b"}, + {file = "setuptools-68.1.2.tar.gz", hash = "sha256:3d4dfa6d95f1b101d695a6160a7626e15583af71a5f52176efa5d39a054d475d"}, ] [package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5,<=7.1.2)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] -testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] [[package]] name = "shellingham" @@ -2431,4 +2430,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "2b9225ae66f4dab6a5785858312ecd2188a972698619418e017152ac2b38f41a" +content-hash = "4635ad235914ef05225525233ce0723226417491de9f2551112682c707921365" diff --git a/pyproject.toml b/pyproject.toml index b0d75a9a1..22f0b66df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ platformdirs = "^3.10.0" soxr = "^0.3.6" [tool.poetry.group.dev.dependencies] -pyinstaller = "^6.2.0" +pyinstaller = "^5.13" pre-commit = "^2.16.0" poetry = "^1.3.1" diff --git a/requirements-dev.txt b/requirements-dev.txt index c9a7736db..2c877c547 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ -altgraph==0.17.4 ; python_version >= "3.11" and python_version < "3.12" +altgraph==0.17.3 ; python_version >= "3.11" and python_version < "3.12" anyio==3.7.1 ; python_version >= "3.11" and python_version < "3.12" asgiref==3.7.2 ; python_version >= "3.11" and python_version < "3.12" attrs==23.1.0 ; python_version >= "3.11" and python_version < "3.12" @@ -28,7 +28,7 @@ jeepney==0.8.0 ; python_version >= "3.11" and python_version < "3.12" and sys_pl jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12" jsonschema==4.17.3 ; python_version >= "3.11" and python_version < "3.12" keyring==24.2.0 ; python_version >= "3.11" and python_version < "3.12" -macholib==1.16.3 ; python_version >= "3.11" and python_version < "3.12" and sys_platform == "darwin" +macholib==1.16.2 ; python_version >= "3.11" and python_version < "3.12" and sys_platform == "darwin" markupsafe==2.1.3 ; python_version >= "3.11" and python_version < "3.12" more-itertools==10.1.0 ; python_version >= "3.11" and python_version < "3.12" msgpack==1.0.5 ; python_version >= "3.11" and python_version < "3.12" @@ -46,8 +46,8 @@ pre-commit==2.21.0 ; python_version >= "3.11" and python_version < "3.12" ptyprocess==0.7.0 ; python_version >= "3.11" and python_version < "3.12" pycparser==2.21 ; python_version >= "3.11" and python_version < "3.12" pydantic==1.10.12 ; python_version >= "3.11" and python_version < "3.12" -pyinstaller-hooks-contrib==2023.10 ; python_version >= "3.11" and python_version < "3.12" -pyinstaller==6.2.0 ; python_version >= "3.11" and python_version < "3.12" +pyinstaller-hooks-contrib==2023.7 ; python_version >= "3.11" and python_version < "3.12" +pyinstaller==5.13.2 ; python_version >= "3.11" and python_version < "3.12" pyopenjtalk @ git+https://github.com/VOICEVOX/pyopenjtalk@b35fc89fe42948a28e33aed886ea145a51113f88 ; python_version >= "3.11" and python_version < "3.12" pyproject-hooks==1.0.0 ; python_version >= "3.11" and python_version < "3.12" pyrsistent==0.19.3 ; python_version >= "3.11" and python_version < "3.12" @@ -60,7 +60,7 @@ requests-toolbelt==1.0.0 ; python_version >= "3.11" and python_version < "3.12" requests==2.31.0 ; python_version >= "3.11" and python_version < "3.12" secretstorage==3.3.3 ; python_version >= "3.11" and python_version < "3.12" and sys_platform == "linux" semver==3.0.1 ; python_version >= "3.11" and python_version < "3.12" -setuptools==69.0.2 ; python_version >= "3.11" and python_version < "3.12" +setuptools==68.1.2 ; python_version >= "3.11" and python_version < "3.12" shellingham==1.5.3 ; python_version >= "3.11" and python_version < "3.12" six==1.16.0 ; python_version >= "3.11" and python_version < "3.12" sniffio==1.3.0 ; python_version >= "3.11" and python_version < "3.12" diff --git a/run.py b/run.py index ea737353c..f1ccf4e2f 100644 --- a/run.py +++ b/run.py @@ -89,7 +89,6 @@ engine_root, get_latest_core_version, get_save_dir, - internal_root, ) from voicevox_engine.utility.run_utility import decide_boolean_from_env @@ -228,7 +227,7 @@ def check_disabled_mutable_api(): metas_store = MetasStore(root_dir / "speaker_info") setting_ui_template = Jinja2Templates( - directory=internal_root() / "ui_template", + directory=engine_root() / "ui_template", variable_start_string="", variable_end_string="", ) diff --git a/run.spec b/run.spec index 65642c61d..970f2adfa 100644 --- a/run.spec +++ b/run.spec @@ -1,42 +1,49 @@ # -*- mode: python ; coding: utf-8 -*- # このファイルはPyInstallerによって自動生成されたもので、それをカスタマイズして使用しています。 -from argparse import ArgumentParser -from pathlib import Path -from shutil import copy2, copytree - from PyInstaller.utils.hooks import collect_data_files - -parser = ArgumentParser() -parser.add_argument("--libcore_path", type=Path) -parser.add_argument("--libonnxruntime_path", type=Path) -parser.add_argument("--core_model_dir_path", type=Path) -options = parser.parse_args() - -libonnxruntime_path: Path | None = options.libonnxruntime_path -if libonnxruntime_path is not None and not libonnxruntime_path.is_file(): - raise Exception(f"libonnxruntime_path: {libonnxruntime_path} is not file") - -libcore_path: Path | None = options.libcore_path -if libcore_path is not None and not libcore_path.is_file(): - raise Exception(f"libcore_path: {libcore_path} is not file") - -core_model_dir_path: Path | None = options.core_model_dir_path -if core_model_dir_path is not None and not core_model_dir_path.is_dir(): - raise Exception(f"core_model_dir_path: {core_model_dir_path} is not dir") +import os datas = [ - ("default.csv", "."), - ("presets.yaml", "."), - ("ui_template", "ui_template"), + ('engine_manifest_assets', 'engine_manifest_assets'), + ('speaker_info', 'speaker_info'), + ('engine_manifest.json', '.'), + ('default.csv', '.'), + ('licenses.json', '.'), + ('presets.yaml', '.'), + ('ui_template', 'ui_template'), ] -datas += collect_data_files("pyopenjtalk") +datas += collect_data_files('pyopenjtalk') + +core_model_dir_path = os.environ.get('CORE_MODEL_DIR_PATH') +if core_model_dir_path: + print('CORE_MODEL_DIR_PATH is found:', core_model_dir_path) + if not os.path.isdir(core_model_dir_path): + raise Exception("CORE_MODEL_DIR_PATH was found, but it is not directory!") + datas += [(core_model_dir_path, "model")] + +# コアとONNX Runtimeはバイナリであるが、`binaries`に加えると +# 依存関係のパスがPyInstallerに書き換えらるので、`datas`に加える +# 参考: https://github.com/VOICEVOX/voicevox_engine/pull/446#issuecomment-1210052318 +libcore_path = os.environ.get('LIBCORE_PATH') +if libcore_path: + print('LIBCORE_PATH is found:', libcore_path) + if not os.path.isfile(libcore_path): + raise Exception("LIBCORE_PATH was found, but it is not file!") + datas += [(libcore_path, ".")] + +libonnxruntime_path = os.environ.get('LIBONNXRUNTIME_PATH') +if libonnxruntime_path: + print('LIBONNXRUNTIME_PATH is found:', libonnxruntime_path) + if not os.path.isfile(libonnxruntime_path): + raise Exception("LIBCORE_PATH was found, but it is not file!") + datas += [(libonnxruntime_path, ".")] block_cipher = None a = Analysis( - ["run.py"], + ['run.py'], pathex=[], binaries=[], datas=datas, @@ -58,7 +65,7 @@ exe = EXE( a.scripts, [], exclude_binaries=True, - name="run", + name='run', debug=False, bootloader_ignore_signals=False, strip=False, @@ -69,7 +76,6 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, - contents_directory="engine_internal", ) coll = COLLECT( @@ -80,27 +86,5 @@ coll = COLLECT( strip=False, upx=True, upx_exclude=[], - name="run", + name='run', ) - -# 実行ファイル作成後の処理 - -# 実行ファイルと同じrootディレクトリ -target_dir = Path(DISTPATH) / "run" - -# 動的ライブラリをコピー -if libonnxruntime_path is not None: - copy2(libonnxruntime_path, target_dir) -if libcore_path is not None: - copy2(libcore_path, target_dir) -if core_model_dir_path is not None: - copytree(core_model_dir_path, target_dir / "model") - -# 互換性維持のために必要なファイルをコピー -license_file_path = Path("licenses.json") -if license_file_path.is_file(): - copy2("licenses.json", target_dir) - -copytree("speaker_info", target_dir / "speaker_info") -copy2("engine_manifest.json", target_dir) -copytree("engine_manifest_assets", target_dir / "engine_manifest_assets") diff --git a/voicevox_engine/user_dict.py b/voicevox_engine/user_dict.py index e931f557c..8661321f7 100644 --- a/voicevox_engine/user_dict.py +++ b/voicevox_engine/user_dict.py @@ -12,9 +12,9 @@ from .model import UserDictWord, WordTypes from .part_of_speech_data import MAX_PRIORITY, MIN_PRIORITY, part_of_speech_data -from .utility import get_save_dir, internal_root, mutex_wrapper +from .utility import engine_root, get_save_dir, mutex_wrapper -root_dir = internal_root() +root_dir = engine_root() save_dir = get_save_dir() if not save_dir.is_dir(): diff --git a/voicevox_engine/utility/__init__.py b/voicevox_engine/utility/__init__.py index 7ed74f118..d40fea3e6 100644 --- a/voicevox_engine/utility/__init__.py +++ b/voicevox_engine/utility/__init__.py @@ -5,7 +5,7 @@ ) 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, internal_root +from .path_utility import delete_file, engine_root, get_save_dir __all__ = [ "ConnectBase64WavesException", @@ -13,9 +13,8 @@ "decode_base64_waves", "get_latest_core_version", "parse_core_version", - "mutex_wrapper", "delete_file", "engine_root", "get_save_dir", - "internal_root", + "mutex_wrapper", ] diff --git a/voicevox_engine/utility/path_utility.py b/voicevox_engine/utility/path_utility.py index 6c5c36ca2..7c46ad40b 100644 --- a/voicevox_engine/utility/path_utility.py +++ b/voicevox_engine/utility/path_utility.py @@ -2,51 +2,18 @@ import sys import traceback from pathlib import Path -from typing import Literal from platformdirs import user_data_dir -def _runtime_type() -> Literal["nuitka", "pyinstaller", "python"]: - """ - コンパイルに使用したライブラリ名を返す。 - コンパイルしていない場合は"python"を返す。 - """ - # nuitkaビルドをした際はグローバルに__compiled__が含まれる - if "__compiled__" in globals(): - return "nuitka" - - # pyinstallerでビルドをした際はsys.frozenが設定される - elif getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): - return "pyinstaller" - - return "python" - - def engine_root() -> Path: - """ - 開発環境ではリポジトリのルートディレクトリを返す。 - コンパイル後は実行ファイルがあるディレクトリを返す。 - """ - runtime = _runtime_type() - if runtime == "nuitka": - root_dir = Path(sys.argv[0]).parent - - elif runtime == "pyinstaller": - root_dir = Path(sys.executable).parent - - else: + if is_development(): root_dir = Path(__file__).parents[2] - return root_dir.resolve(strict=True) - + # Nuitka/Pyinstallerでビルドされている場合 + else: + root_dir = Path(sys.argv[0]).parent -def internal_root() -> Path: - """ - コンパイル時に収集された実行ファイル内部用のルートディレクトリを返す。 - 開発環境ではリポジトリのルートディレクトリを返す。 - """ - root_dir = Path(__file__).parents[2] return root_dir.resolve(strict=True) @@ -55,7 +22,15 @@ def is_development() -> bool: 開発版かどうか判定する関数 Nuitka/Pyinstallerでコンパイルされていない場合は開発環境とする。 """ - return _runtime_type() == "python" + # nuitkaビルドをした際はグローバルに__compiled__が含まれる + if "__compiled__" in globals(): + return False + + # pyinstallerでビルドをした際はsys.frozenが設定される + elif getattr(sys, "frozen", False): + return False + + return True def get_save_dir():