@@ -36,16 +36,29 @@ def build_executable():
3636 '--hidden-import=urllib.request' ,
3737 '--hidden-import=threading' ,
3838 '--hidden-import=validation' , # Include the validation module
39- '--add-data=validation.py:validation.py' , # Include validation.py
40- '--add-data=README.md:README.md' , # Include README
41- '--add-data=LICENSE:LICENSE' , # Include LICENSE
42- '--add-data=requirements.txt:requirements.txt' , # Include requirements
4339 ]
4440
41+ # Add data files
42+ data_files = [
43+ ('validation.py' , 'validation.py' ),
44+ ('README.md' , 'README.md' ),
45+ ('LICENSE' , 'LICENSE' ),
46+ ('requirements.txt' , 'requirements.txt' )
47+ ]
48+
49+ for src , dest in data_files :
50+ if os .path .exists (src ):
51+ cmd .append (f'--add-data={ src } :{ dest } ' )
52+ print (f"Including data file: { src } " )
53+ else :
54+ print (f"Warning: Data file { src } not found, skipping" )
55+
4556 # Add icon if it exists
4657 if sys .platform == 'darwin' : # macOS
4758 icon_path = 'assets/icon.icns'
48- else : # Windows/Linux
59+ elif sys .platform == 'win32' : # Windows
60+ icon_path = 'assets/icon.ico'
61+ else : # Linux
4962 icon_path = 'assets/icon.ico'
5063
5164 if os .path .exists (icon_path ):
@@ -56,14 +69,58 @@ def build_executable():
5669
5770 # Add assets directory if it exists
5871 if os .path .exists ('assets' ):
59- cmd .append ('--add-data=assets:assets' )
72+ if sys .platform == 'win32' : # Windows
73+ cmd .append ('--add-data=assets;assets' )
74+ else : # macOS and Linux
75+ cmd .append ('--add-data=assets:assets' )
6076 print ("Including assets directory" )
6177
6278 # Add the main script
6379 cmd .append ('sd_formatter.py' )
6480
6581 # Run PyInstaller
66- subprocess .run (cmd , check = True )
82+ print (f"Running PyInstaller with command: { ' ' .join (cmd )} " )
83+ result = subprocess .run (cmd , check = False , capture_output = True , text = True )
84+
85+ if result .returncode != 0 :
86+ print (f"PyInstaller failed with return code { result .returncode } " )
87+ print ("STDOUT:" )
88+ print (result .stdout )
89+ print ("STDERR:" )
90+ print (result .stderr )
91+ raise Exception ("PyInstaller build failed" )
92+ else :
93+ print ("PyInstaller completed successfully" )
94+
95+ # Verify the executable was created
96+ if sys .platform == 'darwin' : # macOS
97+ expected_path = 'dist/PicoCalc-SD-Formatter.app'
98+ if os .path .isdir (expected_path ):
99+ print (f"macOS app bundle created at: { expected_path } " )
100+ else :
101+ print (f"Error: macOS app bundle not found at { expected_path } " )
102+ print ("Contents of dist directory:" )
103+ print (os .listdir ('dist' ))
104+ raise FileNotFoundError (f"macOS app bundle not found at { expected_path } " )
105+ elif sys .platform == 'win32' : # Windows
106+ expected_path = 'dist/PicoCalc-SD-Formatter.exe'
107+ if os .path .isfile (expected_path ):
108+ print (f"Windows executable created at: { expected_path } " )
109+ else :
110+ print (f"Error: Windows executable not found at { expected_path } " )
111+ print ("Contents of dist directory:" )
112+ print (os .listdir ('dist' ))
113+ raise FileNotFoundError (f"Windows executable not found at { expected_path } " )
114+ else : # Linux
115+ expected_path = 'dist/PicoCalc-SD-Formatter'
116+ if os .path .isfile (expected_path ):
117+ print (f"Linux executable created at: { expected_path } " )
118+ else :
119+ print (f"Error: Linux executable not found at { expected_path } " )
120+ print ("Contents of dist directory:" )
121+ print (os .listdir ('dist' ))
122+ raise FileNotFoundError (f"Linux executable not found at { expected_path } " )
123+
67124 print ("Build complete." )
68125
69126def create_version_file ():
@@ -92,30 +149,65 @@ def create_release_package():
92149 os .makedirs (release_dir )
93150
94151 # Copy executable and necessary files
95- if sys .platform == 'darwin' :
96- shutil .copytree ('dist/PicoCalc-SD-Formatter.app' , os .path .join (release_dir , 'PicoCalc-SD-Formatter.app' ))
152+ if sys .platform == 'darwin' : # macOS
153+ if os .path .exists ('dist/PicoCalc-SD-Formatter.app' ):
154+ shutil .copytree ('dist/PicoCalc-SD-Formatter.app' , os .path .join (release_dir , 'PicoCalc-SD-Formatter.app' ))
155+ else :
156+ print ("Warning: macOS app bundle not found, skipping copy" )
157+ elif sys .platform == 'win32' : # Windows
158+ if os .path .exists ('dist/PicoCalc-SD-Formatter.exe' ):
159+ shutil .copy ('dist/PicoCalc-SD-Formatter.exe' , release_dir )
160+ else :
161+ print ("Warning: Windows executable not found, skipping copy" )
162+ else : # Linux
163+ if os .path .exists ('dist/PicoCalc-SD-Formatter' ):
164+ shutil .copy ('dist/PicoCalc-SD-Formatter' , release_dir )
165+ else :
166+ print ("Warning: Linux executable not found, skipping copy" )
167+
168+ # Copy version file
169+ if os .path .exists ('dist/VERSION.txt' ):
170+ shutil .copy ('dist/VERSION.txt' , release_dir )
97171 else :
98- shutil . copy ( 'dist/PicoCalc-SD-Formatter' , release_dir )
172+ print ( "Warning: VERSION.txt not found, skipping copy" )
99173
100- shutil .copy ('dist/VERSION.txt' , release_dir )
101- shutil .copy ('README.md' , release_dir )
174+ # Copy README
175+ if os .path .exists ('README.md' ):
176+ shutil .copy ('README.md' , release_dir )
177+ else :
178+ print ("Warning: README.md not found, skipping copy" )
102179
103180 # Create a zip file of the release
104- shutil .make_archive (
105- f'PicoCalc-SD-Formatter-v1.0.0-{ sys .platform } ' ,
106- 'zip' ,
107- release_dir
108- )
181+ platform_suffix = 'win' if sys .platform == 'win32' else ('mac' if sys .platform == 'darwin' else 'linux' )
182+ zip_filename = f'PicoCalc-SD-Formatter-v1.0.0-{ platform_suffix } '
109183
110- print ("Release package created." )
184+ try :
185+ shutil .make_archive (
186+ zip_filename ,
187+ 'zip' ,
188+ release_dir
189+ )
190+ print (f"Release package created: { zip_filename } .zip" )
191+ except Exception as e :
192+ print (f"Error creating zip archive: { e } " )
193+
194+ print ("Release package creation complete." )
111195
112196def main ():
113197 """Main build process"""
114198 try :
199+ print (f"Starting build process on platform: { sys .platform } " )
200+ print (f"Python version: { sys .version } " )
201+ print (f"Current directory: { os .getcwd ()} " )
202+
203+ # Create dist directory if it doesn't exist
204+ os .makedirs ('dist' , exist_ok = True )
205+
115206 clean_build ()
116207 build_executable ()
117208 create_version_file ()
118209 create_release_package ()
210+
119211 print ("\n Build process completed successfully!" )
120212 print ("\n Next steps:" )
121213 print ("1. Test the executable in the 'dist' directory" )
0 commit comments