-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
103 lines (83 loc) · 2.43 KB
/
build.ps1
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
# rubbie kelvin
# NEED HELP FROM WINDOWS USERS
function Main($package) {
Write-Host "🎭 setting up virtual environment..."
if (Test-Path -Path ./venv){
Write-Host "⚡ found existing venv folder."
Write-Host "⚡ activating virtual environment"
pwsh -File ./venv/bin/Activate.ps1 > $null
if (-Not $?){
pwsh.exe -File ./venv/bin/Activate.ps1
}
}else{
Write-Host "👀 creating virtual environment..."
if (python -m venv venv){
# DEBUG: this line might not work on windows
Write-Output "*" > venv/.gitignore
Write-Host "⚡ activating virtual environment"
#TODO: fix activate path
pwsh -File ./venv/bin/Activate.ps1 > $null
if (-Not $?){
pwsh.exe -File ./venv/bin/Activate.ps1
}
}else{
Write-Host "❌ coundn't create virtual envionment"
return
}
}
Write-Host "👀 installing neccessary packages"
if (python -m pip install -r ./requirements.txt){
Write-Host "" > $null
}else{
Write-Host "❌ couldnt install packages"
return
}
# check for ".qrc" file in workspace folder
# if there's a .qrc file... compile it into a python file
# script to compile .qrc
if (Test-Path -Path ./.qrc){
Write-Host "👀 compiling .qrc to python file..."
pyside2-rcc --compress-algo zlib -g python ./.qrc -o ./qrc.py > $null
if ($?){
Write-Host "✅ compiled .qrc -> qrc.py"
}else{
Write-Host "❌ couldnt compile .qrc"
return $false
}
}else {
Write-Host "❌ no .qrc file."
return $false
}
# build executable
if ($package -eq "--package"){
Write-Host "👀 cleaning up..."
if (Test-Path -Path ./dist){
Remove-Item ./dist -Recurse
}
if (Test-Path -Path ./build){
Remove-Item ./build -Recurse
}
# optimize python scripts by removing all docstrings
# assert statements are also removed from byte codes
# this is an attempt to reduce bundle size along size --onefile in pyinstaller options
$env:PYTHONOPTIMIZE = 1
Write-Host "👀 building executable... might take a while"
pyinstaller --windowed -n Courier --clean --onefile --log-level=CRITICAL ./main.py > $null
if ($?){
Remove-Item *.spec
Remove-Item ./build -Recurse
Copy-Item ./dist -Destination ./build -Recurse
Remove-Item ./dist -Recurse
Write-Host "✅ built executable. at build/"
}else{
Write-Host "❌ couldnt build executable..."
return $false
}
}
if (-Not $package){
Write-Host "👀 running python script..."
python ./main.py
}
# return $true
}
Main $args[0]