-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimised Build Script to reduce exe size
- Loading branch information
Showing
1 changed file
with
103 additions
and
33 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 |
---|---|---|
@@ -1,33 +1,103 @@ | ||
import os | ||
import subprocess | ||
|
||
def run_pyinstaller_build(): | ||
pyinstaller_command = [ | ||
"pyinstaller", | ||
"--onefile", | ||
"--windowed", | ||
"--icon=icons/app_icon.ico", | ||
"main.py" | ||
] | ||
|
||
try: | ||
os.system("rmdir /s /q dist") | ||
|
||
subprocess.run(pyinstaller_command, check=True) | ||
print("Build completed successfully!") | ||
|
||
os.rename("dist/main.exe", "dist/Writing Tools.exe") | ||
|
||
os.system("mkdir dist\\icons") | ||
|
||
os.system("copy /Y *.png dist") | ||
os.system("copy /Y icons\\*.* dist\\icons") | ||
|
||
os.system("powershell Compress-Archive -Path dist -DestinationPath 'dist\\Writing Tools.zip'") | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Build failed with error: {e}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
run_pyinstaller_build() | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def run_pyinstaller_build(): | ||
pyinstaller_command = [ | ||
"pyinstaller", | ||
"--onefile", | ||
"--windowed", | ||
"--icon=icons/app_icon.ico", | ||
"--name=Writing Tools", | ||
"--clean", | ||
"--noconfirm", | ||
# Exclude unnecessary modules | ||
"--exclude-module", "tkinter", | ||
"--exclude-module", "unittest", | ||
"--exclude-module", "IPython", | ||
"--exclude-module", "jedi", | ||
"--exclude-module", "email_validator", | ||
"--exclude-module", "cryptography", | ||
"--exclude-module", "psutil", | ||
"--exclude-module", "pyzmq", | ||
"--exclude-module", "tornado", | ||
# Exclude modules related to PySide6 that are not used | ||
"--exclude-module", "PySide6.QtNetwork", | ||
"--exclude-module", "PySide6.QtXml", | ||
"--exclude-module", "PySide6.QtQml", | ||
"--exclude-module", "PySide6.QtQuick", | ||
"--exclude-module", "PySide6.QtQuickWidgets", | ||
"--exclude-module", "PySide6.QtPrintSupport", | ||
"--exclude-module", "PySide6.QtSql", | ||
"--exclude-module", "PySide6.QtTest", | ||
"--exclude-module", "PySide6.QtSvg", | ||
"--exclude-module", "PySide6.QtSvgWidgets", | ||
"--exclude-module", "PySide6.QtHelp", | ||
"--exclude-module", "PySide6.QtMultimedia", | ||
"--exclude-module", "PySide6.QtMultimediaWidgets", | ||
"--exclude-module", "PySide6.QtOpenGL", | ||
"--exclude-module", "PySide6.QtOpenGLWidgets", | ||
"--exclude-module", "PySide6.QtPositioning", | ||
"--exclude-module", "PySide6.QtLocation", | ||
"--exclude-module", "PySide6.QtSerialPort", | ||
"--exclude-module", "PySide6.QtWebChannel", | ||
"--exclude-module", "PySide6.QtWebSockets", | ||
"--exclude-module", "PySide6.QtWinExtras", | ||
"--exclude-module", "PySide6.QtNetworkAuth", | ||
"--exclude-module", "PySide6.QtRemoteObjects", | ||
"--exclude-module", "PySide6.QtTextToSpeech", | ||
"--exclude-module", "PySide6.QtWebEngineCore", | ||
"--exclude-module", "PySide6.QtWebEngineWidgets", | ||
"--exclude-module", "PySide6.QtWebEngine", | ||
"--exclude-module", "PySide6.QtBluetooth", | ||
"--exclude-module", "PySide6.QtNfc", | ||
"--exclude-module", "PySide6.QtWebView", | ||
"--exclude-module", "PySide6.QtCharts", | ||
"--exclude-module", "PySide6.QtDataVisualization", | ||
"--exclude-module", "PySide6.QtPdf", | ||
"--exclude-module", "PySide6.QtPdfWidgets", | ||
"--exclude-module", "PySide6.QtQuick3D", | ||
"--exclude-module", "PySide6.QtQuickControls2", | ||
"--exclude-module", "PySide6.QtQuickParticles", | ||
"--exclude-module", "PySide6.QtQuickTest", | ||
"--exclude-module", "PySide6.QtQuickWidgets", | ||
"--exclude-module", "PySide6.QtSensors", | ||
"--exclude-module", "PySide6.QtStateMachine", | ||
"--exclude-module", "PySide6.Qt3DCore", | ||
"--exclude-module", "PySide6.Qt3DRender", | ||
"--exclude-module", "PySide6.Qt3DInput", | ||
"--exclude-module", "PySide6.Qt3DLogic", | ||
"--exclude-module", "PySide6.Qt3DAnimation", | ||
"--exclude-module", "PySide6.Qt3DExtras", | ||
"main.py" | ||
] | ||
|
||
try: | ||
# Remove previous build directories | ||
if os.path.exists('dist'): | ||
os.system("rmdir /s /q dist") | ||
if os.path.exists('build'): | ||
os.system("rmdir /s /q build") | ||
if os.path.exists('__pycache__'): | ||
os.system("rmdir /s /q __pycache__") | ||
|
||
# Run PyInstaller | ||
subprocess.run(pyinstaller_command, check=True) | ||
print("Build completed successfully!") | ||
|
||
# Clean up unnecessary files | ||
if os.path.exists('build'): | ||
os.system("rmdir /s /q build") | ||
if os.path.exists('__pycache__'): | ||
os.system("rmdir /s /q __pycache__") | ||
|
||
# No need to copy data files manually since they are included | ||
# in the executable using --add-data | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Build failed with error: {e}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
run_pyinstaller_build() |