81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Build script to create an executable using PyInstaller.
|
|
Optimized for faster builds by excluding heavy dependencies.
|
|
"""
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
def build_exe():
|
|
"""Build the executable using PyInstaller."""
|
|
|
|
# Get the project root
|
|
project_root = Path(__file__).parent
|
|
|
|
# Check if PyInstaller is installed
|
|
try:
|
|
import PyInstaller
|
|
except ImportError:
|
|
print("❌ PyInstaller not found. Installing...")
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyinstaller"])
|
|
|
|
# Get the main entry point
|
|
main_file = project_root / "main.py"
|
|
|
|
if not main_file.exists():
|
|
print(f"❌ main.py not found at {main_file}")
|
|
sys.exit(1)
|
|
|
|
# Build command - optimized for faster builds
|
|
cmd = [
|
|
sys.executable,
|
|
"-m", "PyInstaller",
|
|
"--name=MusicDownloader",
|
|
"--onefile",
|
|
"--windowed",
|
|
"--icon=music.png",
|
|
"--add-data=ffmpeg/bin:ffmpeg/bin",
|
|
"--add-data=Resources:Resources",
|
|
"--add-data=music.png:.",
|
|
"--collect-all=PyQt6",
|
|
"--collect-all=yt_dlp",
|
|
"--collect-all=mutagen",
|
|
"--collect-all=musicbrainzngs",
|
|
"--collect-all=thefuzz",
|
|
"--hidden-import=PyQt6.QtCore",
|
|
"--hidden-import=PyQt6.QtGui",
|
|
"--hidden-import=PyQt6.QtWidgets",
|
|
"--hidden-import=yt_dlp",
|
|
"--hidden-import=mutagen",
|
|
"--hidden-import=musicbrainzngs",
|
|
"--hidden-import=thefuzz",
|
|
"--exclude-module=sentence_transformers",
|
|
"--exclude-module=sklearn",
|
|
"--exclude-module=torch",
|
|
"--exclude-module=tensorflow",
|
|
"--distpath=dist",
|
|
"--workpath=build",
|
|
"--specpath=.",
|
|
str(main_file),
|
|
]
|
|
|
|
print("🔨 Building executable...")
|
|
print(f"Command: {' '.join(cmd)}")
|
|
|
|
try:
|
|
result = subprocess.run(cmd, check=True)
|
|
print("✅ Build successful!")
|
|
print(f"📦 Executable created at: {project_root / 'dist' / 'MusicDownloader.exe'}")
|
|
return 0
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"❌ Build failed with error code {e.returncode}")
|
|
return 1
|
|
except Exception as e:
|
|
print(f"❌ Build failed: {e}")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(build_exe())
|