|
1 Make sure the bootstrap script actually works:: |
|
2 |
|
3 >>> import os, sys |
|
4 >>> from os.path import dirname, join |
|
5 >>> import zc.buildout |
|
6 >>> bootstrap_py = join( |
|
7 ... dirname( |
|
8 ... dirname( |
|
9 ... dirname( |
|
10 ... dirname(zc.buildout.__file__) |
|
11 ... ) |
|
12 ... ) |
|
13 ... ), |
|
14 ... 'bootstrap', 'bootstrap.py') |
|
15 >>> sample_buildout = tmpdir('sample') |
|
16 >>> os.chdir(sample_buildout) |
|
17 >>> write('buildout.cfg', |
|
18 ... ''' |
|
19 ... [buildout] |
|
20 ... parts = |
|
21 ... ''') |
|
22 >>> write('bootstrap.py', open(bootstrap_py).read()) |
|
23 >>> print 'X'; print system( |
|
24 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
25 ... 'bootstrap.py'); print 'X' # doctest: +ELLIPSIS |
|
26 X... |
|
27 Creating directory '/sample/bin'. |
|
28 Creating directory '/sample/parts'. |
|
29 Creating directory '/sample/eggs'. |
|
30 Creating directory '/sample/develop-eggs'. |
|
31 Generated script '/sample/bin/buildout'. |
|
32 ... |
|
33 |
|
34 >>> ls(sample_buildout) |
|
35 d bin |
|
36 - bootstrap.py |
|
37 - buildout.cfg |
|
38 d develop-eggs |
|
39 d eggs |
|
40 d parts |
|
41 |
|
42 |
|
43 >>> ls(sample_buildout, 'bin') |
|
44 - buildout |
|
45 |
|
46 >>> print 'X'; ls(sample_buildout, 'eggs') # doctest: +ELLIPSIS |
|
47 X... |
|
48 d zc.buildout-...egg |
|
49 |
|
50 The buildout script it has generated is a new-style script, using a |
|
51 customized site.py. |
|
52 |
|
53 >>> buildout_script = join(sample_buildout, 'bin', 'buildout') |
|
54 >>> if sys.platform.startswith('win'): |
|
55 ... buildout_script += '-script.py' |
|
56 >>> print open(buildout_script).read() # doctest: +ELLIPSIS |
|
57 #... |
|
58 <BLANKLINE> |
|
59 import sys |
|
60 sys.path[0:0] = [ |
|
61 '/sample/parts/buildout', |
|
62 ] |
|
63 <BLANKLINE> |
|
64 <BLANKLINE> |
|
65 import os |
|
66 path = sys.path[0] |
|
67 if os.environ.get('PYTHONPATH'): |
|
68 path = os.pathsep.join([path, os.environ['PYTHONPATH']]) |
|
69 os.environ['BUILDOUT_ORIGINAL_PYTHONPATH'] = os.environ.get('PYTHONPATH', '') |
|
70 os.environ['PYTHONPATH'] = path |
|
71 import site # imports custom buildout-generated site.py |
|
72 <BLANKLINE> |
|
73 import zc.buildout.buildout |
|
74 <BLANKLINE> |
|
75 if __name__ == '__main__': |
|
76 zc.buildout.buildout.main() |
|
77 <BLANKLINE> |
|
78 |
|
79 The bootstrap process prefers final versions of zc.buildout, so it has |
|
80 selected the (generated-locally) 99.99 egg rather than the also-available |
|
81 100.0b1 egg. We can see that in the buildout script's site.py. |
|
82 |
|
83 >>> buildout_site_py = join( |
|
84 ... sample_buildout, 'parts', 'buildout', 'site.py') |
|
85 >>> print open(buildout_site_py).read() # doctest: +ELLIPSIS |
|
86 "... |
|
87 buildout_paths = [ |
|
88 '/sample/eggs/setuptools-...egg', |
|
89 '/sample/eggs/zc.buildout-99.99-pyN.N.egg' |
|
90 ] |
|
91 ... |
|
92 |
|
93 If you want to accept early releases of zc.buildout, you either need to |
|
94 specify an explicit version (using --version here and specifying the |
|
95 version in the buildout configuration file using the |
|
96 ``buildout-version`` option or the ``versions`` option) or specify that you |
|
97 accept early releases by using ``--accept-buildout-test-releases`` on the |
|
98 bootstrap script. |
|
99 |
|
100 Here's an example. |
|
101 |
|
102 >>> ignored = system( |
|
103 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
104 ... 'bootstrap.py --accept-buildout-test-releases') |
|
105 >>> print open(buildout_site_py).read() # doctest: +ELLIPSIS |
|
106 "... |
|
107 buildout_paths = [ |
|
108 '/sample/eggs/setuptools-...egg', |
|
109 '/sample/eggs/zc.buildout-100.0b1-pyN.N.egg' |
|
110 ] |
|
111 ... |
|
112 |
|
113 Notice we are now using zc.buildout 100.0b1, a non-final release. |
|
114 |
|
115 The buildout script remembers the decision to accept early releases, and |
|
116 alerts the user. |
|
117 |
|
118 >>> print system(join('bin', 'buildout')), |
|
119 ... # doctest: +NORMALIZE_WHITESPACE |
|
120 NOTE: Accepting early releases of build system packages. Rerun bootstrap |
|
121 without --accept-buildout-test-releases (-t) to return to default |
|
122 behavior. |
|
123 |
|
124 This is accomplished within the script itself. |
|
125 |
|
126 >>> print open(buildout_script).read() # doctest: +ELLIPSIS |
|
127 #... |
|
128 sys.argv.insert(1, 'buildout:accept-buildout-test-releases=true') |
|
129 print ('NOTE: Accepting early releases of build system packages. Rerun ' |
|
130 'bootstrap without --accept-buildout-test-releases (-t) to return to ' |
|
131 'default behavior.') |
|
132 ... |
|
133 |
|
134 As the note says, to undo, you just need to re-run bootstrap without |
|
135 --accept-buildout-test-releases. |
|
136 |
|
137 >>> ignored = system( |
|
138 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
139 ... 'bootstrap.py') |
|
140 >>> print open(buildout_site_py).read() # doctest: +ELLIPSIS |
|
141 "... |
|
142 buildout_paths = [ |
|
143 '/sample/eggs/setuptools-...egg', |
|
144 '/sample/eggs/zc.buildout-99.99-pyN.N.egg' |
|
145 ] |
|
146 ... |
|
147 >>> ('buildout:accept-buildout-test-releases=true' in |
|
148 ... open(buildout_script).read()) |
|
149 False |
|
150 |
|
151 Now we will try the `--version` option, which lets you define a version for |
|
152 `zc.buildout`. If not provided, bootstrap will look for the latest one. |
|
153 |
|
154 Let's try with an unknown version:: |
|
155 |
|
156 >>> print 'XX'; print system( |
|
157 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
158 ... 'bootstrap.py --version UNKNOWN'); print 'X' # doctest: +ELLIPSIS |
|
159 ... |
|
160 X... |
|
161 No local packages or download links found for zc.buildout==UNKNOWN... |
|
162 ... |
|
163 |
|
164 Now let's try with `1.1.2`, which happens to exist:: |
|
165 |
|
166 >>> print 'X'; print system( |
|
167 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
168 ... 'bootstrap.py --version 1.1.2'); print 'X' |
|
169 ... |
|
170 X |
|
171 Generated script '/sample/bin/buildout'. |
|
172 <BLANKLINE> |
|
173 X |
|
174 |
|
175 Versions older than 1.5.0 put their egg dependencies in the ``buildout`` script. |
|
176 Let's make sure it was generated as we expect:: |
|
177 |
|
178 >>> print open(buildout_script).read() # doctest: +ELLIPSIS |
|
179 #... |
|
180 <BLANKLINE> |
|
181 import sys |
|
182 sys.path[0:0] = [ |
|
183 '/sample/eggs/setuptools-...egg', |
|
184 '/sample/eggs/zc.buildout-1.1.2...egg', |
|
185 ] |
|
186 <BLANKLINE> |
|
187 import zc.buildout.buildout |
|
188 <BLANKLINE> |
|
189 if __name__ == '__main__': |
|
190 zc.buildout.buildout.main() |
|
191 <BLANKLINE> |
|
192 |
|
193 Let's try with `1.2.1`:: |
|
194 |
|
195 >>> print 'X'; print system( |
|
196 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
197 ... 'bootstrap.py --version 1.2.1'); print 'X' # doctest: +ELLIPSIS |
|
198 ... |
|
199 X |
|
200 Generated script '/sample/bin/buildout'. |
|
201 <BLANKLINE> |
|
202 X |
|
203 |
|
204 Let's make sure the generated ``buildout`` script uses it:: |
|
205 |
|
206 >>> print open(buildout_script).read() # doctest: +ELLIPSIS |
|
207 #... |
|
208 <BLANKLINE> |
|
209 import sys |
|
210 sys.path[0:0] = [ |
|
211 '/sample/eggs/setuptools-...egg', |
|
212 '/sample/eggs/zc.buildout-1.2.1...egg', |
|
213 ] |
|
214 <BLANKLINE> |
|
215 import zc.buildout.buildout |
|
216 <BLANKLINE> |
|
217 if __name__ == '__main__': |
|
218 zc.buildout.buildout.main() |
|
219 <BLANKLINE> |
|
220 |
|
221 ``zc.buildout`` now can also run with `Distribute` with the `--distribute` |
|
222 option:: |
|
223 |
|
224 >>> print 'X'; print system( |
|
225 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
226 ... 'bootstrap.py --distribute'); print 'X' # doctest: +ELLIPSIS |
|
227 ... |
|
228 X |
|
229 ... |
|
230 Generated script '/sample/bin/buildout'... |
|
231 X |
|
232 |
|
233 Let's make sure the generated ``site.py`` uses it:: |
|
234 >>> print open(buildout_site_py).read() # doctest: +ELLIPSIS |
|
235 "... |
|
236 buildout_paths = [ |
|
237 '/sample/eggs/distribute-...egg', |
|
238 '/sample/eggs/zc.buildout-99.99-pyN.N.egg' |
|
239 ] |
|
240 ... |
|
241 |
|
242 Make sure both options can be used together:: |
|
243 |
|
244 >>> print 'X'; print system( |
|
245 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
246 ... 'bootstrap.py --distribute --version 1.2.1'); print 'X' |
|
247 ... # doctest: +ELLIPSIS |
|
248 ... |
|
249 X |
|
250 ... |
|
251 Generated script '/sample/bin/buildout'... |
|
252 X |
|
253 |
|
254 Let's make sure the old-style generated ``buildout`` script uses |
|
255 ``Distribute`` *and* ``zc.buildout-1.2.1``:: |
|
256 |
|
257 >>> print open(buildout_script).read() # doctest: +ELLIPSIS |
|
258 #... |
|
259 <BLANKLINE> |
|
260 import sys |
|
261 sys.path[0:0] = [ |
|
262 '/sample/eggs/distribute-...egg', |
|
263 '/sample/eggs/zc.buildout-1.2.1...egg', |
|
264 ] |
|
265 <BLANKLINE> |
|
266 import zc.buildout.buildout |
|
267 <BLANKLINE> |
|
268 if __name__ == '__main__': |
|
269 zc.buildout.buildout.main() |
|
270 <BLANKLINE> |
|
271 |
|
272 Last, the -c option needs to work on bootstrap.py:: |
|
273 |
|
274 >>> conf_file = os.path.join(sample_buildout, 'other.cfg') |
|
275 >>> f = open(conf_file, 'w') |
|
276 >>> f.write('[buildout]\nparts=\n\n') |
|
277 >>> f.close() |
|
278 >>> print 'X'; print system( |
|
279 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
280 ... 'bootstrap.py -c %s --distribute' % conf_file); print 'X' # doctest: +ELLIPSIS |
|
281 ... |
|
282 X |
|
283 ... |
|
284 Generated script '/sample/bin/buildout'... |
|
285 X |
|
286 |
|
287 You can specify a location of ez_setup.py or distribute_setup, so you |
|
288 can rely on a local or remote location. We'll write our own ez_setup.py |
|
289 that we will also use to test some other bootstrap options. |
|
290 |
|
291 >>> write('ez_setup.py', '''\ |
|
292 ... def use_setuptools(**kwargs): |
|
293 ... import sys, pprint |
|
294 ... pprint.pprint(kwargs, width=40) |
|
295 ... sys.exit() |
|
296 ... ''') |
|
297 >>> print system( |
|
298 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
299 ... 'bootstrap.py --setup-source=./ez_setup.py') |
|
300 ... # doctest: +ELLIPSIS |
|
301 {'download_delay': 0, |
|
302 'to_dir': '...'} |
|
303 <BLANKLINE> |
|
304 |
|
305 You can also pass a download-cache, and a place in which eggs should be stored |
|
306 (they are normally stored in a temporary directory). |
|
307 |
|
308 >>> print system( |
|
309 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
310 ... 'bootstrap.py --setup-source=./ez_setup.py '+ |
|
311 ... '--download-base=./download-cache --eggs=eggs') |
|
312 ... # doctest: +ELLIPSIS |
|
313 {'download_base': '/sample/download-cache/', |
|
314 'download_delay': 0, |
|
315 'to_dir': '/sample/eggs'} |
|
316 <BLANKLINE> |
|
317 |
|
318 Here's the entire help text. |
|
319 |
|
320 >>> print system( |
|
321 ... zc.buildout.easy_install._safe_arg(sys.executable)+' '+ |
|
322 ... 'bootstrap.py --help'), |
|
323 ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE |
|
324 Usage: [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] |
|
325 <BLANKLINE> |
|
326 Bootstraps a buildout-based project. |
|
327 <BLANKLINE> |
|
328 Simply run this script in a directory containing a buildout.cfg, using the |
|
329 Python that you want bin/buildout to use. |
|
330 <BLANKLINE> |
|
331 Note that by using --setup-source and --download-base to point to |
|
332 local resources, you can keep this script from going over the network. |
|
333 <BLANKLINE> |
|
334 <BLANKLINE> |
|
335 Options: |
|
336 -h, --help show this help message and exit |
|
337 -v VERSION, --version=VERSION |
|
338 use a specific zc.buildout version |
|
339 -d, --distribute Use Distribute rather than Setuptools. |
|
340 --setup-source=SETUP_SOURCE |
|
341 Specify a URL or file location for the setup file. If |
|
342 you use Setuptools, this will default to |
|
343 http://peak.telecommunity.com/dist/ez_setup.py; if you |
|
344 use Distribute, this will default to http://python- |
|
345 distribute.org/distribute_setup.py. |
|
346 --download-base=DOWNLOAD_BASE |
|
347 Specify a URL or directory for downloading zc.buildout |
|
348 and either Setuptools or Distribute. Defaults to PyPI. |
|
349 --eggs=EGGS Specify a directory for storing eggs. Defaults to a |
|
350 temporary directory that is deleted when the bootstrap |
|
351 script completes. |
|
352 -t, --accept-buildout-test-releases |
|
353 Normally, if you do not specify a --version, the |
|
354 bootstrap script and buildout gets the newest *final* |
|
355 versions of zc.buildout and its recipes and extensions |
|
356 for you. If you use this flag, bootstrap and buildout |
|
357 will get the newest releases even if they are alphas |
|
358 or betas. |
|
359 -c CONFIG_FILE Specify the path to the buildout configuration file to |
|
360 be used. |