~launchpad-pqm/launchpad/devel

8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
1
Launchpad Buildout
2
******************
3
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
4
Launchpad uses the buildout_ (or "zc.buildout") build system.
5
Buildout's biggest strength is managing Python packages.  That is also
6
our focus for it.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
7
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
8
We have at least two other ways of managing dependencies.  Apt
9
manages our Python language installation, as well as many of our
10
non-Python system-level dependencies, such as PostgreSQL.  The
11
sourcecode directory is our other way of managing dependencies.  It is
12
supposed to only contain dependencies that are not standard Python
13
packages.  bzr plugins and Javascript libraries are existing examples.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
14
15
If you are not interested in our `Motivations`_  or in an `Introduction to
16
zc.buildout`_, all developers will at least want to read the very brief
17
sections about the `Set Up`_ and the `Everyday Usage`_.
18
19
Developers who manage source dependencies probably should read the general
20
information about `Managing Dependencies and Scripts`_, but will also find
21
detailed instructions to `Add a Package`_, to `Upgrade a Package`_, to `Add a
22
Script`_, to `Add a File Modified By Buildout`_, and to `Work with Unreleased
23
or Forked Packages`_.
24
25
.. _buildout: http://www.buildout.org/
26
27
===========
28
Motivations
29
===========
30
31
These motivations are labeled as "[INTERNAL]" or "[EXTERNAL]" to indicate
32
whether it is pertinent for internal dependencies, which we on the Launchpad
33
team create and release ourselves; or external dependencies, which other
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
34
parties, in and out of Canonical, create and release.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
35
36
* We want more careful specification of our dependencies across branches.
37
  [INTERNAL] [EXTERNAL]
38
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
39
  This is a real concern pertinent both for our "trunks" (devel,
40
  stable, db-devel, db-stable) and for our development boxes. For
41
  instance, before incorporating buildout, in our trunks, when we want
42
  to update a dependency, we needed to make sure that *all* the
43
  current Launchpad trunks work with the dependency initially; then
44
  submit a new Launchpad branch that uses the change dependency.  A
45
  mistake can even potentially break one or both of the db-* trunks,
46
  since PQM only tests against one branch (usually devel), and
47
  sourcecode changes affect all branches at once.  For simplicity,
48
  speed, and safety, we want to be able to submit a single branch that
49
  incorporates the source dependencies and the associated changes at
50
  once.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
51
52
  This is also true, if less critical and easier to work around, on developer
53
  boxes.  Without care, changes to sourcecode when working on dependencies will
54
  affect all a developer's branches, polluting test results with false
55
  negatives or false positives.
56
57
* We want to default to using released versions of our software dependencies.
58
  [EXTERNAL]
59
60
  A significant number of projects do not always have a pristine trunk, and
61
  many also spend extra effort on polish, bug fixes, and compatibility before a
62
  release.  If we do not desperately need a new feature on trunk, using a
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
63
  release is generally regarded as a safer, better practice. Our earlier usage
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
64
  of bzr branches of the development trunks does not encourage this practice.
65
66
* We want to be encouraged to make the effort to interact with upstream
67
  projects to have our patches integrated. [EXTERNAL]
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
68
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
69
  Interacting and negotiating with upstream is undeniably more
70
  time-consuming than our previous practice of maintaining local bzr
71
  branches with our patches, especially short-term.  But our previous
72
  use of bzr branches is not good open-source community behavior--an
73
  ironic characteristic for a project like Launchpad. It also can
74
  cause problems down the road, for instance, if the patch becomes
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
75
  stale and we want to migrate to new releases.
76
77
* We want to be protected from changes and differences in our operating system.
78
  [INTERNAL] [EXTERNAL]
79
80
  This is a concern both over time and across different Launchpad environments.
81
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
82
  First, our operating system, Ubuntu, is driven by many needs and
83
  goals.  Launchpad is among them, but generally Launchpad serves
84
  Ubuntu, not the reverse.  For instance, Jaunty dropped Launchpad's
85
  Python version.  The Ubuntu developers had good reason--Python 2.4
86
  has not been supported by the Python developers for some time--but
87
  it caused a significant inconvenience to the Launchpad
88
  team. Managing our dependencies, particularly the Python library
89
  dependencies, can help alleviate these problems.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
90
91
  Second, Launchpad developers run a significantly different version of the
