| 73 | |
| 74 | |
| 75 | def compile(signing_key=None): |
| 76 | # Path to your main application script |
| 77 | app_script = os.path.join('app', 'app.py') |
| 78 | |
| 79 | # Common PyInstaller options |
| 80 | pyinstaller_options = [ |
| 81 | '--clean', |
| 82 | '--noconfirm', |
| 83 | |
| 84 | # Debug |
| 85 | # '--debug=all', |
| 86 | |
| 87 | # --- Basics --- # |
| 88 | '--name=Open Interface', |
| 89 | '--icon=app/resources/icon.png', |
| 90 | '--windowed', # Remove this if your application is a console program, also helps to remove this while debugging |
| 91 | # '--onefile', # NOTE: Might not work on Windows. Also discouraged to enable both windowed and one file on Mac. |
| 92 | |
| 93 | # Where to find necessary packages to bundle (python3 -m pip show xxx) |
| 94 | '--paths=./env/lib/python3.12/site-packages', |
| 95 | |
| 96 | # Packaging fails without explicitly including these modules here as shown by the logs outputted by debug=all |
| 97 | '--hidden-import=pyautogui', |
| 98 | '--hidden-import=appdirs', |
| 99 | '--hidden-import=pyparsing', |
| 100 | '--hidden-import=ttkbootstrap', |
| 101 | '--hidden-import=openai', |
| 102 | |
| 103 | # pypi google_genai doesn't play nice with pyinstaller without this |
| 104 | '--hidden-import=google_genai', |
| 105 | '--hidden-import=google', |
| 106 | '--hidden-import=google.genai', |
| 107 | |
| 108 | # NOTE: speech_recognition is the name of the directory that this package is in within ../site-packages/, |
| 109 | # whereas the pypi name is SpeechRecognition (pip install SpeechRecognition). |
| 110 | # This was hard to pin down and took a long time to debug. |
| 111 | # '--hidden-import=speech_recognition', |
| 112 | |
| 113 | # Static files and resources --add-data=src:dest |
| 114 | # - File reads change accordingly - https://pyinstaller.org/en/stable/runtime-information.html#placing-data-files-at-expected-locations-inside-the-bundle |
| 115 | '--add-data=app/resources/*:resources', |
| 116 | |
| 117 | # Manually including source code and submodules because app doesn't launch without it |
| 118 | '--add-data=app/*.py:.', |
| 119 | '--add-data=app/utils/*.py:utils', # Submodules need to be included manually |
| 120 | '--add-data=app/models/*.py:models', # Submodules need to be included manually |
| 121 | |
| 122 | app_script |
| 123 | ] |
| 124 | |
| 125 | # Platform-specific options |
| 126 | if platform.system() == 'Darwin': # MacOS |
| 127 | if signing_key: |
| 128 | pyinstaller_options.extend([ |
| 129 | f'--codesign-identity={signing_key}' |
| 130 | ]) |
| 131 | # Apple Notarization has a problem because this binary used in speech_recognition is signed with too old an SDK |
| 132 | # from PyInstaller.utils.osx import set_macos_sdk_version |