-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
68 lines (58 loc) · 2.08 KB
/
build.py
File metadata and controls
68 lines (58 loc) · 2.08 KB
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
"""
Build script for the Supplement Tracker application.
This script builds the executable for the Supplement Tracker application using PyInstaller.
It also provides instructions for setting up file associations on Windows.
"""
import os
import sys
import subprocess
import shutil
import time
def clean_dist():
"""Clean up the dist directory."""
dist_dir = 'dist'
if os.path.exists(dist_dir):
try:
# Try to remove the directory and its contents
shutil.rmtree(dist_dir)
except PermissionError:
print("Warning: Could not remove existing dist directory. Please close any running instances of the program.")
print("Waiting 5 seconds before continuing...")
time.sleep(5)
try:
shutil.rmtree(dist_dir)
except PermissionError:
print("Error: Still cannot remove dist directory. Please manually close the program and try again.")
sys.exit(1)
def build_exe():
"""Build the executable using PyInstaller."""
# Clean up first
clean_dist()
# PyInstaller command
cmd = [
'pyinstaller',
'--noconfirm',
'--onefile',
'--windowed',
'--icon=icon.ico' if os.path.exists('icon.ico') else '',
'--name=SupplementTracker',
'--add-data=README.md;.',
'main.py'
]
# Remove empty elements
cmd = [x for x in cmd if x]
try:
# Run PyInstaller
subprocess.run(cmd, check=True)
print("\nBuild successful! Executable created in 'dist' directory")
# Additional instructions
print("\nTo use the executable:")
print("1. Copy SupplementTracker.exe from the 'dist' directory")
print("2. Run it once with --register to set up file associations:")
print(" SupplementTracker.exe --register")
print("3. You can then double-click .sup files to open them")
except subprocess.CalledProcessError as e:
print(f"Build failed: {e}")
sys.exit(1)
if __name__ == "__main__":
build_exe()