92
  operating system than that run in production. Maintaining our Python library
93
  dependencies ourselves can also help alleviate these concerns.
94
95
* We want to be able to easily use standard packages of our primary
96
  programming language, Python. [EXTERNAL]
97
98
  Our Python library dependencies are distributed for many operating systems--
99
  Windows, Mac, and other flavors of Linux--in a unified location and format:
100
  PyPI, using distutils.  Using Python library dependencies in their standard
101
  distributions makes it easier for us to reuse code.
102
103
* We want to be encouraged to release Python packages of our open-source
104
  code. [INTERNAL]
105
106
  We are beginning to realize our aspirations of abstracting and releasing some
107
  of our code.  Much of that code is in Python.  Consuming standard Python
108
  packages encourages us to follow good practice in releasing our own Python
109
  packages.  Dogfooding can help keep us honest, and good official releases can
110
  help us support and encourage a community of users.
111
112
Meanwhile, we want to be able to keep certain aspects of the legacy story.
113
114
* We need deployment to not need network access.
115
116
* We need to be able to use custom releases of our Python dependencies, if
117
  absolutely necessary.
118
119
* We would like to be able to follow security releases in our operating system.
120
121
We will be able to support the first two of these aspects entirely.
122
123
As to the third, we will continue to follow operating system security releases
124
for most or all of the dependencies that are not Python packages--a very
125
similar situation to the one before Buildout integration.
126
127
===========================
128
Introduction to zc.buildout
129
===========================
130
131
Buildout is a relatively simple system that increases in complexity as it is
132
extended via "recipes".  It works on top of distutils_ and setuptools_.  It
133
uses declarative ini-style files to direct its work.  The `Buildout site`_
134
points to a variety of documents describing and documenting its use.
135
136
For Launchpad, Buildout is hidden behind a Makefile as of this writing.  If
137
the Makefile is removed, developers will typically run ``bootstrap.py`` in the
138
branch, and then run ``bin/buildout``.  After that, the ``bin`` directory will
139
have the commands to start, stop, test, and debug the software.  If you are
140
interested in example direct usage of Buildout, you may want to read `the
141
"Hacking" document in the Launchpad wiki`_ that describes the usage patterns in
142
``lazr.*`` packages.
143
144
.. _`the "Hacking" document in the Launchpad wiki`: https://dev.launchpad.net/Hacking
145
146
Launchpad's Buildout usage is roughly of medium complexity.  It is more
147
complex than that needed by a package with few dependencies and simple usage
148
(see lazr.uri, for instance), but less complex than that of other large
149
applications that use the buildout system.  More complexity can come by
150
building more non-Python tools and by having multiple configuration variations,
151
for instance.
152
153
The documentation below will focus on using Launchpad's buildout.  See the
154
links given above for a more thorough general review.
155
156
.. _distutils: http://docs.python.org/distutils/index.html
157
158
.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
159
160
.. _`Buildout site`: http://www.buildout.org/
161
162
======
163
Set Up
164
======
165
166
If you use the ``rocketfuel-get`` script, run that, and you will be done.
167
168
If you don't, you have just a bit more initial set up.  I'll assume you
169
maintain a pattern similar to what the ``rocketfuel-*`` scripts use: you have a
170
local, pristine branch of trunk from which you make your other branches.  You
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
171
manually update the trunk and rsync sourcecode when necessary.  When you make
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
172
a branch, you use ``utilities/link-external-sourcecode``.
173
174
Developers that take this approach should do the following, where ``trunk`` is
175
the trunk branch from which you make local branches.
176
177
::
178
179
    bzr co lp:lp-source-dependencies download-cache
180
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
181
Then run ``make`` in the trunk.
182
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
183
See the `Everyday Usage: Manual`_ section for further instructions on how to
184
work without the ``rocketfuel-*`` scripts.
185
186
.. _`Everyday Usage: Manual`: Manual_
187
188
==============
189
Everyday Usage
190
==============
191
192
``rocketfuel`` Scripts
193
======================
194
195
If you typically use ``rocketfuel-get``, and you don't change source
196
dependencies, you should not have any further changes, except that ``bin/test``
197
has replaced ``test.py``.  ``rocketfuel-branch`` and
198
``link-external-dependencies`` will Do the Right Thing.
199
200
Manual
201
======
202
203
If you don't use the rocketfuel scripts, you will still use
204
``link-external-dependencies`` as before.  When a buildout complains that it
205
cannot find a version of a dependency, do the following, from within the
206
branch::
207
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
208
    bzr up download-cache
