-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare_release.py
More file actions
170 lines (143 loc) · 6.37 KB
/
prepare_release.py
File metadata and controls
170 lines (143 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
# Copyright (c) 2025 oatsu
# ruff: noqa: T201, S101
"""kuresampler の配布準備を行う。"""
import shutil
import subprocess
from pathlib import Path
import colored_traceback.auto # noqa: F401
from send2trash import send2trash
from tqdm import tqdm
RELEASE_ROOT = Path('_release')
SOURCE_DIR = Path(__file__).parent
PYTHON_DIR = SOURCE_DIR / 'python-3.12.10-embed-amd64'
REQUIRED_DIRS = [
'resampler',
'models',
]
EXE_FILES = [
'kuresampler_K.exe',
'kuresampler_R.exe',
'kuresampler_fast_K.exe',
'kuresampler_fast_R.exe',
'kuresampler_K_Client.exe',
'kuresampler_R_Client.exe',
]
BAT_FILES = [
'kuresampler_K_child.bat',
'kuresampler_R_child.bat',
'reinstall_torch.bat',
'start_server.bat',
]
CS_FILES = [
'kuresampler.cs',
]
PY_FILES = [
'convert.py',
'util.py',
'resampler.py',
'server_resampler.py',
]
OTHER_FILES = [
'LICENSE',
'README.md',
'requirements.txt',
]
UPDATE_REQUIREMENTS = [
'git+https://github.com/oatsu-gh/nnsvs@kuresampler',
'git+https://github.com/oatsu-gh/PyRwu@kuresampler',
'git+https://github.com/oatsu-gh/ParallelWaveGAN@kuresampler',
'git+https://github.com/oatsu-gh/HN-UnifiedSourceFilterGAN@kuresampler',
'fastapi[standard]',
'uvicorn[standard]',
]
def install_torch_cpu():
"""CPU版のpytorchをインストールする。"""
python_exe = str(PYTHON_DIR / 'python.exe')
uninstall_command = [python_exe, '-m', 'pip', 'uninstall', '-y', 'torch', 'torchvision', 'torchaudio', '--no-input'] # fmt: skip
subprocess.run(uninstall_command, check=True) # noqa: S603
install_command = [python_exe, '-m', 'pip', 'install', 'torch', 'torchvision', 'torchaudio', '--no-warn-script-location'] # fmt: skip
subprocess.run(install_command, check=True) # noqa: S603
def upgrade_packages():
"""必要なパッケージをインストール・アップグレードする。"""
python_exe = str(PYTHON_DIR / 'python.exe')
command_head = [python_exe, '-m', 'pip', 'install', '--upgrade']
for package in UPDATE_REQUIREMENTS:
command = command_head + [package, '--no-warn-script-location']
print(f'Upgrading package: {package}')
subprocess.run(command, check=True, shell=False) # noqa: S603
def remove_cache_files(path_dir: Path):
"""キャッシュファイルを削除する。"""
# キャッシュフォルダを再帰的に検索
# __pycache__フォルダを再帰的に検索
dirs_to_remove = list(path_dir.rglob('__pycache__'))
dirs_to_remove = [
path for path in dirs_to_remove if path.is_dir() and path.name == '__pycache__'
]
# キャッシュフォルダを削除
for cache_dir in tqdm(dirs_to_remove):
shutil.rmtree(cache_dir)
def prepare_release(version: str):
"""配布用フォルダを作成し、zip圧縮する。"""
# 配布フォルダを作成する
RELEASE_ROOT.mkdir(exist_ok=True)
release_dir = RELEASE_ROOT / f'kuresampler-{version}'
if release_dir.exists():
shutil.rmtree(release_dir)
print(f'Removed old release dir: {release_dir}')
release_dir.mkdir()
print(f'Created release dir: {release_dir}')
print('──────────────────────────────────────────────')
# 必要なフォルダをコピーする
for dname in REQUIRED_DIRS:
print(f'Copying dir: {dname}')
shutil.copytree(SOURCE_DIR / dname, release_dir / dname)
print('──────────────────────────────────────────────')
# 必要なファイルをコピーする
required_files = EXE_FILES + BAT_FILES + CS_FILES + PY_FILES + OTHER_FILES
for fname in required_files:
print(f'Copying file: {fname}')
shutil.copy2(SOURCE_DIR / fname, release_dir / fname)
print('──────────────────────────────────────────────')
# CPU版のpytorchをインストールする
print('Installing CPU version of pytorch...')
install_torch_cpu()
print('──────────────────────────────────────────────')
# 必要なパッケージをインストール・アップグレードする
print('Upgrading required packages...')
upgrade_packages()
print('──────────────────────────────────────────────')
# Pythonフォルダ内の __pycache__ を削除する
print('Removing __pycache__ folders...')
remove_cache_files(PYTHON_DIR)
print('──────────────────────────────────────────────')
# Pythonフォルダをコピーする
print(f'Copying Python dir: {PYTHON_DIR}')
shutil.copytree(PYTHON_DIR, release_dir / PYTHON_DIR.name)
print('──────────────────────────────────────────────')
# Pythonフォルダ内の __pycache__ を再度削除する
print('Removing __pycache__ folders...')
remove_cache_files(release_dir / PYTHON_DIR.name)
print('──────────────────────────────────────────────')
# zip圧縮する
zip_path = Path(str(release_dir) + '.zip')
if zip_path.exists():
send2trash(str(zip_path))
print(f'Removed old zip: {zip_path}')
print(f'Creating zip: {zip_path}')
shutil.make_archive(
str(release_dir),
format='zip',
root_dir=RELEASE_ROOT,
base_dir=release_dir.name,
)
print(f'Created zip: {zip_path}')
print('──────────────────────────────────────────────')
zip_size = zip_path.stat().st_size
print(f'Zip size: {zip_size / 1024**2:.2f} MB')
print('Done!')
if __name__ == '__main__':
version = input('kuresamplerのバージョンを入力してください。\n>>> ').lstrip('v')
assert '.' in version
prepare_release(version)
input('Press Enter to exit...\n')