Skip to content

Commit e3a8ff8

Browse files
committed
Enhancing build script to enable apple codesigning and notarizing. Not yet working
1 parent 1ac6e25 commit e3a8ff8

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

build.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
1616
MacOS
1717
- brew install portaudio
18+
- if you're using pyenv, you might also need to install tkinter manually.
19+
I followed this guide https://dev.to/xshapira/using-tkinter-with-pyenv-a-simple-two-step-guide-hh5.
1820
1921
NOTES:
2022
1. For use in future projects, note that pyinstaller will print hundreds of unrelated error messages, but to find
@@ -35,15 +37,32 @@
3537

3638
import os
3739
import platform
40+
import sys
3841

3942
import PyInstaller.__main__
4043

4144
from app.version import version
4245

4346

44-
def build():
47+
def build(signing_key=None):
4548
input("Did you remember to increment version.py?")
49+
macos = platform.system() == 'Darwin'
4650

51+
compile(signing_key)
52+
53+
if macos and signing_key: # Codesign
54+
os.system(
55+
f'codesign --deep --force --verbose --sign "{signing_key}" dist/Open\\ Interface.app --options runtime')
56+
57+
# TODO: codesigning is invalid after I zip using this method, but remains valid if I zip using UI Archive.
58+
zip_name = zip()
59+
60+
if macos and signing_key: # Notarize
61+
keychain_profile = signing_key.split('(')[0].strip()
62+
os.system(f'xcrun notarytool submit --wait --keychain-profile "{keychain_profile}" --verbose dist/{zip_name}')
63+
64+
65+
def compile(signing_key=None):
4766
# Path to your main application script
4867
app_script = os.path.join('app', 'app.py')
4968

@@ -85,7 +104,11 @@ def build():
85104
]
86105

87106
# Platform-specific options
88-
if platform.system() == 'Linux':
107+
if platform.system() == 'Darwin': # MacOS
108+
pyinstaller_options.extend([
109+
f'--codesign-identity={signing_key}'
110+
])
111+
elif platform.system() == 'Linux':
89112
pyinstaller_options.extend([
90113
'--hidden-import=PIL._tkinter_finder',
91114
'--hidden-import=openai',
@@ -100,26 +123,32 @@ def build():
100123
PyInstaller.__main__.run(pyinstaller_options)
101124
print('Done. Check dist/ for executables.')
102125

126+
127+
def zip():
103128
# Zip the app
104129
print('Zipping the executables')
105130
app_name = 'Open\\ Interface'
106131

132+
zip_name = 'Open-Interface-v' + str(version)
107133
if platform.system() == 'Darwin': # MacOS
108-
zip_name = 'Open-Interface-v' + str(version) + '-MacOS' + '.zip'
134+
zip_name = zip_name + '-MacOS' + '.zip'
109135
zip_cli_command = 'cd dist/; zip -r9 ' + zip_name + ' ' + app_name + '.app'
110-
input(f'zip_cli_command - {zip_cli_command} \nExecute?')
111-
os.system(zip_cli_command)
112136
elif platform.system() == 'Linux':
113-
zip_name = 'Open-Interface-v' + str(version) + '-Linux' + '.zip'
137+
zip_name = zip_name + '-Linux' + '.zip'
114138
zip_cli_command = 'cd dist/; zip -r9 ' + zip_name + ' ' + app_name
115-
input(f'zip_cli_command - {zip_cli_command} \nExecute?')
116-
os.system(zip_cli_command)
117139
elif platform.system() == 'Windows':
118-
zip_name = 'Open-Interface-v' + str(version) + '-Windows' + '.zip'
140+
zip_name = zip_name + '-Windows' + '.zip'
119141
zip_cli_command = 'cd dist & powershell Compress-Archive -Path \'Open Interface.exe\' -DestinationPath ' + zip_name
120-
input(f'zip_cli_command - {zip_cli_command} \nExecute?')
121-
os.system(zip_cli_command)
142+
143+
# input(f'zip_cli_command - {zip_cli_command} \nExecute?')
144+
os.system(zip_cli_command)
145+
return zip_name
122146

123147

124148
if __name__ == "__main__":
125-
build()
149+
apple_code_signing_key = None
150+
if len(sys.argv) > 1:
151+
apple_code_signing_key = sys.argv[1] # Developer ID Application: ... (...)
152+
print("apple_code_signing_key: ", apple_code_signing_key)
153+
154+
build(apple_code_signing_key)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ exceptiongroup==1.2.0
77
h11==0.14.0
88
httpcore==1.0.2
99
httpx==0.26.0
10-
idna==3.6
10+
idna==3.7
1111
MouseInfo==0.1.3
1212
openai==1.9.0
13-
pillow==10.2.0
13+
pillow==10.3.0
1414
PyAudio==0.2.14
1515
PyAutoGUI==0.9.54
1616
pydantic==2.5.3
@@ -27,7 +27,7 @@ pytweening==1.0.7
2727
requests==2.31.0
2828
rubicon-objc==0.4.7
2929
sniffio==1.3.0
30-
SpeechRecognition==3.10.1
30+
SpeechRecognition==3.10.3
3131
tqdm==4.66.1
3232
typing_extensions==4.9.0
3333
urllib3==2.2.0

0 commit comments

Comments
 (0)