209
210
After this, retry your make (or run ``bin/buildout`` from the branch).
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
211
212
That's it for everyday usage.
213
214
=================================
215
Managing Dependencies and Scripts
216
=================================
217
218
What if you need to change or add dependencies or scripts?  As you might
219
expect, you need to know a bit more about what's going on, although we can
220
still keep this at a fairly high level.
221
222
First let's talk a little about the anatomy of what we have set up.  To be
223
clear, much of this is based on our own decisions of what to do.  If you see
224
something problematic, bring it up with the Foundations team.  Maybe together
225
we can come up with another approach that meets our needs better.
226
227
If you saw the top-level Launchpad directory before we started using Buildout,
228
you might notice seven new items in the checkout.
229
230
``bootstrap.py``
231
    This is the standard bootstrapping file provided by the Buildout
232
    distribution.  As of this writing, the Makefile uses this file, and you do
233
    not have to modify it or call it directly.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
234
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
235
    Without a Makefile, the first step of developing a source tree that uses
236
    Buildout is to run this file in the top level directory with the Python
237
    executable that you wish to use for the source tree.  It creates a ``bin``
238
    directory, if it does not already exist, and puts a ``buildout`` executable
239
    there.  The next step is to run ``bin/buildout``, which, unless you supply
240
    a ``-c`` option to specify a configuration file, will look for a
241
    buildout.cfg file by default to discover what to do.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
242
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
243
    Again, as of this writing, the Makefile uses this file, and it does not
244
    need to be modified, so you need not concern yourself with it further at
245
    this time.
246
247
``ez_setup.py``
248
    This is another standard file from another project.  In this case, it is
249
    the file provided by the setuptools project to install setuptools.  It is
250
    used by the ``setup.py`` file, described below.  It does not need to be
251
    modified or called directly.
252
253
``setup.py``
254
    This is the file that uses ``distutils``, extended by ``setuptools``, to
255
    specify direct dependencies, scripts, and other elements of the local
256
    source tree.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
257
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
258
    Buildout uses it, but the reverse is not true: ``setup.py`` does not know
259
    about Buildout.  This means that packages that use Buildout for development
260
    do not have to require it when they are being installed in other software
261
    as a dependency.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
262
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
263
    Describing this file in full is well beyond the scope of this document.  We
264
    will give recipes for modifying it for certain tasks below. For more
265
    information beyond these recipes, see the setuptools and distutils
266
    documentation.
267
268
``buildout.cfg``
269
    This is the default configuration file that ``bin/buildout`` will look to
270
    for instructions.
271
272
    Describing it in full is well beyond the scope of this document.  However,
273
    we will give an overview here.
274
275
    Configuration files for Buildout are comprised of sections with key-value
276
    pairs.
277
278
    The key-value pairs are separated with new lines, when the subsequent line
279
    is not indented.  The key and value are each separated with an equals sign.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
280
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
281
    ::
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
282
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
283
        foo = bar
284
        baz = bing
285
              bah
286
              boo
287
        sha = zam
288
289
    That example shows three keys, 'foo', 'baz', and 'sha'.  The 'baz' key has
290
    a string with two new lines (which might be interpreted one several ways,
291
    as defined for that key).
292
293
    The ``[buildout]`` section is the starting point for Buildout to determine
294
    what to do.  It looks for an ``extends`` key to find any additional files
295
    to merge in; we use this for ``versions.cfg``, discussed below.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
296
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
297
    In addition to general configuration and initialization such as this, it
298
    looks in the ``develop`` key to find source trees to develop as part of the
299
    buildout. In the standard Launchpad configuration, we develop only
300
    Launchpad itself (the current directory, or '.').  This means that the
301
    local ``setup.py`` will be run.  If you want to develop Launchpad while you
302
    develop another dependency, you can link another source tree in, and
303
    specify an additional ``develop`` directory in another line::
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
304
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
305
        [buildout]
306
        develop = .
307
                  lazr_uri_branch
308
11132.2.4 by James Westby
Extend the buildout documentation to discuss using the develop option.
309
    See `Developing a Dependent Library In Parallel`_ for more on this.
