Bundle-python
Version 23 (Adrian Georgescu, 11/07/2016 02:12 pm)
1 | 1 | Saúl Ibarra Corretgé | h1. Building a Python Framework to bundle inside Blink |
---|---|---|---|
2 | 1 | Saúl Ibarra Corretgé | |
3 | 1 | Saúl Ibarra Corretgé | In order to avoid using the system Python a custom Framework build is needed. Using a bundled Python version will make the package bigger in size, but all package versions are controlled and not up to the environment. Also, we can use the latest Python version, with latest bugfixes and features, since Apple only updates the system Python version on every major OS release. |
4 | 1 | Saúl Ibarra Corretgé | |
5 | 13 | Saúl Ibarra Corretgé | The following instructions only apply for 64bit builds, 32bit builds are no longer supported. |
6 | 7 | Adrian Georgescu | |
7 | 22 | Adrian Georgescu | Blink dependencies must be installed under the following directory structure: |
8 | 22 | Adrian Georgescu | |
9 | 22 | Adrian Georgescu | * Distribution/Frameworks/ |
10 | 22 | Adrian Georgescu | * Distribution/Resources/lib |
11 | 1 | Saúl Ibarra Corretgé | |
12 | 7 | Adrian Georgescu | h2. Building the Python Framework itself |
13 | 1 | Saúl Ibarra Corretgé | |
14 | 18 | Saúl Ibarra Corretgé | * Install it using Homebrew |
15 | 1 | Saúl Ibarra Corretgé | |
16 | 1 | Saúl Ibarra Corretgé | <pre> |
17 | 18 | Saúl Ibarra Corretgé | brew install python |
18 | 1 | Saúl Ibarra Corretgé | </pre> |
19 | 1 | Saúl Ibarra Corretgé | |
20 | 18 | Saúl Ibarra Corretgé | The framework will be installed and linked with Homebrew supplied OpenSSL and SQLite versions. Those libraries will need to be copied too. |
21 | 1 | Saúl Ibarra Corretgé | |
22 | 18 | Saúl Ibarra Corretgé | *NOTE*: Be careful when copying the framework around, it contains symlinks and if @cp -r@ is used the size will we doubled, use @cp -a@ instead. |
23 | 22 | Adrian Georgescu | |
24 | 22 | Adrian Georgescu | The Python framework is found in |
25 | 22 | Adrian Georgescu | |
26 | 22 | Adrian Georgescu | <pre> |
27 | 22 | Adrian Georgescu | /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/ |
28 | 22 | Adrian Georgescu | </pre> |
29 | 22 | Adrian Georgescu | |
30 | 22 | Adrian Georgescu | *NOTE*: Python.framework as well as all other libraries must be signed using command line tools. Make sure when building Blink that "Code sign on copy" option is disabled for Python.framework. This script can be used to sign all libraries and frameworks |
31 | 22 | Adrian Georgescu | |
32 | 22 | Adrian Georgescu | <pre> |
33 | 22 | Adrian Georgescu | sos=`find ./Resources/lib -name *.so`; for s in $sos; do codesign -f -s '3rd Party Mac Developer Application: AG Projects' $s; done |
34 | 22 | Adrian Georgescu | sos=`find ./Frameworks -name *.dylib`; for s in $sos; do codesign -f -s '3rd Party Mac Developer Application: AG Projects' $s; done |
35 | 22 | Adrian Georgescu | sos=`find ./Frameworks -name *.so`; for s in $sos; do codesign -f -s '3rd Party Mac Developer Application: AG Projects' $s; done |
36 | 22 | Adrian Georgescu | sos=`find ./Frameworks -name *.o`; for s in $sos; do codesign -f -s '3rd Party Mac Developer Application: AG Projects' $s; done |
37 | 22 | Adrian Georgescu | sos=`find ./Frameworks -name *.a`; for s in $sos; do codesign -f -s '3rd Party Mac Developer Application: AG Projects' $s; done |
38 | 22 | Adrian Georgescu | </pre> |
39 | 13 | Saúl Ibarra Corretgé | |
40 | 1 | Saúl Ibarra Corretgé | |
41 | 2 | Saúl Ibarra Corretgé | * Reduce the size of the Python Framework: |
42 | 2 | Saúl Ibarra Corretgé | |
43 | 1 | Saúl Ibarra Corretgé | There are a number of things that can (and must when submitting a sandbox app to Mac App Store) be removed from the framework directory to make it smaller in size: |
44 | 1 | Saúl Ibarra Corretgé | |
45 | 1 | Saúl Ibarra Corretgé | <pre> |
46 | 12 | Adrian Georgescu | *.pyc |
47 | 3 | Saúl Ibarra Corretgé | *.pyo |
48 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/config/python.o |
49 | 1 | Saúl Ibarra Corretgé | Versions/Current/Mac |
50 | 12 | Adrian Georgescu | Versions/Current/bin |
51 | 3 | Saúl Ibarra Corretgé | Versions/Current/share |
52 | 18 | Saúl Ibarra Corretgé | Versions/Current/Resources/* |
53 | 3 | Saúl Ibarra Corretgé | Versions/Current/Resources/*.app |
54 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/test |
55 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/plat-* |
56 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/idlelib |
57 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/curses |
58 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib2to3 |
59 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-tk |
60 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/bsddb |
61 | 18 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-dynload/gdbm.so |
62 | 18 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-dynload/readline.so |
63 | 1 | Saúl Ibarra Corretgé | </pre> |
64 | 3 | Saúl Ibarra Corretgé | |
65 | 4 | Saúl Ibarra Corretgé | * Prevent system paths from being used with this bundle |
66 | 4 | Saúl Ibarra Corretgé | |
67 | 17 | Saúl Ibarra Corretgé | Replace @Versions/Current/lib/python2.7/site.py@ with an empty file. |
68 | 5 | Saúl Ibarra Corretgé | |
69 | 5 | Saúl Ibarra Corretgé | h2. Compiling PyObjC |
70 | 5 | Saúl Ibarra Corretgé | |
71 | 13 | Saúl Ibarra Corretgé | In order to get a PyObjC version that will work with the framework created above (Python 2.7, 64bits) an equivalent Python must be used to compile it. That is, if has to be a Python 2.7 version (it doesn't have to be the exact version) and it has to be a 64bit version. The MACOSX_DEPLOYMENT_TARGET must also be set to the appropriate value. |
72 | 5 | Saúl Ibarra Corretgé | |
73 | 5 | Saúl Ibarra Corretgé | PyObjcC can be installed with easy_install or pip. We install it in 2 steps to save some compilation time due to a bug in the build system: |
74 | 1 | Saúl Ibarra Corretgé | |
75 | 5 | Saúl Ibarra Corretgé | <pre> |
76 | 5 | Saúl Ibarra Corretgé | pip install pyobjc-core |
77 | 5 | Saúl Ibarra Corretgé | pip install pyobjc |
78 | 23 | Adrian Georgescu | pip install pycrypto |
79 | 1 | Saúl Ibarra Corretgé | </pre> |
80 | 1 | Saúl Ibarra Corretgé | |
81 | 5 | Saúl Ibarra Corretgé | When compiling PyObjC a Python package will be created for every system framework, but not all of them are needed (at the moment), so just pick the ones we use: |
82 | 5 | Saúl Ibarra Corretgé | |
83 | 5 | Saúl Ibarra Corretgé | <pre> |
84 | 5 | Saúl Ibarra Corretgé | AddressBook |
85 | 5 | Saúl Ibarra Corretgé | AppKit |
86 | 1 | Saúl Ibarra Corretgé | Cocoa |
87 | 5 | Saúl Ibarra Corretgé | CoreFoundation |
88 | 5 | Saúl Ibarra Corretgé | Foundation |
89 | 13 | Saúl Ibarra Corretgé | JavaScriptCore |
90 | 5 | Saúl Ibarra Corretgé | LaunchServices |
91 | 1 | Saúl Ibarra Corretgé | PyObjCTools |
92 | 1 | Saúl Ibarra Corretgé | Quartz |
93 | 13 | Saúl Ibarra Corretgé | ScriptingBridge |
94 | 13 | Saúl Ibarra Corretgé | StoreKit |
95 | 1 | Saúl Ibarra Corretgé | WebKit |
96 | 8 | Adrian Georgescu | objc |
97 | 6 | Saúl Ibarra Corretgé | </pre> |
98 | 6 | Saúl Ibarra Corretgé | |
99 | 1 | Saúl Ibarra Corretgé | |
100 | 21 | Adrian Georgescu | For example this is the content of a Resources/lib bundled with Blink Cocoa as of November 3rd, 2016 (including sipsimple dependencies & all): |
101 | 20 | Adrian Georgescu | |
102 | 1 | Saúl Ibarra Corretgé | <pre> |
103 | 1 | Saúl Ibarra Corretgé | AVFoundation |
104 | 1 | Saúl Ibarra Corretgé | AddressBook |
105 | 1 | Saúl Ibarra Corretgé | AppKit |
106 | 1 | Saúl Ibarra Corretgé | Cocoa |
107 | 1 | Saúl Ibarra Corretgé | CoreFoundation |
108 | 1 | Saúl Ibarra Corretgé | Crypto |
109 | 1 | Saúl Ibarra Corretgé | Foundation |
110 | 1 | Saúl Ibarra Corretgé | LaunchServices |
111 | 1 | Saúl Ibarra Corretgé | PyObjCTools |
112 | 1 | Saúl Ibarra Corretgé | Quartz |
113 | 1 | Saúl Ibarra Corretgé | ScriptingBridge |
114 | 1 | Saúl Ibarra Corretgé | WebKit |
115 | 1 | Saúl Ibarra Corretgé | _cffi_backend.so |
116 | 1 | Saúl Ibarra Corretgé | _ldap.so |
117 | 1 | Saúl Ibarra Corretgé | _markerlib |
118 | 1 | Saúl Ibarra Corretgé | application |
119 | 1 | Saúl Ibarra Corretgé | cffi |
120 | 1 | Saúl Ibarra Corretgé | cjson.so |
121 | 1 | Saúl Ibarra Corretgé | cryptography |
122 | 1 | Saúl Ibarra Corretgé | cryptography-1.5.1.dist-info |
123 | 1 | Saúl Ibarra Corretgé | dateutil |
124 | 1 | Saúl Ibarra Corretgé | dns |
125 | 1 | Saúl Ibarra Corretgé | dsml.py |
126 | 1 | Saúl Ibarra Corretgé | enum |
127 | 1 | Saúl Ibarra Corretgé | eventlib |
128 | 1 | Saúl Ibarra Corretgé | formencode |
129 | 1 | Saúl Ibarra Corretgé | gmpy2.so |
130 | 1 | Saúl Ibarra Corretgé | gnutls |
131 | 1 | Saúl Ibarra Corretgé | greenlet.so |
132 | 1 | Saúl Ibarra Corretgé | idna |
133 | 1 | Saúl Ibarra Corretgé | ipaddress.py |
134 | 1 | Saúl Ibarra Corretgé | ldap |
135 | 1 | Saúl Ibarra Corretgé | ldapurl.py |
136 | 1 | Saúl Ibarra Corretgé | ldif.py |
137 | 1 | Saúl Ibarra Corretgé | lxml |
138 | 1 | Saúl Ibarra Corretgé | msrplib |
139 | 1 | Saúl Ibarra Corretgé | objc |
140 | 1 | Saúl Ibarra Corretgé | otr |
141 | 1 | Saúl Ibarra Corretgé | pkg_resources |
142 | 1 | Saúl Ibarra Corretgé | pyasn1 |
143 | 1 | Saúl Ibarra Corretgé | pycparser |
144 | 1 | Saúl Ibarra Corretgé | pydispatch |
145 | 1 | Saúl Ibarra Corretgé | pytz |
146 | 1 | Saúl Ibarra Corretgé | service_identity |
147 | 1 | Saúl Ibarra Corretgé | sipsimple |
148 | 1 | Saúl Ibarra Corretgé | six.py |
149 | 1 | Saúl Ibarra Corretgé | sqlobject |
150 | 1 | Saúl Ibarra Corretgé | twisted |
151 | 1 | Saúl Ibarra Corretgé | xcaplib |
152 | 21 | Adrian Georgescu | </pre> |
153 | 21 | Adrian Georgescu | |
154 | 21 | Adrian Georgescu | |
155 | 21 | Adrian Georgescu | *NOTE:* The _objc_ package is located inside a _PyObjC_ directory, just copy it from there, without the parent directory. |
156 | 21 | Adrian Georgescu | |
157 | 21 | Adrian Georgescu | *NOTE:* _PyObjCTools_ is not a valid Python package, as it lacks a @__init__.py@ file, an empty one needs to be manually created with this content: |
158 | 21 | Adrian Georgescu | |
159 | 21 | Adrian Georgescu | <pre> |
160 | 21 | Adrian Georgescu | __import__('pkg_resources').declare_namespace(__name__) |
161 | 21 | Adrian Georgescu | </pre> |
162 | 21 | Adrian Georgescu | |
163 | 21 | Adrian Georgescu | h2. Module exceptions |
164 | 21 | Adrian Georgescu | |
165 | 21 | Adrian Georgescu | When copying built Python modules into the distribution folder, care must be taken with the 2 following packages: |
166 | 21 | Adrian Georgescu | |
167 | 21 | Adrian Georgescu | * zope: an empty @__init__.py@ file must be created in the @zope@ directory |
168 | 21 | Adrian Georgescu | * cryptography: the @*-dist.info@ must be copied too |
169 | 21 | Adrian Georgescu | |
170 | 21 | Adrian Georgescu | h1. Creating a sandbox (Python virtualenv) |
171 | 21 | Adrian Georgescu | |
172 | 21 | Adrian Georgescu | <pre> |
173 | 21 | Adrian Georgescu | sudo easy_install pip |
174 | 21 | Adrian Georgescu | sudo pip install virtualenv virtualenvwrapper |
175 | 21 | Adrian Georgescu | </pre> |
176 | 21 | Adrian Georgescu | |
177 | 21 | Adrian Georgescu | Add to ~.bashrc |
178 | 21 | Adrian Georgescu | |
179 | 21 | Adrian Georgescu | <pre> |
180 | 21 | Adrian Georgescu | # Virtualenv |
181 | 21 | Adrian Georgescu | export WORKON_HOME=$HOME/.virtualenvs |
182 | 21 | Adrian Georgescu | export PIP_VIRTUALENV_BASE=$WORKON_HOME |
183 | 21 | Adrian Georgescu | export PIP_RESPECT_VIRTUALENV=true |
184 | 21 | Adrian Georgescu | export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh |
185 | 21 | Adrian Georgescu | [[ -f /usr/local/bin/virtualenvwrapper_lazy.sh ]] && source /usr/local/bin/virtualenvwrapper_lazy.sh |
186 | 21 | Adrian Georgescu | </pre> |
187 | 21 | Adrian Georgescu | |
188 | 21 | Adrian Georgescu | Creating a sandbox: |
189 | 21 | Adrian Georgescu | |
190 | 21 | Adrian Georgescu | <pre> |
191 | 21 | Adrian Georgescu | mkvirtualenv -p $(which python2.7) sandbox |
192 | 21 | Adrian Georgescu | </pre> |
193 | 21 | Adrian Georgescu | |
194 | 21 | Adrian Georgescu | Exiting the sandbox: |
195 | 21 | Adrian Georgescu | |
196 | 21 | Adrian Georgescu | <pre> |
197 | 21 | Adrian Georgescu | deactivate |
198 | 21 | Adrian Georgescu | </pre> |
199 | 21 | Adrian Georgescu | |
200 | 21 | Adrian Georgescu | Entering the sandbox: |
201 | 21 | Adrian Georgescu | |
202 | 21 | Adrian Georgescu | <pre> |
203 | 21 | Adrian Georgescu | workon sandbox |
204 | 19 | Adrian Georgescu | </pre> |