Bundle-python
Version 20 (Adrian Georgescu, 11/03/2016 10:01 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 | 1 | Saúl Ibarra Corretgé | |
8 | 7 | Adrian Georgescu | h2. Building the Python Framework itself |
9 | 1 | Saúl Ibarra Corretgé | |
10 | 18 | Saúl Ibarra Corretgé | * Install it using Homebrew |
11 | 1 | Saúl Ibarra Corretgé | |
12 | 1 | Saúl Ibarra Corretgé | <pre> |
13 | 18 | Saúl Ibarra Corretgé | brew install python |
14 | 1 | Saúl Ibarra Corretgé | </pre> |
15 | 1 | Saúl Ibarra Corretgé | |
16 | 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. |
17 | 1 | Saúl Ibarra Corretgé | |
18 | 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. |
19 | 13 | Saúl Ibarra Corretgé | |
20 | 1 | Saúl Ibarra Corretgé | |
21 | 2 | Saúl Ibarra Corretgé | * Reduce the size of the Python Framework: |
22 | 2 | Saúl Ibarra Corretgé | |
23 | 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: |
24 | 1 | Saúl Ibarra Corretgé | |
25 | 1 | Saúl Ibarra Corretgé | <pre> |
26 | 12 | Adrian Georgescu | *.pyc |
27 | 3 | Saúl Ibarra Corretgé | *.pyo |
28 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/config/python.o |
29 | 1 | Saúl Ibarra Corretgé | Versions/Current/Mac |
30 | 12 | Adrian Georgescu | Versions/Current/bin |
31 | 3 | Saúl Ibarra Corretgé | Versions/Current/share |
32 | 18 | Saúl Ibarra Corretgé | Versions/Current/Resources/* |
33 | 3 | Saúl Ibarra Corretgé | Versions/Current/Resources/*.app |
34 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/test |
35 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/plat-* |
36 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/idlelib |
37 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/curses |
38 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib2to3 |
39 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-tk |
40 | 3 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/bsddb |
41 | 18 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-dynload/gdbm.so |
42 | 18 | Saúl Ibarra Corretgé | Versions/Current/lib/python2.7/lib-dynload/readline.so |
43 | 1 | Saúl Ibarra Corretgé | </pre> |
44 | 3 | Saúl Ibarra Corretgé | |
45 | 4 | Saúl Ibarra Corretgé | * Prevent system paths from being used with this bundle |
46 | 4 | Saúl Ibarra Corretgé | |
47 | 17 | Saúl Ibarra Corretgé | Replace @Versions/Current/lib/python2.7/site.py@ with an empty file. |
48 | 5 | Saúl Ibarra Corretgé | |
49 | 5 | Saúl Ibarra Corretgé | h2. Compiling PyObjC |
50 | 5 | Saúl Ibarra Corretgé | |
51 | 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. |
52 | 5 | Saúl Ibarra Corretgé | |
53 | 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: |
54 | 1 | Saúl Ibarra Corretgé | |
55 | 5 | Saúl Ibarra Corretgé | <pre> |
56 | 5 | Saúl Ibarra Corretgé | pip install pyobjc-core |
57 | 5 | Saúl Ibarra Corretgé | pip install pyobjc |
58 | 1 | Saúl Ibarra Corretgé | </pre> |
59 | 1 | Saúl Ibarra Corretgé | |
60 | 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: |
61 | 5 | Saúl Ibarra Corretgé | |
62 | 5 | Saúl Ibarra Corretgé | <pre> |
63 | 5 | Saúl Ibarra Corretgé | AddressBook |
64 | 5 | Saúl Ibarra Corretgé | AppKit |
65 | 1 | Saúl Ibarra Corretgé | Cocoa |
66 | 5 | Saúl Ibarra Corretgé | CoreFoundation |
67 | 5 | Saúl Ibarra Corretgé | Foundation |
68 | 13 | Saúl Ibarra Corretgé | JavaScriptCore |
69 | 5 | Saúl Ibarra Corretgé | LaunchServices |
70 | 1 | Saúl Ibarra Corretgé | PyObjCTools |
71 | 1 | Saúl Ibarra Corretgé | Quartz |
72 | 13 | Saúl Ibarra Corretgé | ScriptingBridge |
73 | 13 | Saúl Ibarra Corretgé | StoreKit |
74 | 1 | Saúl Ibarra Corretgé | WebKit |
75 | 8 | Adrian Georgescu | objc |
76 | 6 | Saúl Ibarra Corretgé | </pre> |
77 | 6 | Saúl Ibarra Corretgé | |
78 | 6 | Saúl Ibarra Corretgé | *NOTE:* The _objc_ package is located inside a _PyObjC_ directory, just copy it from there, without the parent directory. |
79 | 6 | Saúl Ibarra Corretgé | |
80 | 20 | 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: |
81 | 20 | Adrian Georgescu | |
82 | 20 | Adrian Georgescu | <pre> |
83 | 20 | Adrian Georgescu | __import__('pkg_resources').declare_namespace(__name__) |
84 | 20 | Adrian Georgescu | </pre> |
85 | 6 | Saúl Ibarra Corretgé | |
86 | 16 | Saúl Ibarra Corretgé | h2. Module exceptions |
87 | 16 | Saúl Ibarra Corretgé | |
88 | 16 | Saúl Ibarra Corretgé | When copying built Python modules into the distribution folder, care must be taken with the 2 following packages: |
89 | 16 | Saúl Ibarra Corretgé | |
90 | 16 | Saúl Ibarra Corretgé | * zope: an empty @__init__.py@ file must be created in the @zope@ directory |
91 | 16 | Saúl Ibarra Corretgé | * cryptography: the @*-dist.info@ must be copied too |
92 | 6 | Saúl Ibarra Corretgé | |
93 | 14 | Saúl Ibarra Corretgé | h1. Creating a sandbox (Python virtualenv) |
94 | 6 | Saúl Ibarra Corretgé | |
95 | 6 | Saúl Ibarra Corretgé | <pre> |
96 | 6 | Saúl Ibarra Corretgé | sudo easy_install pip |
97 | 6 | Saúl Ibarra Corretgé | sudo pip install virtualenv virtualenvwrapper |
98 | 6 | Saúl Ibarra Corretgé | </pre> |
99 | 6 | Saúl Ibarra Corretgé | |
100 | 6 | Saúl Ibarra Corretgé | Add to ~.bashrc |
101 | 6 | Saúl Ibarra Corretgé | |
102 | 9 | Adrian Georgescu | <pre> |
103 | 9 | Adrian Georgescu | # Virtualenv |
104 | 9 | Adrian Georgescu | export WORKON_HOME=$HOME/.virtualenvs |
105 | 9 | Adrian Georgescu | export PIP_VIRTUALENV_BASE=$WORKON_HOME |
106 | 9 | Adrian Georgescu | export PIP_RESPECT_VIRTUALENV=true |
107 | 9 | Adrian Georgescu | export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh |
108 | 9 | Adrian Georgescu | [[ -f /usr/local/bin/virtualenvwrapper_lazy.sh ]] && source /usr/local/bin/virtualenvwrapper_lazy.sh |
109 | 9 | Adrian Georgescu | </pre> |
110 | 10 | Adrian Georgescu | |
111 | 13 | Saúl Ibarra Corretgé | Creating a sandbox: |
112 | 10 | Adrian Georgescu | |
113 | 10 | Adrian Georgescu | <pre> |
114 | 13 | Saúl Ibarra Corretgé | mkvirtualenv -p $(which python2.7) sandbox |
115 | 13 | Saúl Ibarra Corretgé | </pre> |
116 | 13 | Saúl Ibarra Corretgé | |
117 | 13 | Saúl Ibarra Corretgé | Exiting the sandbox: |
118 | 13 | Saúl Ibarra Corretgé | |
119 | 13 | Saúl Ibarra Corretgé | <pre> |
120 | 10 | Adrian Georgescu | deactivate |
121 | 13 | Saúl Ibarra Corretgé | </pre> |
122 | 13 | Saúl Ibarra Corretgé | |
123 | 13 | Saúl Ibarra Corretgé | Entering the sandbox: |
124 | 13 | Saúl Ibarra Corretgé | |
125 | 13 | Saúl Ibarra Corretgé | <pre> |
126 | 11 | Adrian Georgescu | workon sandbox |
127 | 11 | Adrian Georgescu | </pre> |
128 | 19 | Adrian Georgescu | |
129 | 19 | Adrian Georgescu | h2. Content of a Resources/lib bundled with Blink (as of November 3rd, 2016) |
130 | 19 | Adrian Georgescu | |
131 | 19 | Adrian Georgescu | <pre> |
132 | 19 | Adrian Georgescu | AVFoundation |
133 | 19 | Adrian Georgescu | AddressBook |
134 | 19 | Adrian Georgescu | AppKit |
135 | 19 | Adrian Georgescu | Cocoa |
136 | 19 | Adrian Georgescu | CoreFoundation |
137 | 19 | Adrian Georgescu | Crypto |
138 | 19 | Adrian Georgescu | Foundation |
139 | 19 | Adrian Georgescu | LaunchServices |
140 | 19 | Adrian Georgescu | PyObjCTools |
141 | 19 | Adrian Georgescu | Quartz |
142 | 19 | Adrian Georgescu | ScriptingBridge |
143 | 19 | Adrian Georgescu | WebKit |
144 | 19 | Adrian Georgescu | _cffi_backend.so |
145 | 19 | Adrian Georgescu | _ldap.so |
146 | 19 | Adrian Georgescu | _markerlib |
147 | 19 | Adrian Georgescu | application |
148 | 19 | Adrian Georgescu | cffi |
149 | 19 | Adrian Georgescu | cjson.so |
150 | 19 | Adrian Georgescu | cryptography |
151 | 19 | Adrian Georgescu | cryptography-1.5.1.dist-info |
152 | 19 | Adrian Georgescu | dateutil |
153 | 19 | Adrian Georgescu | dns |
154 | 19 | Adrian Georgescu | dsml.py |
155 | 19 | Adrian Georgescu | enum |
156 | 19 | Adrian Georgescu | eventlib |
157 | 19 | Adrian Georgescu | formencode |
158 | 19 | Adrian Georgescu | gmpy2.so |
159 | 19 | Adrian Georgescu | gnutls |
160 | 19 | Adrian Georgescu | greenlet.so |
161 | 19 | Adrian Georgescu | idna |
162 | 19 | Adrian Georgescu | ipaddress.py |
163 | 19 | Adrian Georgescu | ldap |
164 | 19 | Adrian Georgescu | ldapurl.py |
165 | 19 | Adrian Georgescu | ldif.py |
166 | 19 | Adrian Georgescu | lxml |
167 | 19 | Adrian Georgescu | msrplib |
168 | 19 | Adrian Georgescu | objc |
169 | 19 | Adrian Georgescu | otr |
170 | 19 | Adrian Georgescu | pkg_resources |
171 | 19 | Adrian Georgescu | pyasn1 |
172 | 19 | Adrian Georgescu | pycparser |
173 | 19 | Adrian Georgescu | pydispatch |
174 | 19 | Adrian Georgescu | pytz |
175 | 19 | Adrian Georgescu | service_identity |
176 | 19 | Adrian Georgescu | sipsimple |
177 | 19 | Adrian Georgescu | six.py |
178 | 19 | Adrian Georgescu | sqlobject |
179 | 19 | Adrian Georgescu | twisted |
180 | 19 | Adrian Georgescu | xcaplib |
181 | 19 | Adrian Georgescu | </pre> |