Skip to content

Commit 1c8d163

Browse files
committed
fixed assets issue
1 parent 92414bf commit 1c8d163

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

build.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ def check_pyinstaller():
2525
def build_command(current_platform):
2626
# Set --add-data flag syntax and icon flag
2727
if os.name == "nt": # Windows
28-
add_data = f"{ASSETS_SRC};assets"
28+
add_data = f"{ASSETS_SRC}{os.pathsep}assets"
2929
icon_flag = ["--icon", str(ICON_PATH)] if ICON_PATH.exists() else []
3030
else: # POSIX (Linux/macOS)
3131
add_data = f"{ASSETS_SRC}:assets"
32-
# .ico icons are not supported on Linux/macOS for PyInstaller
33-
icon_flag = (
34-
["--icon", str(ICON_PATH)]
35-
if (
36-
ICON_PATH.with_suffix(".icns").exists() and current_platform == "darwin"
37-
)
38-
else []
39-
)
32+
# .ico icons are not supported on Linux/macOS for PyInstaller, use .icns for macOS if available
33+
if current_platform == "darwin" and ICON_PATH.with_suffix(".icns").exists():
34+
icon_flag = ["--icon", str(ICON_PATH.with_suffix(".icns"))]
35+
else:
36+
icon_flag = []
4037

4138
cmd = [
4239
"pyinstaller",
@@ -50,6 +47,17 @@ def build_command(current_platform):
5047
return cmd
5148

5249

50+
def copy_assets_to_dist():
51+
"""
52+
Ensure the assets folder is present in the dist directory after build.
53+
"""
54+
dist_assets = DIST_DIR / "assets"
55+
if dist_assets.exists():
56+
shutil.rmtree(dist_assets)
57+
shutil.copytree(ASSETS_SRC, dist_assets)
58+
print(f"Copied {ASSETS_SRC} to {dist_assets}.")
59+
60+
5361
def clean():
5462
if DIST_DIR.exists():
5563
shutil.rmtree(DIST_DIR)
@@ -73,17 +81,19 @@ def main():
7381
cmd = build_command(current_platform)
7482
print(f"Running: {' '.join(map(str, cmd))}")
7583
subprocess.check_call(cmd)
84+
# Copy assets folder to dist so it is available for the onefile binary
85+
copy_assets_to_dist()
7686
if current_platform == "windows":
77-
print("Your EXE is in the dist/ folder.")
87+
print("Your EXE and assets are in the dist/ folder.")
7888
elif current_platform == "linux":
79-
print("Your Linux binary is in the dist/ folder.")
89+
print("Your Linux binary and assets are in the dist/ folder.")
8090
elif current_platform == "darwin":
81-
print("Your macOS binary is in the dist/ folder.")
91+
print("Your macOS binary and assets are in the dist/ folder.")
8292
else:
8393
print(f"Unsupported platform: {current_platform}")
8494
sys.exit(1)
8595
print("Done!")
8696

8797

8898
if __name__ == "__main__":
89-
main()
99+
main()

0 commit comments

Comments
 (0)