310
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
311
    The other basic key in the ``[buildout]`` section that we'll highlight here
312
    is ``parts``.  This key identifies the other sections in buildout.cfg that
313
    will be processed.  A section that is not identified in the ``[buildout]``
314
    sections ``parts`` key will usually be ignored (unless chosen for another
315
    role by another key elsewhere).
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
316
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
317
    Sections other than ``[buildout]`` that are specified as parts always must
318
    specify a ``recipe``: an identifier that determines what code should
319
    process that section.  You'll see a variety of recipes in Launchpad's
320
    buildout.cfg, including ``z3c.recipe.filetemplate``, ``zc.recipe.egg``, and
321
    others.
322
323
``versions.cfg``
324
    As mentioned above, ``buildout.cfg`` extends ``versions.cfg``  by
325
    specifying it in the ``extends`` key of the ``[buildout]`` section.
326
    Versions.cfg specifies the precise versions of the dependencies we use.
327
    This means that we can have several versions of a dependency available
328
    locally, but we only build the precise one we specify.  We give an
329
    example of its use below.  To read about the mechanism used, see the
330
    zc.buildout documentation of the ``versions`` option in the ``[buildout]``
331
    section.
332
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
333
``eggs``
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
334
    The ``eggs`` directory holds the eggs built from the downloaded
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
335
    distributions. Unless you set it up differently yourself, this directory is
336
    shared by all your branches. This directory is local to your system--we do
337
    not manage it in a branch. One reason for this is that eggs are often
338
    platform-specific.
339
340
``download-cache``
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
341
    The ``download-cache`` directory is a set of downloaded distributions--that
342
    is, exact copies of the items that would typically be obtained from the
343
    Python Package Index ("PyPI"), or another download source. We manage the
344
    download cache as a shared resource across all of our developers with a bzr
345
    branch in a Launchpad project called ``lp-source-dependencies``.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
346
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
347
    When we run buildout, Buildout reads a special key and value in the
348
    ``[buildout]`` section: ``install-from-cache = true``.  This means that, by
349
    default, Buildout will *not* use network access to find packages, but
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
350
    *only* look in the download cache.  This has many advantages.
351
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
352
    - First, it helps us keep our deployment boxes from needing network access
353
      out to PyPI and other download sites.
354
355
    - Second, it makes the buildout much faster, because it does not have to
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
356
      look out on the net for every dependency.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
357
358
    - Third, it makes the buildout more repeatable, because we are more
359
      insulated from outages at download sites such as PyPI, and poor release
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
360
      management.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
361
362
    - Fourth, it makes our deployments more auditable, because we can tell
363
      exactly what we are deploying.
364
365
    - Fifth, it gives us a single obvious place to put custom package
366
      distributions, as we'll discuss below.
367
368
    The downside is that adding and upgrading packages takes a small additional
369
    step, as we'll see below.
370
371
``buildout-templates``
372
    The last additional item in the checkout is the ``buildout-templates``
373
    directory.  This is used to hold templates that are used by the
374
    section in buildout.cfg that uses the ``z3c.recipe.filetemplate`` recipe.
375
    This can be used for many things, but we are using it as an alternate way
376
    for producing scripts when the zc.recipe.egg approach is insufficient.
377
378
In addition to these seven listings, after you have run the Makefile (or
379
``bin/buildout``), you will see an additional listing:
380
381
``bin``
382
    The ``bin`` directory has already been discussed many times.  After running
383
    the bootstrap.py, it holds the ``buildout`` script which can be used to
384
    process Buildout configuration files.  In Launchpad's case, after running
385
    the buildout, it also holds many executables, including scripts to test
386
    Launchpad; to run it; to run Python or IPython with Launchpad's sourcetree
387
    and dependencies available; to run harness or iharness (with IPython) with
388
    the sourcetree, dependencies, and database connections; or to perform
389
    several other tasks.  For now, the Makefile provides aliases for many of
390
    these.
391
392
Now that you have an introduction to the pertinent files and directories, we'll
393
move on to trying to perform tasks in the buildout.  We'll discuss adding a
394
dependency, upgrading a dependency, adding a script, adding an arbitrary file,
395
and working with unreleased packages.
396
397
Add a Package
398
=============
399
400
Let's suppose that we want to add the "lazr.foo" package as a dependency.
401
402
1.  Add the new package to the ``setup.py`` file in the ``install_requires``
403
    list.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
