#!/usr/bin/env python3 """ Build script for creating binary executables from the CLI and web tools. """ import subprocess import sys import os def build_binary(script_name, output_name=None): """Build a binary from a Python script using PyInstaller.""" if output_name is None: output_name = script_name.replace('.py', '') print(f"Building {script_name} -> {output_name}...") cmd = [ 'pyinstaller', '--onefile', # Create a single executable file '--name', output_name, '--clean', # Clean PyInstaller cache script_name ] # Add hidden imports that might be needed hidden_imports = [ 'mpremote.transport_serial', 'mpremote.transport', 'mpremote.console', 'mpremote.mp_errno', 'serial', 'serial.tools.list_ports', ] for imp in hidden_imports: cmd.extend(['--hidden-import', imp]) # Include the lib directory cmd.extend(['--add-data', 'lib:lib']) result = subprocess.run(cmd, cwd=os.path.dirname(os.path.abspath(__file__))) if result.returncode == 0: print(f"✓ Successfully built {output_name}") print(f" Binary location: dist/{output_name}") else: print(f"✗ Failed to build {output_name}") return False return True if __name__ == '__main__': print("Building binaries for led-tool...") print("=" * 60) success = True # Build CLI binary if build_binary('cli.py', 'led-cli'): print() else: success = False # Optionally build web binary (commented out as it's less common) # if build_binary('web.py', 'led-tool-web'): # print() # else: # success = False if success: print("=" * 60) print("Build complete! Binaries are in the 'dist' directory.") else: print("=" * 60) print("Build failed. Check errors above.") sys.exit(1)