-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
108 lines (86 loc) · 2.63 KB
/
build.py
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
import subprocess
import shutil
from pathlib import Path
baseDir = Path(__file__).resolve().parent
distPath = baseDir / "dist-full"
venvPath = baseDir / "venv-full"
venvScripts = venvPath / "Scripts"
def runSubprocess(command, shell=False):
try:
subprocess.run(command, shell=shell, check=True)
except subprocess.CalledProcessError as e:
print(f"Error while running command {command}: {e}")
raise
def createVenv():
print("Creating the virtual environment...")
runSubprocess(["python", "-m", "venv", str(venvPath)])
def activateVenv():
print("Activating the virtual environment...")
runSubprocess(str(venvScripts / "activate"), shell=True)
def installRequirements():
print("Installing the requirements...")
runSubprocess(
[str(venvScripts / "pip3"), "install", "-r", "requirements-windows.txt"]
)
def installPyinstaller():
print("Installing PyInstaller...")
runSubprocess([str(venvScripts / "python"), "-m", "pip", "install", "pyinstaller"])
def createExecutable():
print("Creating executable with PyInstaller...")
srcPath = baseDir / "src"
mainPath = baseDir / "main.py"
iconPath = srcPath / "assets" / "icon.ico"
commonArgs = [
"--noconfirm",
"--onedir",
"--console",
"--noupx",
"--clean",
"--icon",
str(iconPath),
"--distpath",
str(distPath),
]
cliArgs = commonArgs + [
"--optimize",
"1",
"--add-data",
f"{srcPath};src/",
"--hidden-import",
"rife_ncnn_vulkan_python.rife_ncnn_vulkan_wrapper",
"--hidden-import",
"upscale_ncnn_py.upscale_ncnn_py_wrapper",
"--collect-all",
"tensorrt",
"--collect-all",
"tensorrt-cu12-bindings",
"--collect-all",
"tensorrt_libs",
"--collect-all",
"fastrlock",
"--collect-all",
"inquirer",
"--collect-all",
"readchar",
"--collect-all",
"grapheme",
str(mainPath),
]
print("Creating the CLI executable...")
runSubprocess([str(venvScripts / "pyinstaller")] + cliArgs)
print("Finished creating the CLI executable")
def moveExtras():
mainDir = distPath / "main"
filesToCopy = ["LICENSE", "README.md", "README.txt"]
for fileName in filesToCopy:
try:
shutil.copy(baseDir / fileName, mainDir)
except Exception as e:
print(f"Error while copying {fileName}: {e}")
if __name__ == "__main__":
createVenv()
activateVenv()
installRequirements()
installPyinstaller()
createExecutable()
moveExtras()