404
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
405
    Generally, our policy is to only set minimum version numbers in this file,
406
    or none at all.  It doesn't really matter for an application like
407
    Launchpad, but it a good rule for library packages, so we follow it for
408
    consistency.  Therefore, we might simply add ``'lazr.foo'`` to
409
    install_requires, or ``'lazr.foo >= 1.1'`` if we know that we are depending
410
    on features introduced in version 1.1 of lazr.foo.
411
412
2.  [OPTIONAL] If you know it, add the desired version number to versions.cfg
413
    now.
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
414
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
415
    For instance, if you know you want lazr.foo 1.1.2, add this line to the
416
    ``[versions]`` section of ``versions.cfg``::
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
417
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
418
      lazr.foo = 1.1.2
419
420
3.  [OPTIONAL] Add the desired distribution of lazr.foo 1.1.2 to the
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
421
    ``download-cache/dist`` directory.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
422
423
4.  Run the following command (or your variation)::
424
425
        ./bin/buildout -v buildout:install-from-cache=false | tee out.txt | grep 'Picked'
426
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
427
    The first part (``./bin/buildout -v
428
    buildout:install-from-cache=false``) will run buildout, allowing
429
    it to download source packages from the Internet to
430
    ``download-cache/dist``. The second part (``tee out.txt``) will
431
    dump the full output to the ``out.txt`` file in case you need to
432
    debug a problem. The last part (``grep 'Picked'``) will filter the
433
    output so that only additional packages--dependencies of your
434
    dependency--will be listed.  You need to see if it means that you
435
    have dependencies, some of which may be indirect
436
    dependencies. We'll see how to do this with an example.  Here's an
437
    imaginary output::
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
438
8514.2.1 by Francis J. Lacoste
Refer to ipython as the spurious Picked example.
439
        Picked: ipython = 0.9.1
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
440
        Picked: lazr.foom = 1.4
441
        Picked: zope.bar = 3.6.1
442
        Picked: z3c.shazam = 2.0.1
443
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
444
    In our example, this means that these packages have been added to
445
    your ``download-cache/dist`` directory. You now need to add those
446
    versions to the ``versions.cfg`` file::
447
448
        ipython = 0.9.1
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
449
        lazr.foom = 1.4
450
        zope.bar = 3.6.1
451
        z3c.shazam = 2.0.1
452
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
453
    Note that the output might include at least one, and possibly
454
    more, spurious "Picked:" listings.  ipython, in particular, has
455
    shown up in the past incorrectly--that is, when you try to add the
456
    file to the download-cache/dist directory, you'll discover that it
457
    is already there; and you'll see that versions.cfg already
458
    specifies the version.  As long as the test passes (see step 5,
459
    below), you can ignore this.
460
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
461
5.  Test.
462
14646.1.1 by Gary Poster
update buildout docs and try to clarify some parts
463
    Note that you can tell ``ec2 test`` to include all uncommitted
464
    distributions from the local download-cache in its tests with the
465
    ``--include-download-cache-changes`` flag (or ``-c``).  If you do
466
    this, you cannot use the ec2 test feature to submit on test
467
    success.  Also, if you have uncommitted distributions and you do
468
    *not* explicitly tell ec2 test to include or ignore the
469
    uncommitted distributions, it will refuse to start an instance.
470
471
6.  Check old versions in the download-cache.  If you are sure that
472
    they are not in use any more, *anywhere*, then remove them to save
473
    checkout space.  More explicitly, check with the LOSAs to see if
474
    they are in use in production and send an email to
475
    launchpad-dev@lists.launchpad.net before deleting anything if you
476
    are unsure.  A rule of thumb is that it's worth starting this
477
    investigation if the replacement has already been in use by the
478
    Launchpad tree for more than a month.  You can approximate this
479
    information by using ``bzr log`` on the newer (replacement)
480
    download-cache/dist file for the particular package.
481
482
7.  Now you need to share your package changes with the rest of the
483
    team.  You must do this before submitting your Launchpad branch to
484
    PQM or else your branch will not build properly anywhere else,
