-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_exe.py
executable file
·61 lines (49 loc) · 1.97 KB
/
build_exe.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
# build_exe.py
import PyInstaller.__main__
import os
import sys
import glob
def collect_assets():
"""Collect all PNG and MP3 files from the Assets directory"""
script_dir = os.path.dirname(os.path.abspath(__file__))
assets_dir = os.path.join(script_dir, 'Assets')
# Create the assets directory if it doesn't exist
os.makedirs(assets_dir, exist_ok=True)
# Collect all PNG and MP3 files
png_files = glob.glob(os.path.join(assets_dir, '**', '*.png'), recursive=True)
mp3_files = glob.glob(os.path.join(assets_dir, '**', '*.mp3'), recursive=True)
# Create data_files list for PyInstaller
# Note: On Windows, we use semicolon (;) as separator
data_files = []
for file in png_files + mp3_files:
# Get relative path from assets directory
rel_dir = os.path.dirname(os.path.relpath(file, script_dir))
# Format for PyInstaller: (source_path, destination_directory)
data_files.append(f'--add-data={file};{rel_dir}')
return data_files
def build_executable():
# Directory containing your script
script_dir = os.path.dirname(os.path.abspath(__file__))
# Collect asset files
asset_args = collect_assets()
# Create PyInstaller command
pyinstaller_args = [
'main.py',
'--onefile', # Create a single executable
'--clean', # Clean PyInstaller cache
'--noconfirm', # Replace output directory without asking
'--name=LapinCarotte', # Name of your executable
'--noconsole',
'-i=Assets/HP.ico',
'--optimize=2',
'--noupx',
]
# Add all asset files to the command
pyinstaller_args.extend(asset_args)
print("Building executable with the following assets:")
for arg in asset_args:
print(f" {arg}")
# Run PyInstaller
PyInstaller.__main__.run(pyinstaller_args)
if __name__ == "__main__":
build_executable()