source: TI12-security/trunk/NDGSecurity/python/buildout/ndgsecurity/eggs/zc.buildout-1.2.1-py2.5.egg/zc/buildout/debugging.txt @ 7081

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/buildout/ndgsecurity/eggs/zc.buildout-1.2.1-py2.5.egg/zc/buildout/debugging.txt@7081
Revision 7081, 3.1 KB checked in by pjkersha, 11 years ago (diff)
  • Property svn:keywords set to Id
Line 
1Debugging buildouts
2===================
3
4Buildouts can be pretty complex.  When things go wrong, it isn't
5always obvious why.  Errors can occur due to problems in user input or
6due to bugs in zc.buildout or recipes.  When an error occurs, Python's
7post-mortem debugger can be used to inspect the state of the buildout
8or recipe code were there error occured.  To enable this, use the -D
9option to the buildout.  Let's create a recipe that has a bug:
10
11    >>> mkdir(sample_buildout, 'recipes')
12
13    >>> write(sample_buildout, 'recipes', 'mkdir.py',
14    ... """
15    ... import os, zc.buildout
16    ...
17    ... class Mkdir:
18    ...
19    ...     def __init__(self, buildout, name, options):
20    ...         self.name, self.options = name, options
21    ...         options['path'] = os.path.join(
22    ...                               buildout['buildout']['directory'],
23    ...                               options['path'],
24    ...                               )
25    ...
26    ...     def install(self):
27    ...         directory = self.options['directory']
28    ...         os.mkdir(directory)
29    ...         return directory
30    ...
31    ...     def update(self):
32    ...         pass
33    ... """)
34
35    >>> write(sample_buildout, 'recipes', 'setup.py',
36    ... """
37    ... from setuptools import setup
38    ...
39    ... setup(name = "recipes",
40    ...       entry_points = {'zc.buildout': ['mkdir = mkdir:Mkdir']},
41    ...       )
42    ... """)
43
44And create a buildout that uses it:
45
46    >>> write(sample_buildout, 'buildout.cfg',
47    ... """
48    ... [buildout]
49    ... develop = recipes
50    ... parts = data-dir
51    ...
52    ... [data-dir]
53    ... recipe = recipes:mkdir
54    ... path = mystuff
55    ... """)
56
57If we run the buildout, we'll get an error:
58
59    >>> print system(buildout),
60    Develop: '/sample-buildout/recipes'
61    Installing data-dir.
62    While:
63      Installing data-dir.
64    Error: Missing option: data-dir:directory
65
66
67If we want to debug the error, we can add the -D option. Here's we'll
68supply some input:
69
70    >>> print system(buildout+" -D", """\
71    ... up
72    ... p self.options.keys()
73    ... q
74    ... """),
75    Develop: '/sample-buildout/recipes'
76    Installing data-dir.
77    > /zc/buildout/buildout.py(925)__getitem__()
78    -> raise MissingOption("Missing option: %s:%s" % (self.name, key))
79    (Pdb) > /sample-buildout/recipes/mkdir.py(14)install()
80    -> directory = self.options['directory']
81    (Pdb) ['path', 'recipe']
82    (Pdb) While:
83      Installing data-dir.
84    Traceback (most recent call last):
85      File "/zc/buildout/buildout.py", line 1352, in main
86        getattr(buildout, command)(args)
87      File "/zc/buildout/buildout.py", line 383, in install
88        installed_files = self[part]._call(recipe.install)
89      File "/zc/buildout/buildout.py", line 961, in _call
90        return f()
91      File "/sample-buildout/recipes/mkdir.py", line 14, in install
92        directory = self.options['directory']
93      File "/zc/buildout/buildout.py", line 925, in __getitem__
94        raise MissingOption("Missing option: %s:%s" % (self.name, key))
95    MissingOption: Missing option: data-dir:directory
96    <BLANKLINE>
97    Starting pdb:
Note: See TracBrowser for help on using the repository browser.