485
    including buildbot.  Commit the changes (``cd download-cache``,
486
    bzr add the needed files, ``bzr up``, ``bzr commit -m 'Add
487
    lazr.foom 1.1.2 and depdendencies to the download cache'``) to the
488
    shared download cache when you are sure it is what you want.
489
490
*Never* modify a package in the download-cache.  A change in code must mean a
491
change in version number, or else very bad inconsistencies and
492
confusion across build environments will happen.
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
493
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
494
495
Upgrade a Package
496
=================
497
498
Sometimes you need to upgrade a dependency.  This may require additional
499
dependency additions or upgrades.
500
501
If you already know what version you want, the simplest thing to try is to
502
modify versions.cfg to specify the new version and run steps 4, 5, and 6 of the
503
`Add a Package`_ instructions.
504
505
If you don't know what version you want, but just want to see what happens when
506
you upgrade to the most recent revision, you can clear out the versions of the
507
packages for upgrade and give it a try (that is, run steps 4, 5, and 6 of the
508
`Add a Package`_ instructions).  Note that, when not given an explicit version
509
number, our buildout is set to prefer final releases over alpha and beta
510
releases.  If you want to temporarily override this behavior, include
511
``buildout:prefer-final=false`` as another argument to ``bin/buildout``.
512
513
Add a Script
514
============
515
516
We often need scripts that are run in a certain environment defined by Python
517
dependencies, and sometimes even different Python executables.  Several of the
518
scripts we have are specified using the setuptools-based spelling that the
519
``zc.recipe.egg`` recipe supports.
520
521
For the common case, in ``setup.py``, add a string in the ``console_scripts``
522
list of the ``entry_points`` argument. Here's an example string::
523
14565.2.11 by Curtis Hovey
Moved runlaunchpad to lp.scripts.
524
    'run = lp.scripts.runlaunchpad:start_launchpad'
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
525
526
This will create a script named ``run`` in the ``bin`` directory that calls the
527
``start_launchpad`` function in the
14565.2.11 by Curtis Hovey
Moved runlaunchpad to lp.scripts.
528
``lp.scripts.runlaunchpad`` module.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
529
530
See the `zc.recipe.egg documentation`_ for more information on how to add
531
scripts using this method.
532
533
.. _`zc.recipe.egg documentation`: http://pypi.python.org/pypi/zc.recipe.egg
534
535
Add a File Modified By Buildout
536
===============================
537
538
Sometimes we need more control for the way our scripts are generated, or we
539
need other files processed during a buildout.  Writing a custom zc.buildout
540
recipe is one way, but well out of the scope of this document.  Read the
541
zc.buildout documentation for direction.
542
543
A much easier, and more limited approach is to use `z3c.recipe.filetemplate`_
9012.1.3 by Maris Fogels
Added a bit to the buildout docs for using the filetemplate recipe.
544
to build the file.  The recipe uses the ``buildout-templates`` directory,
545
which is a mirror of the Launchpad source tree.  The recipe searches the tree
546
for files ending in '.in', performs variable substitution on them, and then be
547
copies them into the Launchpad source tree.
548
549
To add a file using the recipe, simply create mirrors of the source tree
550
directories that you need under ``buildout-templates/``, and create a .in file
551
template at the desired location.  Take a look at
552
``buildout-templates/bin/`` for examples of what is possible.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
553
554
.. _`z3c.recipe.filetemplate`: http://pypi.python.org/pypi/z3c.recipe.filetemplate
555
556
Work with Unreleased or Forked Packages
557
=======================================
558
559
Sometimes you need to work with unreleased or forked packages.  FeedValidator_,
560
for instance, makes nightly zip releases but other than that only offers svn
561
access.  Similarly, we may require a patched or unreleased version of a package
562
for some purpose.  Hopefully, these situations will be rare, but they do occur.
563
564
While `other answers`_ are available for Buildout, our solution is to use the
565
download-cache.  Basically, make a custom source distribution with a unique
566
suffix in the name, and use it (and its version name) for the normal process of
567
adding or updating a package, as described above.  Because the custom package
568
is in the download-cache, it will be found and used.
569
570
Here's an example of making a custom distribution of FeedValidator.
571
572
FeedValidator is a Subversion project.  We check it out::
573
574
    svn co http://feedvalidator.googlecode.com/svn/trunk/feedvalidator/src feedvalidator
575
576
Next, we ``cd feedvalidator``, and, using a Python that has setuptools
577
installed, we run the following command::
578
579
    python setup.py egg_info -r -bDEV sdist
580
581
For this example, imagine that the current revision of the repository is 1049.
582
Because setuptools has built-in Subversion support, the command above will
583
create a tar.gz in the ``dist`` directory named
584
``feedvalidator-0.0.0DEV-r1049.tar.gz``. The -r option specifies that the
585
subversion revision should be part of the package name.  The -bDEV option
586
specifies that the 'DEV' suffix should be added to the version number.
587
8329.1.7 by Gary Poster
convert layout to have eggs and download-cache on top; and add make target for eggs folder, for deployment.
588
We could then put the tar.gz file in Launchpad's ``download-cache/dist``
589
directory, specify ``feedvalidator = 0.0.0DEV-r1049`` in the ``versions.cfg``
590
file, and proceed with the usual steps to update or add a new package.
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
591
592
If you use a bzr branch, you might use the ``-d`` option instead of the ``-r``
593
option when you create the distribution.  This will add the date instead of the
594
revision::
595
596
    python setup.py egg_info -d -bDEV sdist
597
598
For instance, this might produce a distribution for the ``lazr.restful``
599
project with a name like this: ``lazr.restful-0.9.1DEV-20090512.tar.gz``.
600
601
See the setuptools documentation for more information about `the egg_info
602
command`_.
603
13697.6.2 by Henning Eggers
Update buildout docucmentation.
604
It is also possible that setup.py does not support the egg_info command and
605
it is sufficient to just run the sdist command. It adds the current revision
606
of the bzr branch to the version number::
607
608
    python setup.py sdist
609
610
For instance, this might produce a distribution for the ``testtools``
611
project with a name like this: ``testtools-0.9.12-r228.tar.gz``.
612
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
613
.. _FeedValidator: http://feedvalidator.org/
614
615
.. _`other answers`: http://pypi.python.org/pypi/zc.buildoutsftp
616
617
.. _`the egg_info command`: http://peak.telecommunity.com/DevCenter/setuptools#tagging-and-daily-build-or-snapshot-releases
618
11132.2.4 by James Westby
Extend the buildout documentation to discuss using the develop option.
619
Developing a Dependent Library In Parallel
620
==========================================
621
622
Sometimes you need to iterate on change to a library used by Launchpad
623
that is managed by buildout as an egg. You could just edit what it is in
624
the ``eggs`` directory, but it is harder to produce a patch while doing
625
this. You could instead grab a branch of the libarary and produce an egg
626
everytime you make a change and make buildout use the new egg, but this is
627
slow.
628
629
buildout defaults to only using the current directory as code that will
630
be used without creating a distribution. We can arrange for it to use other
631
paths as well, so we can use a checkout of any code we like, with changes
632
being picked up instantly without us having to create a distribution.
633
634
To do this add the extra paths to the ``develop`` key in the ``[buildout]``
12392.1.1 by Jonathan Lange
Fix restructured text errors.
635
section of ``buildout.cfg``::
11132.2.4 by James Westby
Extend the buildout documentation to discuss using the develop option.
636
637
    [buildout]
638
    develop = .
639
              path/to/branch
640
641
and re-run ``make``.
642
643
Now any changes you make in that path will be picked up, and you are free
644
to make the changes you need and test them in the Launchpad environment.
645
646
Once you are finished you can produce a distribution as above for inclusion
647
in to Launchpad, as well as sending your patch upstream. At that point you
648
are free to revert the configuration to only develop Launchpad. You should
649
not submit your branch with this change in the configuration as it will
650
not work for others.
651
652
Be aware that you may have to change the version for the package in
653
``versions.cfg`` if there is a difference between the version in the
654
``eggs`` directory and the one in the ``setup.py`` that you pointed to
655
in the ``develop`` key.
656
657
One thing to be wary of is that setuptools treats "develop eggs" created
658
by this process with the same precedence as system packages. That means
659
that if the version in the ``setup.py`` at the path that you put in the
660
``develop`` key is the same as the version installed system wide, setuptools
661
may pick the wrong one. If that happens then increase the version in
662
setup.py and setuptools will take it.
663
8329.1.4 by Gary Poster
respond to reviews; in particular, add doc.
664
=====================
665
Possible Future Goals
666
=====================
667
668
- No longer use system site-packages.
669
- No longer use make.
670
- Get rid of the sourcecode directory.