-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-linux.py
120 lines (100 loc) · 3.15 KB
/
build-linux.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
109
110
111
112
113
114
115
116
117
118
119
120
import subprocess
import shutil
from pathlib import Path
baseDir = Path(__file__).resolve().parent
distPath = baseDir / "dist-full"
venvPath = baseDir / "venv-full"
venvBinPath = venvPath / "bin"
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...")
try:
runSubprocess(["python3.12", "-m", "venv", str(venvPath), "--without-pip"])
print("Installing pip in the virtual environment...")
runSubprocess([str(venvBinPath / "python3.12"), "-m", "ensurepip", "--upgrade"])
except subprocess.CalledProcessError:
print("Failed to create venv with python3.12. Attempting with virtualenv...")
runSubprocess(["pip", "install", "virtualenv"])
runSubprocess(["virtualenv", "-p", "python3.12", str(venvPath)])
def installRequirements():
print("Installing the requirements...")
runSubprocess(
[
str(venvBinPath / "python3.12"),
"-m",
"pip",
"install",
"-r",
"requirements-linux.txt",
]
)
def installPyinstaller():
print("Installing PyInstaller...")
runSubprocess(
[str(venvBinPath / "python3.12"), "-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 + [
"--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),
]
pyinstallerPath = shutil.which("pyinstaller", path=str(venvBinPath))
if not pyinstallerPath:
print("PyInstaller not found in the virtual environment")
return
print("Creating the CLI executable...")
runSubprocess([pyinstallerPath] + 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()
installRequirements()
installPyinstaller()
createExecutable()
moveExtras()