-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33a887a
commit c11bc00
Showing
5 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,8 @@ build/ | |
log/ | ||
dist/ | ||
output/ | ||
export/ | ||
export/ | ||
|
||
# created when building | ||
LICENSE.txt | ||
*.spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
""" | ||
Pyinstaller script to move stuff, rename, and also make a clean output folder | ||
""" | ||
|
||
import os, shutil, sys | ||
from PyInstaller.__main__ import generate_parser, run # type: ignore | ||
from speech_translate._version import __version__ | ||
|
||
|
||
def run_makespec(filenames, **opts): | ||
# Split pathex by using the path separator | ||
temppaths = opts["pathex"][:] | ||
pathex = opts["pathex"] = [] | ||
for p in temppaths: | ||
pathex.extend(p.split(os.pathsep)) | ||
|
||
import PyInstaller.building.makespec | ||
|
||
spec_file = PyInstaller.building.makespec.main(filenames, **opts) | ||
return spec_file | ||
|
||
|
||
def get_env_name(): | ||
return os.path.basename(sys.prefix) | ||
|
||
|
||
def get_base_prefix_compat(): | ||
"""Get base/real prefix, or sys.prefix if there is none.""" | ||
return getattr(sys, "base_prefix", None) or getattr(sys, "real_prefix", None) or sys.prefix | ||
|
||
|
||
def in_virtualenv(): | ||
return get_base_prefix_compat() != sys.prefix | ||
|
||
|
||
if not in_virtualenv(): | ||
print("Please run this script in a virtual environment") | ||
sys.exit(1) | ||
|
||
options = [ | ||
"Main.py", | ||
"-c", # console window. Console window cannot be hidden because it will cause error on whisper transformer logging | ||
"--clean", | ||
"--noconfirm", | ||
"--additional-hooks-dir=./_pyinstaller_hooks", | ||
"--runtime-hook=./_pyinstaller_hooks/add_lib.py", | ||
"--icon=./assets/icon.ico", | ||
"--add-data=./theme;theme", | ||
"--add-data=./assets;assets", | ||
"--add-data=./LICENSE.txt;.", | ||
f"--add-data={get_env_name()}/Lib/site-packages/whisper/assets;whisper/assets/", | ||
"--copy-metadata=tqdm", | ||
"--copy-metadata=regex", | ||
"--copy-metadata=requests", | ||
"--copy-metadata=packaging", | ||
"--copy-metadata=filelock", | ||
"--copy-metadata=numpy", | ||
"--copy-metadata=tokenizers", | ||
"--exclude-module=pyinstaller", | ||
] | ||
|
||
print(f"Currently running in virtual environment {get_env_name()} using python {sys.version}") | ||
specName = f"SpeechTranslate {__version__}" | ||
argsName = f"-n{specName}" # name of the spec file | ||
|
||
# ----------------- | ||
# make spec folder | ||
parser = generate_parser() | ||
args = parser.parse_args(options) | ||
run_makespec(**vars(args)) | ||
|
||
# Edit spec folder | ||
specFile = f"{specName}.spec" | ||
spec = "" | ||
with open(specFile, "r") as f: | ||
spec = f.read() | ||
spec = spec.replace(f"name='{specName}'", f"name='SpeechTranslate'", 1) | ||
|
||
# write spec file | ||
with open(specFile, "w") as f: | ||
f.write(spec) | ||
|
||
# create license.txt file | ||
with open("LICENSE", "r") as f: | ||
license = f.read() | ||
with open("LICENSE.txt", "w") as f2: | ||
f2.write(license) | ||
|
||
# run pyinstaller | ||
run([specFile, "--noconfirm", "--clean"]) | ||
|
||
# delete license.txt file | ||
print(">> Deleting created license.txt file") | ||
os.remove("LICENSE.txt") | ||
|
||
output_folder = f"dist/{specName}" | ||
|
||
# create lib folder in output folder | ||
lib_folder = f"{output_folder}/lib" | ||
os.mkdir(lib_folder) | ||
|
||
# move all .dll .pyd files to lib folder with some exception | ||
print(">> Moving .dll files to lib folder") | ||
dontMove = ["python3.dll", "python310.dll", "python38.dll", "python39.dll", "libopenblas64__v0.3.21-gcc_10_3_0.dll"] | ||
for file in os.listdir(output_folder): | ||
if file.endswith(".dll") or file.endswith(".pyd"): | ||
if file not in dontMove: | ||
shutil.move(f"{output_folder}/{file}", f"{lib_folder}/{file}") | ||
|
||
# open folder | ||
print(">> Opening output folder") | ||
output_folder = os.path.abspath(output_folder) | ||
os.startfile(output_folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pillow==9.4.0 |